-
-
Notifications
You must be signed in to change notification settings - Fork 281
/
Copy pathArray.test.ts
45 lines (42 loc) · 1.4 KB
/
Array.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import * as AST from "@effect/schema/AST"
import * as S from "@effect/schema/Schema"
import * as Either from "effect/Either"
import { assert, describe, expect, it } from "vitest"
describe("Array", () => {
it("annotations()", () => {
const schema = S.Array(S.String).annotations({ identifier: "X" }).annotations({ title: "Y" })
expect(schema.ast.annotations).toStrictEqual({
[AST.IdentifierAnnotationId]: "X",
[AST.TitleAnnotationId]: "Y"
})
})
it("should expose the value", () => {
const schema = S.Array(S.String)
expect(schema.value).toStrictEqual(S.String)
})
it("should compute the partial result", () => {
const schema = S.Array(S.Number)
const all = S.decodeUnknownEither(schema)([1, "a", 2, "b"], { errors: "all" })
if (Either.isLeft(all)) {
const issue = all.left.error
if (issue._tag === "TupleType") {
expect(issue.output).toStrictEqual([1, 2])
} else {
assert.fail("expected a TupleType")
}
} else {
assert.fail("expected a Left")
}
const first = S.decodeUnknownEither(schema)([1, "a", 2, "b"], { errors: "first" })
if (Either.isLeft(first)) {
const issue = first.left.error
if (issue._tag === "TupleType") {
expect(issue.output).toStrictEqual([1])
} else {
assert.fail("expected a TupleType")
}
} else {
assert.fail("expected a Left")
}
})
})