-
-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Schema.headNonEmpty on Schema.NonEmptyArray (#3983)
Co-authored-by: Giulio Canti <[email protected]>
- Loading branch information
1 parent
98324d0
commit d2da73b
Showing
3 changed files
with
44 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"effect": minor | ||
--- | ||
|
||
Add Schema.headNonEmpty for Schema.NonEmptyArray |
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
26 changes: 26 additions & 0 deletions
26
packages/effect/test/Schema/Schema/Array/headNonEmpty.test.ts
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,26 @@ | ||
import * as S from "effect/Schema" | ||
import * as Util from "effect/test/Schema/TestUtils" | ||
import { describe, it } from "vitest" | ||
|
||
describe("headNonEmpty", () => { | ||
it("decoding", async () => { | ||
const schema = S.headNonEmpty(S.NonEmptyArray(S.NumberFromString)) | ||
await Util.expectDecodeUnknownSuccess(schema, ["1"], 1) | ||
await Util.expectDecodeUnknownFailure( | ||
schema, | ||
["a"], | ||
`(readonly [NumberFromString, ...NumberFromString[]] <-> number | number) | ||
└─ Encoded side transformation failure | ||
└─ readonly [NumberFromString, ...NumberFromString[]] | ||
└─ [0] | ||
└─ NumberFromString | ||
└─ Transformation process failure | ||
└─ Expected NumberFromString, actual "a"` | ||
) | ||
}) | ||
|
||
it("encoding", async () => { | ||
const schema = S.headNonEmpty(S.NonEmptyArray(S.NumberFromString)) | ||
await Util.expectEncodeSuccess(schema, 1, ["1"]) | ||
}) | ||
}) |