MCPcopy Create free account
hub / github.com/Effect-TS/effect / roundtrip

Function roundtrip

packages/effect/test/schema/toDifferJsonPatch.test.ts:19–47  ·  view source on GitHub ↗

* This suite intentionally avoids re-testing generic JSON Patch behavior * (pointer parsing, add/replace/remove mechanics, ordering, etc). * * It focuses on Schema.toDifferJsonPatch-specific guarantees: * - reference preservation when patch is a no-op * - reference replacement for root replace

(codec: Schema.Codec<T, E>)

Source from the content-addressed store, hash-verified

17 */
18
19function roundtrip<T, E>(codec: Schema.Codec<T, E>) {
20 const differ = Schema.toDifferJsonPatch(codec)
21 const arbitrary = Schema.toArbitrary(codec)(FastCheck)
22 const arb = arbitrary.filter((v) => {
23 // avoid prototype-poisoning-ish values that aren't valid JSON-ish containers for patching
24 if (
25 typeof v === "object" &&
26 v !== null &&
27 (Object.getPrototypeOf(v) === null || Object.hasOwn(v as any, "__proto__"))
28 ) {
29 return false
30 }
31 return true
32 })
33
34 FastCheck.assert(
35 FastCheck.property(arb, arb, (v1, v2) => {
36 const patch = differ.diff(v1, v2)
37 const patched = differ.patch(v1, patch)
38
39 // two invalid dates are not considered equal by deepStrictEqual
40 if (patched instanceof Date && v2 instanceof Date && Object.is(patched.getTime(), v2.getTime())) {
41 return
42 }
43
44 deepStrictEqual(patched, v2)
45 })
46 )
47}
48
49describe("Schema.toDifferJsonPatch", () => {
50 describe("structural guarantees", () => {

Callers 1

Calls 6

deepStrictEqualFunction · 0.90
filterMethod · 0.80
assertMethod · 0.80
diffMethod · 0.80
patchMethod · 0.80
isMethod · 0.65

Tested by

no test coverage detected