Skip to content

Commit

Permalink
internal: add SchemaTest utils (#4365)
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti authored Jan 30, 2025
1 parent 766113c commit 207491b
Show file tree
Hide file tree
Showing 51 changed files with 291 additions and 381 deletions.
50 changes: 25 additions & 25 deletions packages/effect/test/BigDecimal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ describe("BigDecimal", () => {
})

it("sign", () => {
deepStrictEqual(BigDecimal.sign($("-5")), -1)
deepStrictEqual(BigDecimal.sign($("0")), 0)
deepStrictEqual(BigDecimal.sign($("5")), 1)
deepStrictEqual(BigDecimal.sign($("-123.456")), -1)
deepStrictEqual(BigDecimal.sign($("456.789")), 1)
strictEqual(BigDecimal.sign($("-5")), -1)
strictEqual(BigDecimal.sign($("0")), 0)
strictEqual(BigDecimal.sign($("5")), 1)
strictEqual(BigDecimal.sign($("-123.456")), -1)
strictEqual(BigDecimal.sign($("456.789")), 1)
})

it("equals", () => {
Expand Down Expand Up @@ -136,7 +136,7 @@ describe("BigDecimal", () => {
equals(BigDecimal.unsafeDivide($(x), $(y)), $(z))
}

assertTrue(Option.isNone(BigDecimal.divide($("5"), $("0"))))
assertNone(BigDecimal.divide($("5"), $("0")))
throws(() => BigDecimal.unsafeDivide($("5"), $("0")), new RangeError("Division by zero"))
})

Expand All @@ -149,15 +149,15 @@ describe("BigDecimal", () => {
})

it("Order", () => {
deepStrictEqual(BigDecimal.Order($("1"), $("2")), -1)
deepStrictEqual(BigDecimal.Order($("2"), $("1")), 1)
deepStrictEqual(BigDecimal.Order($("2"), $("2")), 0)
deepStrictEqual(BigDecimal.Order($("1"), $("1.1")), -1)
deepStrictEqual(BigDecimal.Order($("1.1"), $("1")), 1)
deepStrictEqual(BigDecimal.Order($("0.00012300"), $("0.000123")), 0)
deepStrictEqual(BigDecimal.Order($("5"), $("5.000")), 0)
deepStrictEqual(BigDecimal.Order($("5"), $("0.500")), 1)
deepStrictEqual(BigDecimal.Order($("5"), $("50.00")), -1)
strictEqual(BigDecimal.Order($("1"), $("2")), -1)
strictEqual(BigDecimal.Order($("2"), $("1")), 1)
strictEqual(BigDecimal.Order($("2"), $("2")), 0)
strictEqual(BigDecimal.Order($("1"), $("1.1")), -1)
strictEqual(BigDecimal.Order($("1.1"), $("1")), 1)
strictEqual(BigDecimal.Order($("0.00012300"), $("0.000123")), 0)
strictEqual(BigDecimal.Order($("5"), $("5.000")), 0)
strictEqual(BigDecimal.Order($("5"), $("0.500")), 1)
strictEqual(BigDecimal.Order($("5"), $("50.00")), -1)
})

it("lessThan", () => {
Expand All @@ -179,19 +179,19 @@ describe("BigDecimal", () => {
})

it("greaterThanOrEqualTo", () => {
deepStrictEqual(BigDecimal.greaterThanOrEqualTo($("2"), $("3")), false)
deepStrictEqual(BigDecimal.greaterThanOrEqualTo($("3"), $("3")), true)
deepStrictEqual(BigDecimal.greaterThanOrEqualTo($("4"), $("3")), true)
assertFalse(BigDecimal.greaterThanOrEqualTo($("2"), $("3")))
assertTrue(BigDecimal.greaterThanOrEqualTo($("3"), $("3")))
assertTrue(BigDecimal.greaterThanOrEqualTo($("4"), $("3")))
})

it("between", () => {
deepStrictEqual(BigDecimal.between({ minimum: $("0"), maximum: $("5") })($("3")), true)
deepStrictEqual(BigDecimal.between({ minimum: $("0"), maximum: $("5") })($("-1")), false)
deepStrictEqual(BigDecimal.between({ minimum: $("0"), maximum: $("5") })($("6")), false)
deepStrictEqual(BigDecimal.between({ minimum: $("0.02"), maximum: $("5") })($("0.0123")), false)
deepStrictEqual(BigDecimal.between({ minimum: $("0.02"), maximum: $("5") })($("0.05")), true)
assertTrue(BigDecimal.between({ minimum: $("0"), maximum: $("5") })($("3")))
assertFalse(BigDecimal.between({ minimum: $("0"), maximum: $("5") })($("-1")))
assertFalse(BigDecimal.between({ minimum: $("0"), maximum: $("5") })($("6")))
assertFalse(BigDecimal.between({ minimum: $("0.02"), maximum: $("5") })($("0.0123")))
assertTrue(BigDecimal.between({ minimum: $("0.02"), maximum: $("5") })($("0.05")))

deepStrictEqual(BigDecimal.between($("3"), { minimum: $("0"), maximum: $("5") }), true)
assertTrue(BigDecimal.between($("3"), { minimum: $("0"), maximum: $("5") }))
})

it("clamp", () => {
Expand Down Expand Up @@ -235,7 +235,7 @@ describe("BigDecimal", () => {
equals(BigDecimal.remainder($("5"), $("2")).pipe(Option.getOrThrow), $("1"))
equals(BigDecimal.remainder($("4"), $("2")).pipe(Option.getOrThrow), $("0"))
equals(BigDecimal.remainder($("123.456"), $("0.2")).pipe(Option.getOrThrow), $("0.056"))
assertTrue(Option.isNone(BigDecimal.remainder($("5"), $("0"))))
assertNone(BigDecimal.remainder($("5"), $("0")))
})

it("unsafeRemainder", () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/effect/test/Schema/ParseResultFormatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("ParseResultFormatter", () => {
it("default message", () => {
const schema = Util.AsyncString
const input = ""
Util.assertParseError(
Util.assertions.parseError(
() => S.decodeUnknownSync(schema)(input),
`AsyncString
└─ cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work`
Expand All @@ -41,7 +41,7 @@ describe("ParseResultFormatter", () => {
it("default message with identifier", () => {
const schema = Util.AsyncString
const input = ""
Util.assertParseError(
Util.assertions.parseError(
() => S.decodeUnknownSync(schema)(input),
`AsyncString
└─ cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work`
Expand All @@ -57,7 +57,7 @@ describe("ParseResultFormatter", () => {
it("custom message (override=false)", () => {
const schema = Util.AsyncString.annotations({ message: () => "custom message" })
const input = ""
Util.assertParseError(
Util.assertions.parseError(
() => S.decodeUnknownSync(schema)(input),
`AsyncString
└─ cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work`
Expand All @@ -75,7 +75,7 @@ describe("ParseResultFormatter", () => {
message: () => ({ message: "custom message", override: true })
})
const input = ""
Util.assertParseError(
Util.assertions.parseError(
() => S.decodeUnknownSync(schema)(input),
`AsyncString
└─ cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work`
Expand Down
Loading

0 comments on commit 207491b

Please sign in to comment.