import * as S from "@effect/schema/Schema"
import { formatErrors } from "@effect/schema/TreeFormatter"
import { expect, test } from "vitest"
import * as E from "effect/Either"
const LongString = S.string.pipe(
S.filter((s) => s.length >= 10, {
message: () => "a string at least 10 characters long",
}),
)
const decode = S.parseEither(LongString)
test("short string", () => {
const result = decode("1234")
const error = expectLeft(result)
expect(formatErrors(error.errors)).toMatch("a string at least 10 characters long")
})
test.each([null, undefined])("invalid strings %s", (input) => {
const result = decode(input)
const error = expectLeft(result)
expect(formatErrors(error.errors)).toMatch(`Expected string, actual ${input}`)
})
const expectLeft = <E, A>(e: E.Either<E, A>) => {
if (E.isRight(e)) throw new Error(`Either is right: ${e.right}`)
return e.left
}
import * as S from "@effect/schema/Schema"
import { formatErrors } from "@effect/schema/TreeFormatter"
import { expect, test } from "vitest"
import * as E from "effect/Either"
const LongString = S.string.pipe(
S.filter((s) => s.length >= 10, {
message: () => "a string at least 10 characters long",
}),
)
const decode = S.parseEither(LongString)
test("short string", () => {
const result = decode("1234")
const error = expectLeft(result)
expect(formatErrors(error.errors)).toMatch("a string at least 10 characters long")
})
test.each([null, undefined])("invalid strings %s", (input) => {
const result = decode(input)
const error = expectLeft(result)
expect(formatErrors(error.errors)).toMatch(`Expected string, actual ${input}`)
})
const expectLeft = <E, A>(e: E.Either<E, A>) => {
if (E.isRight(e)) throw new Error(`Either is right: ${e.right}`)
return e.left
}