Skip to content

Commit

Permalink
SchemaTest: add pretty util
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed Jan 30, 2025
1 parent 6aaf695 commit 8b90035
Show file tree
Hide file tree
Showing 37 changed files with 229 additions and 318 deletions.
240 changes: 100 additions & 140 deletions packages/effect/test/Schema/Pretty.test.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { BigDecimal } from "effect"
import * as Pretty from "effect/Pretty"
import * as S from "effect/Schema"
import * as Util from "effect/test/Schema/TestUtils"
import { assertFalse, assertTrue, strictEqual } from "effect/test/util"
import { assertFalse, assertTrue } from "effect/test/util"
import { describe, it } from "vitest"

describe("BigDecimalFromSelf", () => {
Expand Down Expand Up @@ -34,11 +33,10 @@ describe("BigDecimalFromSelf", () => {

it("pretty", () => {
const schema = S.BigDecimalFromSelf
const pretty = Pretty.make(schema)

strictEqual(pretty(BigDecimal.fromNumber(123)), "BigDecimal(123)")
strictEqual(pretty(BigDecimal.unsafeFromString("123.100")), "BigDecimal(123.1)")
strictEqual(pretty(BigDecimal.unsafeFromString("")), "BigDecimal(0)")
Util.assertions.pretty(schema, BigDecimal.fromNumber(123), "BigDecimal(123)")
Util.assertions.pretty(schema, BigDecimal.unsafeFromString("123.100"), "BigDecimal(123.1)")
Util.assertions.pretty(schema, BigDecimal.unsafeFromString(""), "BigDecimal(0)")
})

it("equivalence", () => {
Expand Down
24 changes: 12 additions & 12 deletions packages/effect/test/Schema/Schema/Cause/CauseFromSelf.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import * as Cause from "effect/Cause"
import * as FiberId from "effect/FiberId"
import * as Pretty from "effect/Pretty"
import * as S from "effect/Schema"
import * as Util from "effect/test/Schema/TestUtils"
import { strictEqual } from "effect/test/util"
import { describe, it } from "vitest"

describe("CauseFromSelf", () => {
Expand Down Expand Up @@ -60,20 +58,22 @@ describe("CauseFromSelf", () => {

it("pretty", () => {
const schema = S.CauseFromSelf({ error: S.String, defect: S.Unknown })
const pretty = Pretty.make(schema)
strictEqual(pretty(Cause.die("error")), `Cause.die(Error: error)`)
strictEqual(pretty(Cause.empty), `Cause.empty`)
strictEqual(pretty(Cause.fail("error")), `Cause.fail("error")`)
strictEqual(
pretty(Cause.interrupt(FiberId.composite(FiberId.none, FiberId.none))),
Util.assertions.pretty(schema, Cause.die("error"), `Cause.die(Error: error)`)
Util.assertions.pretty(schema, Cause.empty, `Cause.empty`)
Util.assertions.pretty(schema, Cause.fail("error"), `Cause.fail("error")`)
Util.assertions.pretty(
schema,
Cause.interrupt(FiberId.composite(FiberId.none, FiberId.none)),
`Cause.interrupt(FiberId.composite(FiberId.none, FiberId.none))`
)
strictEqual(
pretty(Cause.parallel(Cause.die("error"), Cause.fail("error"))),
Util.assertions.pretty(
schema,
Cause.parallel(Cause.die("error"), Cause.fail("error")),
`Cause.parallel(Cause.die(Error: error), Cause.fail("error"))`
)
strictEqual(
pretty(Cause.sequential(Cause.die("error"), Cause.fail("error"))),
Util.assertions.pretty(
schema,
Cause.sequential(Cause.die("error"), Cause.fail("error")),
`Cause.sequential(Cause.die(Error: error), Cause.fail("error"))`
)
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as C from "effect/Chunk"
import * as P from "effect/ParseResult"
import * as Pretty from "effect/Pretty"
import * as S from "effect/Schema"
import * as Util from "effect/test/Schema/TestUtils"
import { assertFalse, assertTrue, strictEqual } from "effect/test/util"
import { assertFalse, assertTrue } from "effect/test/util"
import { describe, it } from "vitest"

describe("ChunkFromSelf", () => {
Expand Down Expand Up @@ -59,8 +58,7 @@ describe("ChunkFromSelf", () => {

it("pretty", () => {
const schema = S.ChunkFromSelf(S.String)
const pretty = Pretty.make(schema)
strictEqual(pretty(C.empty()), "Chunk()")
strictEqual(pretty(C.fromIterable(["a", "b"])), `Chunk("a", "b")`)
Util.assertions.pretty(schema, C.empty(), "Chunk()")
Util.assertions.pretty(schema, C.fromIterable(["a", "b"]), `Chunk("a", "b")`)
})
})
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import * as Arbitrary from "effect/Arbitrary"
import * as C from "effect/Chunk"
import * as FastCheck from "effect/FastCheck"
import * as Pretty from "effect/Pretty"
import * as S from "effect/Schema"
import * as Util from "effect/test/Schema/TestUtils"
import { assertFalse, assertTrue, strictEqual } from "effect/test/util"
import { assertFalse, assertTrue } from "effect/test/util"
import { describe, it } from "vitest"

describe("NonEmptyChunkFromSelf", () => {
Expand Down Expand Up @@ -56,8 +55,7 @@ describe("NonEmptyChunkFromSelf", () => {

it("pretty", () => {
const schema = S.NonEmptyChunkFromSelf(S.String)
const pretty = Pretty.make(schema)
strictEqual(pretty(C.make("a", "b")), `NonEmptyChunk("a", "b")`)
Util.assertions.pretty(schema, C.make("a", "b"), `NonEmptyChunk("a", "b")`)
})

it("equivalence", () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/effect/test/Schema/Schema/Class/Class.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Context, Data, Effect, Equal, JSONSchema, ParseResult, Pretty, Schema as S, SchemaAST as AST } from "effect"
import { Context, Data, Effect, Equal, JSONSchema, ParseResult, Schema as S, SchemaAST as AST } from "effect"
import * as Util from "effect/test/Schema/TestUtils"
import { assertFalse, assertSome, assertTrue, deepStrictEqual, strictEqual, throws } from "effect/test/util"
import { describe, it } from "vitest"
Expand Down Expand Up @@ -391,8 +391,8 @@ details: Duplicate key "a"`)
})

it("pretty", () => {
const pretty = Pretty.make(Person)
strictEqual(pretty(new Person({ id: 1, name: "John" })), `Person({ "id": 1, "name": "John" })`)
const schema = Person
Util.assertions.pretty(schema, new Person({ id: 1, name: "John" }), `Person({ "id": 1, "name": "John" })`)
})

describe("encode", () => {
Expand Down
6 changes: 2 additions & 4 deletions packages/effect/test/Schema/Schema/Data/DataFromSelf.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as Data from "effect/Data"
import * as P from "effect/ParseResult"
import * as Pretty from "effect/Pretty"
import * as S from "effect/Schema"
import * as Util from "effect/test/Schema/TestUtils"
import { assertFalse, assertTrue, strictEqual } from "effect/test/util"
import { assertFalse, assertTrue } from "effect/test/util"
import { describe, it } from "vitest"

describe("DataFromSelf", () => {
Expand Down Expand Up @@ -53,7 +52,6 @@ describe("DataFromSelf", () => {

it("pretty", () => {
const schema = S.DataFromSelf(S.Struct({ a: S.String, b: S.Number }))
const pretty = Pretty.make(schema)
strictEqual(pretty(Data.struct({ a: "ok", b: 0 })), `Data({ "a": "ok", "b": 0 })`)
Util.assertions.pretty(schema, Data.struct({ a: "ok", b: 0 }), `Data({ "a": "ok", "b": 0 })`)
})
})
6 changes: 2 additions & 4 deletions packages/effect/test/Schema/Schema/Date/DateFromSelf.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import * as Pretty from "effect/Pretty"
import * as S from "effect/Schema"
import * as Util from "effect/test/Schema/TestUtils"
import { strictEqual } from "effect/test/util"
import { describe, it } from "vitest"

describe("DateFromSelf", () => {
Expand All @@ -28,7 +26,7 @@ describe("DateFromSelf", () => {
})

it("pretty", () => {
const pretty = Pretty.make(S.DateFromSelf)
strictEqual(pretty(new Date(0)), `new Date("1970-01-01T00:00:00.000Z")`)
const schema = S.DateFromSelf
Util.assertions.pretty(schema, new Date(0), `new Date("1970-01-01T00:00:00.000Z")`)
})
})
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Duration } from "effect"
import * as Pretty from "effect/Pretty"
import * as S from "effect/Schema"
import * as Util from "effect/test/Schema/TestUtils"
import { strictEqual } from "effect/test/util"
import { describe, it } from "vitest"

describe("DurationFromSelf", () => {
Expand Down Expand Up @@ -32,10 +30,8 @@ describe("DurationFromSelf", () => {
})

it("pretty", () => {
const pretty = Pretty.make(schema)

strictEqual(pretty(Duration.millis(500)), "Duration(500ms)")
strictEqual(pretty(Duration.seconds(30)), "Duration(30s)")
strictEqual(pretty(Duration.minutes(5.25)), "Duration(5m 15s)")
Util.assertions.pretty(schema, Duration.millis(500), "Duration(500ms)")
Util.assertions.pretty(schema, Duration.seconds(30), "Duration(30s)")
Util.assertions.pretty(schema, Duration.minutes(5.25), "Duration(5m 15s)")
})
})
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as E from "effect/Either"
import * as P from "effect/ParseResult"
import * as Pretty from "effect/Pretty"
import * as S from "effect/Schema"
import * as Util from "effect/test/Schema/TestUtils"
import { assertFalse, assertTrue, strictEqual } from "effect/test/util"
import { assertFalse, assertTrue } from "effect/test/util"
import { describe, it } from "vitest"

describe("EitherFromSelf", () => {
Expand Down Expand Up @@ -60,8 +59,7 @@ describe("EitherFromSelf", () => {

it("pretty", () => {
const schema = S.EitherFromSelf({ left: S.String, right: S.Number })
const pretty = Pretty.make(schema)
strictEqual(pretty(E.left("a")), `left("a")`)
strictEqual(pretty(E.right(1)), "right(1)")
Util.assertions.pretty(schema, E.left("a"), `left("a")`)
Util.assertions.pretty(schema, E.right(1), "right(1)")
})
})
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import * as FiberId from "effect/FiberId"
import * as Pretty from "effect/Pretty"
import * as S from "effect/Schema"
import * as Util from "effect/test/Schema/TestUtils"
import { strictEqual } from "effect/test/util"
import { describe, it } from "vitest"

describe("FiberIdFromSelf", () => {
Expand Down Expand Up @@ -30,9 +28,12 @@ describe("FiberIdFromSelf", () => {

it("pretty", () => {
const schema = S.FiberIdFromSelf
const pretty = Pretty.make(schema)
strictEqual(pretty(FiberId.none), `FiberId.none`)
strictEqual(pretty(FiberId.runtime(1, 100)), `FiberId.runtime(1, 100)`)
strictEqual(pretty(FiberId.composite(FiberId.none, FiberId.none)), `FiberId.composite(FiberId.none, FiberId.none)`)
Util.assertions.pretty(schema, FiberId.none, `FiberId.none`)
Util.assertions.pretty(schema, FiberId.runtime(1, 100), `FiberId.runtime(1, 100)`)
Util.assertions.pretty(
schema,
FiberId.composite(FiberId.none, FiberId.none),
`FiberId.composite(FiberId.none, FiberId.none)`
)
})
})
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as HashMap from "effect/HashMap"
import * as P from "effect/ParseResult"
import * as Pretty from "effect/Pretty"
import * as S from "effect/Schema"
import * as Util from "effect/test/Schema/TestUtils"
import { assertFalse, assertTrue, strictEqual } from "effect/test/util"
import { assertFalse, assertTrue } from "effect/test/util"
import { describe, it } from "vitest"

describe("HashMapFromSelf", () => {
Expand Down Expand Up @@ -66,8 +65,7 @@ describe("HashMapFromSelf", () => {

it("pretty", () => {
const schema = S.HashMapFromSelf({ key: S.Number, value: S.String })
const pretty = Pretty.make(schema)
strictEqual(pretty(HashMap.fromIterable([])), "HashMap([])")
strictEqual(pretty(HashMap.fromIterable([[1, "a"], [2, "b"]])), `HashMap([[1, "a"], [2, "b"]])`)
Util.assertions.pretty(schema, HashMap.fromIterable([]), "HashMap([])")
Util.assertions.pretty(schema, HashMap.fromIterable([[1, "a"], [2, "b"]]), `HashMap([[1, "a"], [2, "b"]])`)
})
})
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as HashSet from "effect/HashSet"
import * as P from "effect/ParseResult"
import * as Pretty from "effect/Pretty"
import * as S from "effect/Schema"
import * as Util from "effect/test/Schema/TestUtils"
import { assertFalse, assertTrue, strictEqual } from "effect/test/util"
import { assertFalse, assertTrue } from "effect/test/util"
import { describe, it } from "vitest"

describe("HashSetFromSelf", () => {
Expand Down Expand Up @@ -59,8 +58,7 @@ describe("HashSetFromSelf", () => {

it("pretty", () => {
const schema = S.HashSetFromSelf(S.String)
const pretty = Pretty.make(schema)
strictEqual(pretty(HashSet.empty()), "HashSet()")
strictEqual(pretty(HashSet.fromIterable(["a", "b"])), `HashSet("a", "b")`)
Util.assertions.pretty(schema, HashSet.empty(), "HashSet()")
Util.assertions.pretty(schema, HashSet.fromIterable(["a", "b"]), `HashSet("a", "b")`)
})
})
8 changes: 3 additions & 5 deletions packages/effect/test/Schema/Schema/List/ListFromSelf.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as List from "effect/List"
import * as P from "effect/ParseResult"
import * as Pretty from "effect/Pretty"
import * as S from "effect/Schema"
import * as Util from "effect/test/Schema/TestUtils"
import { assertFalse, assertTrue, strictEqual } from "effect/test/util"
import { assertFalse, assertTrue } from "effect/test/util"
import { describe, it } from "vitest"

describe("ListFromSelf", () => {
Expand Down Expand Up @@ -59,8 +58,7 @@ describe("ListFromSelf", () => {

it("pretty", () => {
const schema = S.ListFromSelf(S.String)
const pretty = Pretty.make(schema)
strictEqual(pretty(List.empty()), "List()")
strictEqual(pretty(List.fromIterable(["a", "b"])), `List("a", "b")`)
Util.assertions.pretty(schema, List.empty(), "List()")
Util.assertions.pretty(schema, List.fromIterable(["a", "b"]), `List("a", "b")`)
})
})
6 changes: 2 additions & 4 deletions packages/effect/test/Schema/Schema/Number/greaterThan.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as P from "effect/ParseResult"
import * as Pretty from "effect/Pretty"
import * as S from "effect/Schema"
import * as Util from "effect/test/Schema/TestUtils"
import { assertFalse, assertTrue, strictEqual } from "effect/test/util"
import { assertFalse, assertTrue } from "effect/test/util"
import { describe, it } from "vitest"

describe("greaterThan", () => {
Expand Down Expand Up @@ -38,7 +37,6 @@ describe("greaterThan", () => {
})

it("pretty", () => {
const pretty = Pretty.make(schema)
strictEqual(pretty(1), "1")
Util.assertions.pretty(schema, 1, "1")
})
})
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as P from "effect/ParseResult"
import * as Pretty from "effect/Pretty"
import * as S from "effect/Schema"
import * as Util from "effect/test/Schema/TestUtils"
import { assertFalse, assertTrue, strictEqual } from "effect/test/util"
import { assertFalse, assertTrue } from "effect/test/util"
import { describe, it } from "vitest"

describe("greaterThanOrEqualTo", () => {
Expand Down Expand Up @@ -32,7 +31,6 @@ describe("greaterThanOrEqualTo", () => {
})

it("pretty", () => {
const pretty = Pretty.make(schema)
strictEqual(pretty(1), "1")
Util.assertions.pretty(schema, 1, "1")
})
})
6 changes: 2 additions & 4 deletions packages/effect/test/Schema/Schema/Number/int.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as P from "effect/ParseResult"
import * as Pretty from "effect/Pretty"
import * as S from "effect/Schema"
import * as Util from "effect/test/Schema/TestUtils"
import { assertFalse, assertTrue, strictEqual } from "effect/test/util"
import { assertFalse, assertTrue } from "effect/test/util"
import { describe, it } from "vitest"

describe("Int", () => {
Expand Down Expand Up @@ -34,7 +33,6 @@ describe("Int", () => {
})

it("pretty", () => {
const pretty = Pretty.make(schema)
strictEqual(pretty(1), "1")
Util.assertions.pretty(schema, 1, "1")
})
})
7 changes: 3 additions & 4 deletions packages/effect/test/Schema/Schema/Number/lessThan.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as P from "effect/ParseResult"
import * as Pretty from "effect/Pretty"
import * as S from "effect/Schema"
import * as Util from "effect/test/Schema/TestUtils"
import { assertFalse, assertTrue, strictEqual } from "effect/test/util"
import { assertFalse, assertTrue } from "effect/test/util"
import { describe, it } from "vitest"

describe("lessThan", () => {
Expand Down Expand Up @@ -37,7 +36,7 @@ describe("lessThan", () => {
})

it("pretty", () => {
const pretty = Pretty.make(S.lessThan(0)(S.Number))
strictEqual(pretty(1), "1")
const schema = S.lessThan(0)(S.Number)
Util.assertions.pretty(schema, 1, "1")
})
})
Loading

0 comments on commit 8b90035

Please sign in to comment.