-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add running tests to the CI pipeline (#12)
- small refactor of shared type
- Loading branch information
1 parent
b5e4d8d
commit 864c6ce
Showing
9 changed files
with
94 additions
and
79 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,6 @@ jobs: | |
|
||
- name: Run check:types | ||
run: bun check:types | ||
|
||
- name: Run tests | ||
run: bun test |
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
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,79 @@ | ||
import { describe, expect, test } from "bun:test"; | ||
import { initCorrettore, min, string, arrays, Infer } from "../src"; | ||
import { Equal, Expect } from "./helpers.types"; | ||
|
||
describe("arrays", () => { | ||
const c = initCorrettore([ | ||
arrays.array, | ||
string, | ||
min, | ||
arrays.nonEmpty, | ||
arrays.min, | ||
arrays.max, | ||
arrays.length, | ||
]); | ||
|
||
test("arrays", () => { | ||
expect(() => c.array(c.string().min(2)).parse(["ab", "ba"])).not.toThrow(); | ||
expect(() => c.array(c.string()).parse([])).not.toThrow(); | ||
expect(() => c.array(c.string()).parse([42])).toThrow(); | ||
expect(() => | ||
c.array(c.string()).nonEmpty().parse(["a", "b"]), | ||
).not.toThrow(); | ||
expect(() => c.array(c.string()).nonEmpty().parse([])).toThrow(); | ||
expect(() => | ||
c | ||
.array(c.string()) | ||
.nonEmpty() | ||
.min(3) | ||
.max(5) | ||
.length(4) | ||
.parse(["a", "b", "c", "d"]), | ||
).not.toThrow(); | ||
expect(() => | ||
c | ||
.array(c.string()) | ||
.nonEmpty() | ||
.min(3) | ||
.max(5) | ||
.length(4) | ||
.parse(["a", "b", "d"]), | ||
).toThrow(); | ||
|
||
const schema = c.array(c.string()); | ||
type SchemaType = Infer<typeof schema>; | ||
type _test = Expect<Equal<SchemaType, string[]>>; | ||
}); | ||
|
||
test("arrays alternative syntax", () => { | ||
expect(() => c.string().min(2).array().parse(["ab", "ba"])).not.toThrow(); | ||
expect(() => c.string().array().parse([])).not.toThrow(); | ||
expect(() => c.string().array().parse([42])).toThrow(); | ||
expect(() => c.string().array().nonEmpty().parse(["a", "b"])).not.toThrow(); | ||
expect(() => c.string().array().nonEmpty().parse([])).toThrow(); | ||
expect(() => | ||
c | ||
.string() | ||
.array() | ||
.nonEmpty() | ||
.min(3) | ||
.max(5) | ||
.length(4) | ||
.parse(["a", "b", "c", "d"]), | ||
).not.toThrow(); | ||
expect(() => | ||
c | ||
.string() | ||
.array() | ||
.nonEmpty() | ||
.min(3) | ||
.max(5) | ||
.length(4) | ||
.parse(["a", "b", "d"]), | ||
).toThrow(); | ||
|
||
const schema = c.string().array(); | ||
type SchemaType = Infer<typeof schema>; | ||
type _test = Expect<Equal<SchemaType, string[]>>; | ||
}); | ||
}); |
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