* Verifies that the schema satisfies the roundtrip law: `decode(encode(a))` * is equal to `a`.
(schema: Schema.Schema<A, I, never>, options?: {
readonly ignoreEncodingErrors?: ((issue: ParseResult.ParseIssue) => boolean) | undefined
readonly params?: FastCheck.Parameters<[A]> | undefined
})
| 111 | * is equal to `a`. |
| 112 | */ |
| 113 | testRoundtripConsistency<A, I>(schema: Schema.Schema<A, I, never>, options?: { |
| 114 | readonly ignoreEncodingErrors?: ((issue: ParseResult.ParseIssue) => boolean) | undefined |
| 115 | readonly params?: FastCheck.Parameters<[A]> | undefined |
| 116 | }) { |
| 117 | if (config.testRoundtripConsistency?.skip === true) { |
| 118 | return |
| 119 | } |
| 120 | const params = Predicate.isObject(config.testRoundtripConsistency?.params) |
| 121 | ? { ...config.testRoundtripConsistency?.params, ...options?.params } |
| 122 | : options?.params |
| 123 | const arb = Arbitrary.make(schema) |
| 124 | const is = Schema.is(schema) |
| 125 | const encode = ParseResult.encode(schema) |
| 126 | const decode = ParseResult.decode(schema) |
| 127 | FastCheck.assert( |
| 128 | FastCheck.property(arb, (a) => { |
| 129 | const roundtrip = encode(a).pipe( |
| 130 | Effect.mapError((issue) => ["encoding", issue] as const), |
| 131 | Effect.flatMap((i) => decode(i).pipe(Effect.mapError((issue) => ["decoding", issue] as const))), |
| 132 | Effect.either, |
| 133 | Effect.runSync |
| 134 | ) |
| 135 | if (Either.isLeft(roundtrip)) { |
| 136 | if (roundtrip.left[0] === "encoding" && options?.ignoreEncodingErrors) { |
| 137 | return options.ignoreEncodingErrors(roundtrip.left[1]) |
| 138 | } |
| 139 | return false |
| 140 | } |
| 141 | return is(roundtrip.right) |
| 142 | }), |
| 143 | params |
| 144 | ) |
| 145 | }, |
| 146 | |
| 147 | decoding: { |
| 148 | /** |