-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(core-utils): cleanup and add tests
Remove unused modules and add some test coverage. The tests are not exhaustive, but any test coverage is good test coverage.
- Loading branch information
Showing
14 changed files
with
288 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { describe, expect, test } from "tstyche"; | ||
|
||
import { isPresentArray } from "./array.js"; | ||
|
||
describe("type checks", () => { | ||
describe("isPresentArray", () => { | ||
test("empty array", () => { | ||
const array = ["hello"] as const; | ||
if (isPresentArray(array)) { | ||
expect(array).type.toEqual<readonly ["hello"]>(); | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { describe, expect, test } from "tstyche"; | ||
|
||
import type { PresentArray } from "./array.js"; | ||
import { iterableHasItems, reverse } from "./iterable.js"; | ||
|
||
describe("type checks", () => { | ||
describe("reverse", () => { | ||
test("PresentArray", () => { | ||
const array = ["a", "b", "c"] as const; | ||
expect(reverse(array)).type.toEqual<PresentArray<"b" | "a" | "c">>(); | ||
}); | ||
|
||
test("Set", () => { | ||
const set = new Set(["a", "b", "c"]); | ||
expect(reverse(set)).type.toEqual<string[]>(); | ||
}); | ||
}); | ||
|
||
describe("iterableHasItems", () => { | ||
test("PresentArray", () => { | ||
const array = ["a", "b", "c"] as const; | ||
expect(iterableHasItems(array)).type.toEqual<true>(); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { describe, expect, test } from "tstyche"; | ||
|
||
import { isPresent } from "./value.js"; | ||
|
||
describe("type checks", () => { | ||
test("truthy | null | undefined", () => { | ||
{ | ||
const x: number | null = 1; | ||
|
||
if (isPresent(x)) { | ||
expect(x).type.toEqual<number>(); | ||
} | ||
} | ||
|
||
{ | ||
const x: number | undefined = 1; | ||
|
||
if (isPresent(x)) { | ||
expect(x).type.toEqual<number>(); | ||
} | ||
} | ||
|
||
{ | ||
const x: number | void = 1; | ||
|
||
if (isPresent(x)) { | ||
expect(x).type.toEqual<number>(); | ||
} | ||
} | ||
|
||
{ | ||
const x: number = 1; | ||
|
||
if (isPresent(x)) { | ||
expect(x).type.toEqual<number>(); | ||
} | ||
} | ||
|
||
{ | ||
const x: number | null | undefined = 1; | ||
|
||
if (isPresent(x)) { | ||
expect(x).type.toEqual<number>(); | ||
} | ||
} | ||
}); | ||
|
||
test("falsey | null | undefined", () => { | ||
{ | ||
// even though 0 is falsy, it is still present | ||
const x: number | null = 0; | ||
|
||
if (isPresent(x)) { | ||
expect(x).type.toEqual<number>(); | ||
} | ||
} | ||
|
||
{ | ||
// even though "" is falsy, it is still present | ||
const x: string | null = ""; | ||
|
||
if (isPresent(x)) { | ||
expect(x).type.toEqual<string>(); | ||
} | ||
} | ||
}); | ||
}); |
Oops, something went wrong.