From f818c305b5b5d59d7ea8a2d84f122a833fa6e1d3 Mon Sep 17 00:00:00 2001 From: Dmitry Zakharov Date: Tue, 30 Apr 2024 22:52:44 +0400 Subject: [PATCH] Internal: Format tests --- packages/tests/src/core/S_Array_max_test.res | 26 ++- packages/tests/src/core/S_Array_min_test.res | 26 ++- packages/tests/src/core/S_Float_max_test.res | 26 ++- packages/tests/src/core/S_Float_min_test.res | 26 ++- packages/tests/src/core/S_Int_max_test.res | 26 ++- packages/tests/src/core/S_Int_min_test.res | 26 ++- packages/tests/src/core/S_Int_port_test.res | 5 +- .../src/core/S_Option_getOrWith_test.res | 13 +- .../tests/src/core/S_Option_getOr_test.res | 13 +- .../tests/src/core/S_String_cuid_test.res | 5 +- .../tests/src/core/S_String_datetime_test.res | 26 ++- .../tests/src/core/S_String_email_test.res | 26 ++- .../tests/src/core/S_String_length_test.res | 52 +++-- packages/tests/src/core/S_String_max_test.res | 26 ++- packages/tests/src/core/S_String_min_test.res | 26 ++- packages/tests/src/core/S_String_url_test.res | 5 +- .../tests/src/core/S_String_uuid_test.res | 5 +- packages/tests/src/core/S_array_test.res | 39 ++-- packages/tests/src/core/S_bool_test.res | 13 +- packages/tests/src/core/S_custom_test.res | 31 ++- packages/tests/src/core/S_deprecate_test.res | 26 ++- packages/tests/src/core/S_dict_test.res | 26 ++- .../tests/src/core/S_failWithError_test.res | 30 +-- packages/tests/src/core/S_float_test.res | 26 ++- packages/tests/src/core/S_int_test.res | 52 +++-- packages/tests/src/core/S_json_test.res | 52 +++-- packages/tests/src/core/S_list_test.res | 13 +- .../tests/src/core/S_literal_NaN_test.res | 26 ++- .../tests/src/core/S_literal_Null_test.res | 26 ++- .../tests/src/core/S_literal_Number_test.res | 52 +++-- .../tests/src/core/S_literal_Object_test.res | 95 +++++---- .../tests/src/core/S_literal_String_test.res | 38 ++-- .../src/core/S_literal_Undefined_test.res | 26 ++- packages/tests/src/core/S_never_test.res | 39 ++-- packages/tests/src/core/S_null_test.res | 52 +++-- packages/tests/src/core/S_nullable_test.res | 13 +- .../tests/src/core/S_object_escaping_test.res | 39 ++-- packages/tests/src/core/S_object_test.res | 188 +++++++++++------- .../S_object_withoutDeclaredFields_test.res | 13 +- packages/tests/src/core/S_option_test.res | 39 ++-- .../src/core/S_parseJsonStringWith_test.res | 13 +- packages/tests/src/core/S_parseWith_test.res | 13 +- packages/tests/src/core/S_preprocess_test.res | 36 ++-- packages/tests/src/core/S_recursive_test.res | 45 +++-- packages/tests/src/core/S_refine_test.res | 39 ++-- .../tests/src/core/S_serializeWith_test.res | 153 ++++++++------ packages/tests/src/core/S_string_test.res | 13 +- packages/tests/src/core/S_transform_test.res | 105 ++++++---- packages/tests/src/core/S_tuple1_test.res | 32 +-- packages/tests/src/core/S_tuple2_test.res | 32 +-- packages/tests/src/core/S_union_test.res | 57 +++--- 51 files changed, 1135 insertions(+), 715 deletions(-) diff --git a/packages/tests/src/core/S_Array_max_test.res b/packages/tests/src/core/S_Array_max_test.res index 14fc8541..27b5688a 100644 --- a/packages/tests/src/core/S_Array_max_test.res +++ b/packages/tests/src/core/S_Array_max_test.res @@ -10,11 +10,14 @@ test("Successfully parses valid data", t => { test("Fails to parse invalid data", t => { let schema = S.array(S.int)->S.Array.max(1) - t->U.assertErrorResult([1, 2, 3, 4]->S.parseAnyWith(schema), { - code: OperationFailed("Array must be 1 or fewer items long"), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + [1, 2, 3, 4]->S.parseAnyWith(schema), + { + code: OperationFailed("Array must be 1 or fewer items long"), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Successfully serializes valid value", t => { @@ -27,11 +30,14 @@ test("Successfully serializes valid value", t => { test("Fails to serialize invalid value", t => { let schema = S.array(S.int)->S.Array.max(1) - t->U.assertErrorResult([1, 2, 3, 4]->S.serializeToUnknownWith(schema), { - code: OperationFailed("Array must be 1 or fewer items long"), - operation: Serializing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + [1, 2, 3, 4]->S.serializeToUnknownWith(schema), + { + code: OperationFailed("Array must be 1 or fewer items long"), + operation: Serializing, + path: S.Path.empty, + }, + ) }) test("Returns custom error message", t => { diff --git a/packages/tests/src/core/S_Array_min_test.res b/packages/tests/src/core/S_Array_min_test.res index 23d6c50f..928f76f5 100644 --- a/packages/tests/src/core/S_Array_min_test.res +++ b/packages/tests/src/core/S_Array_min_test.res @@ -10,11 +10,14 @@ test("Successfully parses valid data", t => { test("Fails to parse invalid data", t => { let schema = S.array(S.int)->S.Array.min(1) - t->U.assertErrorResult([]->S.parseAnyWith(schema), { - code: OperationFailed("Array must be 1 or more items long"), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + []->S.parseAnyWith(schema), + { + code: OperationFailed("Array must be 1 or more items long"), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Successfully serializes valid value", t => { @@ -27,11 +30,14 @@ test("Successfully serializes valid value", t => { test("Fails to serialize invalid value", t => { let schema = S.array(S.int)->S.Array.min(1) - t->U.assertErrorResult([]->S.serializeToUnknownWith(schema), { - code: OperationFailed("Array must be 1 or more items long"), - operation: Serializing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + []->S.serializeToUnknownWith(schema), + { + code: OperationFailed("Array must be 1 or more items long"), + operation: Serializing, + path: S.Path.empty, + }, + ) }) test("Returns custom error message", t => { diff --git a/packages/tests/src/core/S_Float_max_test.res b/packages/tests/src/core/S_Float_max_test.res index ec293e6b..05b75a61 100644 --- a/packages/tests/src/core/S_Float_max_test.res +++ b/packages/tests/src/core/S_Float_max_test.res @@ -10,11 +10,14 @@ test("Successfully parses valid data", t => { test("Fails to parse invalid data", t => { let schema = S.float->S.Float.max(1.) - t->U.assertErrorResult(1234->S.parseAnyWith(schema), { - code: OperationFailed("Number must be lower than or equal to 1"), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + 1234->S.parseAnyWith(schema), + { + code: OperationFailed("Number must be lower than or equal to 1"), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Successfully serializes valid value", t => { @@ -27,11 +30,14 @@ test("Successfully serializes valid value", t => { test("Fails to serialize invalid value", t => { let schema = S.float->S.Float.max(1.) - t->U.assertErrorResult(1234.->S.serializeToUnknownWith(schema), { - code: OperationFailed("Number must be lower than or equal to 1"), - operation: Serializing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + 1234.->S.serializeToUnknownWith(schema), + { + code: OperationFailed("Number must be lower than or equal to 1"), + operation: Serializing, + path: S.Path.empty, + }, + ) }) test("Returns custom error message", t => { diff --git a/packages/tests/src/core/S_Float_min_test.res b/packages/tests/src/core/S_Float_min_test.res index 347b2eda..7e8de572 100644 --- a/packages/tests/src/core/S_Float_min_test.res +++ b/packages/tests/src/core/S_Float_min_test.res @@ -10,11 +10,14 @@ test("Successfully parses valid data", t => { test("Fails to parse invalid data", t => { let schema = S.float->S.Float.min(1.) - t->U.assertErrorResult(0->S.parseAnyWith(schema), { - code: OperationFailed("Number must be greater than or equal to 1"), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + 0->S.parseAnyWith(schema), + { + code: OperationFailed("Number must be greater than or equal to 1"), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Successfully serializes valid value", t => { @@ -27,11 +30,14 @@ test("Successfully serializes valid value", t => { test("Fails to serialize invalid value", t => { let schema = S.float->S.Float.min(1.) - t->U.assertErrorResult(0.->S.serializeToUnknownWith(schema), { - code: OperationFailed("Number must be greater than or equal to 1"), - operation: Serializing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + 0.->S.serializeToUnknownWith(schema), + { + code: OperationFailed("Number must be greater than or equal to 1"), + operation: Serializing, + path: S.Path.empty, + }, + ) }) test("Returns custom error message", t => { diff --git a/packages/tests/src/core/S_Int_max_test.res b/packages/tests/src/core/S_Int_max_test.res index 4592ffd7..b6bfbd44 100644 --- a/packages/tests/src/core/S_Int_max_test.res +++ b/packages/tests/src/core/S_Int_max_test.res @@ -10,11 +10,14 @@ test("Successfully parses valid data", t => { test("Fails to parse invalid data", t => { let schema = S.int->S.Int.max(1) - t->U.assertErrorResult(1234->S.parseAnyWith(schema), { - code: OperationFailed("Number must be lower than or equal to 1"), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + 1234->S.parseAnyWith(schema), + { + code: OperationFailed("Number must be lower than or equal to 1"), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Successfully serializes valid value", t => { @@ -27,11 +30,14 @@ test("Successfully serializes valid value", t => { test("Fails to serialize invalid value", t => { let schema = S.int->S.Int.max(1) - t->U.assertErrorResult(1234->S.serializeToUnknownWith(schema), { - code: OperationFailed("Number must be lower than or equal to 1"), - operation: Serializing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + 1234->S.serializeToUnknownWith(schema), + { + code: OperationFailed("Number must be lower than or equal to 1"), + operation: Serializing, + path: S.Path.empty, + }, + ) }) test("Returns custom error message", t => { diff --git a/packages/tests/src/core/S_Int_min_test.res b/packages/tests/src/core/S_Int_min_test.res index a4231cf1..0e87704a 100644 --- a/packages/tests/src/core/S_Int_min_test.res +++ b/packages/tests/src/core/S_Int_min_test.res @@ -10,11 +10,14 @@ test("Successfully parses valid data", t => { test("Fails to parse invalid data", t => { let schema = S.int->S.Int.min(1) - t->U.assertErrorResult(0->S.parseAnyWith(schema), { - code: OperationFailed("Number must be greater than or equal to 1"), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + 0->S.parseAnyWith(schema), + { + code: OperationFailed("Number must be greater than or equal to 1"), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Successfully serializes valid value", t => { @@ -27,11 +30,14 @@ test("Successfully serializes valid value", t => { test("Fails to serialize invalid value", t => { let schema = S.int->S.Int.min(1) - t->U.assertErrorResult(0->S.serializeToUnknownWith(schema), { - code: OperationFailed("Number must be greater than or equal to 1"), - operation: Serializing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + 0->S.serializeToUnknownWith(schema), + { + code: OperationFailed("Number must be greater than or equal to 1"), + operation: Serializing, + path: S.Path.empty, + }, + ) }) test("Returns custom error message", t => { diff --git a/packages/tests/src/core/S_Int_port_test.res b/packages/tests/src/core/S_Int_port_test.res index a9003a48..7e45bd9c 100644 --- a/packages/tests/src/core/S_Int_port_test.res +++ b/packages/tests/src/core/S_Int_port_test.res @@ -25,7 +25,10 @@ test("Successfully serializes valid value", t => { test("Fails to serialize invalid value", t => { let schema = S.int->S.Int.port - t->U.assertErrorResult(-80->S.serializeToUnknownWith(schema), {code: OperationFailed("Invalid port"), operation: Serializing, path: S.Path.empty}) + t->U.assertErrorResult( + -80->S.serializeToUnknownWith(schema), + {code: OperationFailed("Invalid port"), operation: Serializing, path: S.Path.empty}, + ) }) test("Returns custom error message", t => { diff --git a/packages/tests/src/core/S_Option_getOrWith_test.res b/packages/tests/src/core/S_Option_getOrWith_test.res index 5c9f7169..18c9b632 100644 --- a/packages/tests/src/core/S_Option_getOrWith_test.res +++ b/packages/tests/src/core/S_Option_getOrWith_test.res @@ -40,11 +40,14 @@ test("Successfully parses nested option with default value", t => { test("Fails to parse data with default", t => { let schema = S.bool->S.option->S.Option.getOrWith(() => false) - t->U.assertErrorResult(%raw(`"string"`)->S.parseAnyWith(schema), { - code: InvalidType({expected: schema->S.toUnknown, received: %raw(`"string"`)}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + %raw(`"string"`)->S.parseAnyWith(schema), + { + code: InvalidType({expected: schema->S.toUnknown, received: %raw(`"string"`)}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Successfully serializes schema with transformation", t => { diff --git a/packages/tests/src/core/S_Option_getOr_test.res b/packages/tests/src/core/S_Option_getOr_test.res index 2d1fbf7e..55feaa58 100644 --- a/packages/tests/src/core/S_Option_getOr_test.res +++ b/packages/tests/src/core/S_Option_getOr_test.res @@ -47,11 +47,14 @@ test("Successfully serializes nested option with default value", t => { test("Fails to parse data with default", t => { let schema = S.bool->S.option->S.Option.getOr(false) - t->U.assertErrorResult(%raw(`"string"`)->S.parseAnyWith(schema), { - code: InvalidType({expected: schema->S.toUnknown, received: %raw(`"string"`)}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + %raw(`"string"`)->S.parseAnyWith(schema), + { + code: InvalidType({expected: schema->S.toUnknown, received: %raw(`"string"`)}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Successfully parses schema with transformation", t => { diff --git a/packages/tests/src/core/S_String_cuid_test.res b/packages/tests/src/core/S_String_cuid_test.res index b3461c10..b7b071dc 100644 --- a/packages/tests/src/core/S_String_cuid_test.res +++ b/packages/tests/src/core/S_String_cuid_test.res @@ -33,7 +33,10 @@ test("Successfully serializes valid value", t => { test("Fails to serialize invalid value", t => { let schema = S.string->S.String.cuid - t->U.assertErrorResult("cifjhdsfhsd-invalid-cuid"->S.serializeToUnknownWith(schema), {code: OperationFailed("Invalid CUID"), operation: Serializing, path: S.Path.empty}) + t->U.assertErrorResult( + "cifjhdsfhsd-invalid-cuid"->S.serializeToUnknownWith(schema), + {code: OperationFailed("Invalid CUID"), operation: Serializing, path: S.Path.empty}, + ) }) test("Returns custom error message", t => { diff --git a/packages/tests/src/core/S_String_datetime_test.res b/packages/tests/src/core/S_String_datetime_test.res index 1edda484..093b308e 100644 --- a/packages/tests/src/core/S_String_datetime_test.res +++ b/packages/tests/src/core/S_String_datetime_test.res @@ -24,21 +24,27 @@ test("Successfully parses valid data", t => { test("Fails to parse non UTC date string", t => { let schema = S.string->S.String.datetime - t->U.assertErrorResult("Thu Apr 20 2023 10:45:48 GMT+0400"->S.parseAnyWith(schema), { - code: OperationFailed("Invalid datetime string! Must be UTC"), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + "Thu Apr 20 2023 10:45:48 GMT+0400"->S.parseAnyWith(schema), + { + code: OperationFailed("Invalid datetime string! Must be UTC"), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Fails to parse UTC date with timezone offset", t => { let schema = S.string->S.String.datetime - t->U.assertErrorResult("2020-01-01T00:00:00+02:00"->S.parseAnyWith(schema), { - code: OperationFailed("Invalid datetime string! Must be UTC"), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + "2020-01-01T00:00:00+02:00"->S.parseAnyWith(schema), + { + code: OperationFailed("Invalid datetime string! Must be UTC"), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Uses custom message on failure", t => { diff --git a/packages/tests/src/core/S_String_email_test.res b/packages/tests/src/core/S_String_email_test.res index 7d25c1d3..3ad6b4c1 100644 --- a/packages/tests/src/core/S_String_email_test.res +++ b/packages/tests/src/core/S_String_email_test.res @@ -9,11 +9,14 @@ test("Successfully parses valid data", t => { test("Fails to parse invalid data", t => { let schema = S.string->S.String.email - t->U.assertErrorResult("dzakh.dev"->S.parseAnyWith(schema), { - code: OperationFailed("Invalid email address"), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + "dzakh.dev"->S.parseAnyWith(schema), + { + code: OperationFailed("Invalid email address"), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Successfully serializes valid value", t => { @@ -29,11 +32,14 @@ test("Successfully serializes valid value", t => { test("Fails to serialize invalid value", t => { let schema = S.string->S.String.email - t->U.assertErrorResult("dzakh.dev"->S.serializeToUnknownWith(schema), { - code: OperationFailed("Invalid email address"), - operation: Serializing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + "dzakh.dev"->S.serializeToUnknownWith(schema), + { + code: OperationFailed("Invalid email address"), + operation: Serializing, + path: S.Path.empty, + }, + ) }) test("Returns custom error message", t => { diff --git a/packages/tests/src/core/S_String_length_test.res b/packages/tests/src/core/S_String_length_test.res index e82e7676..0486e951 100644 --- a/packages/tests/src/core/S_String_length_test.res +++ b/packages/tests/src/core/S_String_length_test.res @@ -9,16 +9,22 @@ test("Successfully parses valid data", t => { test("Fails to parse invalid data", t => { let schema = S.string->S.String.length(1) - t->U.assertErrorResult(""->S.parseAnyWith(schema), { - code: OperationFailed("String must be exactly 1 characters long"), - operation: Parsing, - path: S.Path.empty, - }) - t->U.assertErrorResult("1234"->S.parseAnyWith(schema), { - code: OperationFailed("String must be exactly 1 characters long"), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + ""->S.parseAnyWith(schema), + { + code: OperationFailed("String must be exactly 1 characters long"), + operation: Parsing, + path: S.Path.empty, + }, + ) + t->U.assertErrorResult( + "1234"->S.parseAnyWith(schema), + { + code: OperationFailed("String must be exactly 1 characters long"), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Successfully serializes valid value", t => { @@ -30,16 +36,22 @@ test("Successfully serializes valid value", t => { test("Fails to serialize invalid value", t => { let schema = S.string->S.String.length(1) - t->U.assertErrorResult(""->S.serializeToUnknownWith(schema), { - code: OperationFailed("String must be exactly 1 characters long"), - operation: Serializing, - path: S.Path.empty, - }) - t->U.assertErrorResult("1234"->S.serializeToUnknownWith(schema), { - code: OperationFailed("String must be exactly 1 characters long"), - operation: Serializing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + ""->S.serializeToUnknownWith(schema), + { + code: OperationFailed("String must be exactly 1 characters long"), + operation: Serializing, + path: S.Path.empty, + }, + ) + t->U.assertErrorResult( + "1234"->S.serializeToUnknownWith(schema), + { + code: OperationFailed("String must be exactly 1 characters long"), + operation: Serializing, + path: S.Path.empty, + }, + ) }) test("Returns custom error message", t => { diff --git a/packages/tests/src/core/S_String_max_test.res b/packages/tests/src/core/S_String_max_test.res index c40075b1..a0c251a0 100644 --- a/packages/tests/src/core/S_String_max_test.res +++ b/packages/tests/src/core/S_String_max_test.res @@ -10,11 +10,14 @@ test("Successfully parses valid data", t => { test("Fails to parse invalid data", t => { let schema = S.string->S.String.max(1) - t->U.assertErrorResult("1234"->S.parseAnyWith(schema), { - code: OperationFailed("String must be 1 or fewer characters long"), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + "1234"->S.parseAnyWith(schema), + { + code: OperationFailed("String must be 1 or fewer characters long"), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Successfully serializes valid value", t => { @@ -27,11 +30,14 @@ test("Successfully serializes valid value", t => { test("Fails to serialize invalid value", t => { let schema = S.string->S.String.max(1) - t->U.assertErrorResult("1234"->S.serializeToUnknownWith(schema), { - code: OperationFailed("String must be 1 or fewer characters long"), - operation: Serializing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + "1234"->S.serializeToUnknownWith(schema), + { + code: OperationFailed("String must be 1 or fewer characters long"), + operation: Serializing, + path: S.Path.empty, + }, + ) }) test("Returns custom error message", t => { diff --git a/packages/tests/src/core/S_String_min_test.res b/packages/tests/src/core/S_String_min_test.res index d7bfd647..b271affe 100644 --- a/packages/tests/src/core/S_String_min_test.res +++ b/packages/tests/src/core/S_String_min_test.res @@ -10,11 +10,14 @@ test("Successfully parses valid data", t => { test("Fails to parse invalid data", t => { let schema = S.string->S.String.min(1) - t->U.assertErrorResult(""->S.parseAnyWith(schema), { - code: OperationFailed("String must be 1 or more characters long"), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + ""->S.parseAnyWith(schema), + { + code: OperationFailed("String must be 1 or more characters long"), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Successfully serializes valid value", t => { @@ -27,11 +30,14 @@ test("Successfully serializes valid value", t => { test("Fails to serialize invalid value", t => { let schema = S.string->S.String.min(1) - t->U.assertErrorResult(""->S.serializeToUnknownWith(schema), { - code: OperationFailed("String must be 1 or more characters long"), - operation: Serializing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + ""->S.serializeToUnknownWith(schema), + { + code: OperationFailed("String must be 1 or more characters long"), + operation: Serializing, + path: S.Path.empty, + }, + ) }) test("Returns custom error message", t => { diff --git a/packages/tests/src/core/S_String_url_test.res b/packages/tests/src/core/S_String_url_test.res index 0744e77d..8eec884a 100644 --- a/packages/tests/src/core/S_String_url_test.res +++ b/packages/tests/src/core/S_String_url_test.res @@ -29,7 +29,10 @@ test("Successfully serializes valid value", t => { test("Fails to serialize invalid value", t => { let schema = S.string->S.String.url - t->U.assertErrorResult("cifjhdsfhsd"->S.serializeToUnknownWith(schema), {code: OperationFailed("Invalid url"), operation: Serializing, path: S.Path.empty}) + t->U.assertErrorResult( + "cifjhdsfhsd"->S.serializeToUnknownWith(schema), + {code: OperationFailed("Invalid url"), operation: Serializing, path: S.Path.empty}, + ) }) test("Returns custom error message", t => { diff --git a/packages/tests/src/core/S_String_uuid_test.res b/packages/tests/src/core/S_String_uuid_test.res index 9c280602..48d2081f 100644 --- a/packages/tests/src/core/S_String_uuid_test.res +++ b/packages/tests/src/core/S_String_uuid_test.res @@ -33,7 +33,10 @@ test("Successfully serializes valid value", t => { test("Fails to serialize invalid value", t => { let schema = S.string->S.String.uuid - t->U.assertErrorResult("123e4567"->S.serializeToUnknownWith(schema), {code: OperationFailed("Invalid UUID"), operation: Serializing, path: S.Path.empty}) + t->U.assertErrorResult( + "123e4567"->S.serializeToUnknownWith(schema), + {code: OperationFailed("Invalid UUID"), operation: Serializing, path: S.Path.empty}, + ) }) test("Returns custom error message", t => { diff --git a/packages/tests/src/core/S_array_test.res b/packages/tests/src/core/S_array_test.res index 388f020c..92bbacad 100644 --- a/packages/tests/src/core/S_array_test.res +++ b/packages/tests/src/core/S_array_test.res @@ -17,21 +17,27 @@ module CommonWithNested = { test("Fails to parse", t => { let schema = factory() - t->U.assertErrorResult(invalidAny->S.parseAnyWith(schema), { - code: InvalidType({expected: schema->S.toUnknown, received: invalidAny}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + invalidAny->S.parseAnyWith(schema), + { + code: InvalidType({expected: schema->S.toUnknown, received: invalidAny}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Fails to parse nested", t => { let schema = factory() - t->U.assertErrorResult(nestedInvalidAny->S.parseAnyWith(schema), { - code: InvalidType({expected: S.string->S.toUnknown, received: 1->Obj.magic}), - operation: Parsing, - path: S.Path.fromArray(["1"]), - }) + t->U.assertErrorResult( + nestedInvalidAny->S.parseAnyWith(schema), + { + code: InvalidType({expected: S.string->S.toUnknown, received: 1->Obj.magic}), + operation: Parsing, + path: S.Path.fromArray(["1"]), + }, + ) }) test("Successfully serializes", t => { @@ -91,11 +97,14 @@ test("Successfully parses matrix", t => { test("Fails to parse matrix", t => { let schema = S.array(S.array(S.string)) - t->U.assertErrorResult(%raw(`[["a", 1], ["c", "d"]]`)->S.parseAnyWith(schema), { - code: InvalidType({expected: S.string->S.toUnknown, received: %raw(`1`)}), - operation: Parsing, - path: S.Path.fromArray(["0", "1"]), - }) + t->U.assertErrorResult( + %raw(`[["a", 1], ["c", "d"]]`)->S.parseAnyWith(schema), + { + code: InvalidType({expected: S.string->S.toUnknown, received: %raw(`1`)}), + operation: Parsing, + path: S.Path.fromArray(["0", "1"]), + }, + ) }) test("Successfully parses array of optional items", t => { diff --git a/packages/tests/src/core/S_bool_test.res b/packages/tests/src/core/S_bool_test.res index 7637bacd..611ffcae 100644 --- a/packages/tests/src/core/S_bool_test.res +++ b/packages/tests/src/core/S_bool_test.res @@ -16,11 +16,14 @@ module Common = { test("Fails to parse ", t => { let schema = factory() - t->U.assertErrorResult(invalidAny->S.parseAnyWith(schema), { - code: InvalidType({expected: schema->S.toUnknown, received: invalidAny}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + invalidAny->S.parseAnyWith(schema), + { + code: InvalidType({expected: schema->S.toUnknown, received: invalidAny}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Successfully serializes", t => { diff --git a/packages/tests/src/core/S_custom_test.res b/packages/tests/src/core/S_custom_test.res index b29e8ead..09ee6f8a 100644 --- a/packages/tests/src/core/S_custom_test.res +++ b/packages/tests/src/core/S_custom_test.res @@ -32,11 +32,14 @@ test("Correctly parses custom schema", t => { t->Assert.deepEqual("Hello world!"->S.parseAnyWith(schema), Ok(Some("Hello world!")), ()) t->Assert.deepEqual(%raw(`null`)->S.parseAnyWith(schema), Ok(None), ()) t->Assert.deepEqual(%raw(`undefined`)->S.parseAnyWith(schema), Ok(None), ()) - t->U.assertErrorResult(123->S.parseAnyWith(schema), { - code: InvalidType({expected: S.string->S.toUnknown, received: %raw(`123`)}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + 123->S.parseAnyWith(schema), + { + code: InvalidType({expected: S.string->S.toUnknown, received: %raw(`123`)}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Correctly serializes custom schema", t => { @@ -55,7 +58,10 @@ test("Fails to serialize with user error", t => { serializer: _ => s.fail("User error"), }) - t->U.assertErrorResult(None->S.serializeToUnknownWith(schema), {code: OperationFailed("User error"), operation: Serializing, path: S.Path.empty}) + t->U.assertErrorResult( + None->S.serializeToUnknownWith(schema), + {code: OperationFailed("User error"), operation: Serializing, path: S.Path.empty}, + ) }) test("Fails to serialize with serializer is missing", t => { @@ -63,11 +69,14 @@ test("Fails to serialize with serializer is missing", t => { parser: _ => (), }) - t->U.assertErrorResult(()->S.serializeToUnknownWith(schema), { - code: InvalidOperation({description: "The S.custom serializer is missing"}), - operation: Serializing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + ()->S.serializeToUnknownWith(schema), + { + code: InvalidOperation({description: "The S.custom serializer is missing"}), + operation: Serializing, + path: S.Path.empty, + }, + ) }) asyncTest("Parses with asyncParser", async t => { diff --git a/packages/tests/src/core/S_deprecate_test.res b/packages/tests/src/core/S_deprecate_test.res index 252705fa..10a88491 100644 --- a/packages/tests/src/core/S_deprecate_test.res +++ b/packages/tests/src/core/S_deprecate_test.res @@ -16,11 +16,14 @@ module Common = { test("Fails to parse", t => { let schema = factory() - t->U.assertErrorResult(invalidAny->S.parseAnyWith(schema), { - code: InvalidType({expected: schema->S.toUnknown, received: invalidAny}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + invalidAny->S.parseAnyWith(schema), + { + code: InvalidType({expected: schema->S.toUnknown, received: invalidAny}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Successfully serializes", t => { @@ -45,11 +48,14 @@ test("Successfully parses undefined", t => { test("Fails to parse null", t => { let schema = S.bool->S.option->S.deprecate("Deprecated") - t->U.assertErrorResult(%raw(`null`)->S.parseAnyWith(schema), { - code: InvalidType({expected: schema->S.toUnknown, received: %raw(`null`)}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + %raw(`null`)->S.parseAnyWith(schema), + { + code: InvalidType({expected: schema->S.toUnknown, received: %raw(`null`)}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Successfully parses null for deprecated nullable schema", t => { diff --git a/packages/tests/src/core/S_dict_test.res b/packages/tests/src/core/S_dict_test.res index 4d3aadac..0922e678 100644 --- a/packages/tests/src/core/S_dict_test.res +++ b/packages/tests/src/core/S_dict_test.res @@ -23,21 +23,27 @@ module CommonWithNested = { test("Fails to parse", t => { let schema = factory() - t->U.assertErrorResult(invalidAny->S.parseAnyWith(schema), { - code: InvalidType({expected: schema->S.toUnknown, received: invalidAny}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + invalidAny->S.parseAnyWith(schema), + { + code: InvalidType({expected: schema->S.toUnknown, received: invalidAny}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Fails to parse nested", t => { let schema = factory() - t->U.assertErrorResult(nestedInvalidAny->S.parseAnyWith(schema), { - code: InvalidType({expected: S.string->S.toUnknown, received: %raw(`true`)}), - operation: Parsing, - path: S.Path.fromArray(["key2"]), - }) + t->U.assertErrorResult( + nestedInvalidAny->S.parseAnyWith(schema), + { + code: InvalidType({expected: S.string->S.toUnknown, received: %raw(`true`)}), + operation: Parsing, + path: S.Path.fromArray(["key2"]), + }, + ) }) test("Compiled parse code snapshot", t => { diff --git a/packages/tests/src/core/S_failWithError_test.res b/packages/tests/src/core/S_failWithError_test.res index 06ba34a0..b3bb195d 100644 --- a/packages/tests/src/core/S_failWithError_test.res +++ b/packages/tests/src/core/S_failWithError_test.res @@ -14,11 +14,14 @@ test("FIXME: Should keep operation of the error passed to advanced fail", t => { }), ) - t->U.assertErrorResult(["Hello world!"]->S.parseAnyWith(schema), { - code: OperationFailed("User error"), - operation: Parsing, - path: S.Path.fromArray(["0", "a", "b"]), - }) + t->U.assertErrorResult( + ["Hello world!"]->S.parseAnyWith(schema), + { + code: OperationFailed("User error"), + operation: Parsing, + path: S.Path.fromArray(["0", "a", "b"]), + }, + ) }) test("Works with failing outside of the parser", t => { @@ -40,11 +43,14 @@ test("Works with failing outside of the parser", t => { ) ) - t->U.assertErrorResult(["Hello world!"]->S.parseAnyWith(schema), { - code: OperationFailed("User error"), - operation: Parsing, - path: S.Path.fromLocation("root") - ->S.Path.concat(S.Path.dynamic) - ->S.Path.concat(S.Path.fromArray(["a", "b"])), - }) + t->U.assertErrorResult( + ["Hello world!"]->S.parseAnyWith(schema), + { + code: OperationFailed("User error"), + operation: Parsing, + path: S.Path.fromLocation("root") + ->S.Path.concat(S.Path.dynamic) + ->S.Path.concat(S.Path.fromArray(["a", "b"])), + }, + ) }) diff --git a/packages/tests/src/core/S_float_test.res b/packages/tests/src/core/S_float_test.res index 181cf6dd..562ee41a 100644 --- a/packages/tests/src/core/S_float_test.res +++ b/packages/tests/src/core/S_float_test.res @@ -15,11 +15,14 @@ module Common = { test("Fails to parse", t => { let schema = factory() - t->U.assertErrorResult(invalidAny->S.parseAnyWith(schema), { - code: InvalidType({expected: schema->S.toUnknown, received: invalidAny}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + invalidAny->S.parseAnyWith(schema), + { + code: InvalidType({expected: schema->S.toUnknown, received: invalidAny}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Successfully serializes", t => { @@ -54,9 +57,12 @@ test("Successfully parses number with a fractional part", t => { test("Fails to parse NaN", t => { let schema = S.float - t->U.assertErrorResult(%raw(`NaN`)->S.parseAnyWith(schema), { - code: InvalidType({expected: schema->S.toUnknown, received: %raw(`NaN`)}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + %raw(`NaN`)->S.parseAnyWith(schema), + { + code: InvalidType({expected: schema->S.toUnknown, received: %raw(`NaN`)}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) diff --git a/packages/tests/src/core/S_int_test.res b/packages/tests/src/core/S_int_test.res index 98242109..b1600ad2 100644 --- a/packages/tests/src/core/S_int_test.res +++ b/packages/tests/src/core/S_int_test.res @@ -15,11 +15,14 @@ module Common = { test("Fails to parse", t => { let schema = factory() - t->U.assertErrorResult(invalidAny->S.parseAnyWith(schema), { - code: InvalidType({expected: schema->S.toUnknown, received: invalidAny}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + invalidAny->S.parseAnyWith(schema), + { + code: InvalidType({expected: schema->S.toUnknown, received: invalidAny}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Successfully serializes", t => { @@ -48,31 +51,40 @@ module Common = { test("Fails to parse int when JSON is a number bigger than +2^31", t => { let schema = S.int - t->U.assertErrorResult(%raw(`2147483648`)->S.parseAnyWith(schema), { - code: InvalidType({expected: schema->S.toUnknown, received: %raw(`2147483648`)}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + %raw(`2147483648`)->S.parseAnyWith(schema), + { + code: InvalidType({expected: schema->S.toUnknown, received: %raw(`2147483648`)}), + operation: Parsing, + path: S.Path.empty, + }, + ) t->Assert.deepEqual(%raw(`2147483647`)->S.parseAnyWith(schema), Ok(2147483647), ()) }) test("Fails to parse int when JSON is a number lower than -2^31", t => { let schema = S.int - t->U.assertErrorResult(%raw(`-2147483649`)->S.parseAnyWith(schema), { - code: InvalidType({expected: schema->S.toUnknown, received: %raw(`-2147483649`)}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + %raw(`-2147483649`)->S.parseAnyWith(schema), + { + code: InvalidType({expected: schema->S.toUnknown, received: %raw(`-2147483649`)}), + operation: Parsing, + path: S.Path.empty, + }, + ) t->Assert.deepEqual(%raw(`-2147483648`)->S.parseAnyWith(schema), Ok(-2147483648), ()) }) test("Fails to parse NaN", t => { let schema = S.int - t->U.assertErrorResult(%raw(`NaN`)->S.parseAnyWith(schema), { - code: InvalidType({expected: schema->S.toUnknown, received: %raw(`NaN`)}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + %raw(`NaN`)->S.parseAnyWith(schema), + { + code: InvalidType({expected: schema->S.toUnknown, received: %raw(`NaN`)}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) diff --git a/packages/tests/src/core/S_json_test.res b/packages/tests/src/core/S_json_test.res index c62571be..2912924d 100644 --- a/packages/tests/src/core/S_json_test.res +++ b/packages/tests/src/core/S_json_test.res @@ -57,40 +57,52 @@ test("Fails to parse Object field", t => { [("bar", %raw(`undefined`)), ("baz", JSON.Encode.null)]->Dict.fromArray, ) - t->U.assertErrorResult(data->S.parseWith(schema), { - code: InvalidType({received: %raw(`undefined`), expected: schema->S.toUnknown}), - operation: Parsing, - path: S.Path.fromLocation("bar"), - }) + t->U.assertErrorResult( + data->S.parseWith(schema), + { + code: InvalidType({received: %raw(`undefined`), expected: schema->S.toUnknown}), + operation: Parsing, + path: S.Path.fromLocation("bar"), + }, + ) }) test("Fails to parse matrix field", t => { let schema = S.json let data = %raw(`[1,[undefined]]`) - t->U.assertErrorResult(data->S.parseWith(schema), { - code: InvalidType({received: %raw(`undefined`), expected: schema->S.toUnknown}), - operation: Parsing, - path: S.Path.fromArray(["1", "0"]), - }) + t->U.assertErrorResult( + data->S.parseWith(schema), + { + code: InvalidType({received: %raw(`undefined`), expected: schema->S.toUnknown}), + operation: Parsing, + path: S.Path.fromArray(["1", "0"]), + }, + ) }) test("Fails to parse NaN", t => { let schema = S.json - t->U.assertErrorResult(%raw(`NaN`)->S.parseAnyWith(schema), { - code: InvalidType({received: %raw(`NaN`), expected: schema->S.toUnknown}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + %raw(`NaN`)->S.parseAnyWith(schema), + { + code: InvalidType({received: %raw(`NaN`), expected: schema->S.toUnknown}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Fails to parse undefined", t => { let schema = S.json - t->U.assertErrorResult(%raw(`undefined`)->S.parseAnyWith(schema), { - code: InvalidType({received: %raw(`undefined`), expected: schema->S.toUnknown}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + %raw(`undefined`)->S.parseAnyWith(schema), + { + code: InvalidType({received: %raw(`undefined`), expected: schema->S.toUnknown}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Compiled parse code snapshot", t => { diff --git a/packages/tests/src/core/S_list_test.res b/packages/tests/src/core/S_list_test.res index aab68537..84b9026d 100644 --- a/packages/tests/src/core/S_list_test.res +++ b/packages/tests/src/core/S_list_test.res @@ -35,11 +35,14 @@ module CommonWithNested = { test("Fails to parse nested", t => { let schema = factory() - t->U.assertErrorResult(nestedInvalidAny->S.parseAnyWith(schema), { - code: InvalidType({expected: S.string->S.toUnknown, received: 1->Obj.magic}), - operation: Parsing, - path: S.Path.fromArray(["1"]), - }) + t->U.assertErrorResult( + nestedInvalidAny->S.parseAnyWith(schema), + { + code: InvalidType({expected: S.string->S.toUnknown, received: 1->Obj.magic}), + operation: Parsing, + path: S.Path.fromArray(["1"]), + }, + ) }) test("Successfully serializes", t => { diff --git a/packages/tests/src/core/S_literal_NaN_test.res b/packages/tests/src/core/S_literal_NaN_test.res index 22e3925a..580e49a9 100644 --- a/packages/tests/src/core/S_literal_NaN_test.res +++ b/packages/tests/src/core/S_literal_NaN_test.res @@ -16,11 +16,14 @@ module Common = { test("Fails to parse invalid type", t => { let schema = factory() - t->U.assertErrorResult(invalidTypeAny->S.parseAnyWith(schema), { - code: InvalidLiteral({expected: S.Literal.parse(%raw(`NaN`)), received: invalidTypeAny}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + invalidTypeAny->S.parseAnyWith(schema), + { + code: InvalidLiteral({expected: S.Literal.parse(%raw(`NaN`)), received: invalidTypeAny}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Successfully serializes", t => { @@ -32,11 +35,14 @@ module Common = { test("Fails to serialize invalid value", t => { let schema = factory() - t->U.assertErrorResult(invalidValue->S.serializeToUnknownWith(schema), { - code: InvalidLiteral({expected: S.Literal.parse(%raw(`NaN`)), received: invalidValue}), - operation: Serializing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + invalidValue->S.serializeToUnknownWith(schema), + { + code: InvalidLiteral({expected: S.Literal.parse(%raw(`NaN`)), received: invalidValue}), + operation: Serializing, + path: S.Path.empty, + }, + ) }) test("Compiled parse code snapshot", t => { diff --git a/packages/tests/src/core/S_literal_Null_test.res b/packages/tests/src/core/S_literal_Null_test.res index 1675842a..c09ef021 100644 --- a/packages/tests/src/core/S_literal_Null_test.res +++ b/packages/tests/src/core/S_literal_Null_test.res @@ -17,11 +17,14 @@ module Common = { test("Fails to parse invalid type", t => { let schema = factory() - t->U.assertErrorResult(invalidTypeAny->S.parseAnyWith(schema), { - code: InvalidLiteral({expected: S.Literal.parse(%raw(`null`)), received: invalidTypeAny}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + invalidTypeAny->S.parseAnyWith(schema), + { + code: InvalidLiteral({expected: S.Literal.parse(%raw(`null`)), received: invalidTypeAny}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Successfully serializes", t => { @@ -33,11 +36,14 @@ module Common = { test("Fails to serialize invalid value", t => { let schema = factory() - t->U.assertErrorResult(invalidValue->S.serializeToUnknownWith(schema), { - code: InvalidLiteral({expected: S.Literal.parse(%raw(`null`)), received: invalidValue}), - operation: Serializing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + invalidValue->S.serializeToUnknownWith(schema), + { + code: InvalidLiteral({expected: S.Literal.parse(%raw(`null`)), received: invalidValue}), + operation: Serializing, + path: S.Path.empty, + }, + ) }) test("Compiled parse code snapshot", t => { diff --git a/packages/tests/src/core/S_literal_Number_test.res b/packages/tests/src/core/S_literal_Number_test.res index 7f57f2ba..f9ddbd80 100644 --- a/packages/tests/src/core/S_literal_Number_test.res +++ b/packages/tests/src/core/S_literal_Number_test.res @@ -17,21 +17,27 @@ module Common = { test("Fails to parse invalid value", t => { let schema = factory() - t->U.assertErrorResult(invalidAny->S.parseAnyWith(schema), { - code: InvalidLiteral({expected: S.Literal.parse(123.), received: 444.->Obj.magic}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + invalidAny->S.parseAnyWith(schema), + { + code: InvalidLiteral({expected: S.Literal.parse(123.), received: 444.->Obj.magic}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Fails to parse invalid type", t => { let schema = factory() - t->U.assertErrorResult(invalidTypeAny->S.parseAnyWith(schema), { - code: InvalidLiteral({expected: S.Literal.parse(123.), received: invalidTypeAny}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + invalidTypeAny->S.parseAnyWith(schema), + { + code: InvalidLiteral({expected: S.Literal.parse(123.), received: invalidTypeAny}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Successfully serializes", t => { @@ -43,11 +49,14 @@ module Common = { test("Fails to serialize invalid value", t => { let schema = factory() - t->U.assertErrorResult(invalidValue->S.serializeToUnknownWith(schema), { - code: InvalidLiteral({expected: S.Literal.parse(123.), received: invalidValue}), - operation: Serializing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + invalidValue->S.serializeToUnknownWith(schema), + { + code: InvalidLiteral({expected: S.Literal.parse(123.), received: invalidValue}), + operation: Serializing, + path: S.Path.empty, + }, + ) }) test("Compiled parse code snapshot", t => { @@ -66,9 +75,12 @@ module Common = { test("Formatting of negative number with a decimal point in an error message", t => { let schema = S.literal(-123.567) - t->U.assertErrorResult(%raw(`"foo"`)->S.parseAnyWith(schema), { - code: InvalidLiteral({expected: S.Literal.parse(-123.567), received: "foo"->Obj.magic}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + %raw(`"foo"`)->S.parseAnyWith(schema), + { + code: InvalidLiteral({expected: S.Literal.parse(-123.567), received: "foo"->Obj.magic}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) diff --git a/packages/tests/src/core/S_literal_Object_test.res b/packages/tests/src/core/S_literal_Object_test.res index 3cd7fc84..9cf7816a 100644 --- a/packages/tests/src/core/S_literal_Object_test.res +++ b/packages/tests/src/core/S_literal_Object_test.res @@ -27,14 +27,17 @@ module Common = { test("Fails to parse invalid", t => { let schema = factory() - t->U.assertErrorResult(invalid->S.parseAnyWith(schema), { - code: InvalidLiteral({ - expected: S.Literal.parse(Dict.fromArray([("foo", "bar")])), - received: invalid, - }), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + invalid->S.parseAnyWith(schema), + { + code: InvalidLiteral({ + expected: S.Literal.parse(Dict.fromArray([("foo", "bar")])), + received: invalid, + }), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Successfully serializes", t => { @@ -46,53 +49,65 @@ module Common = { test("Fails to serialize invalid", t => { let schema = factory() - t->U.assertErrorResult(invalid->S.serializeToUnknownWith(schema), { - code: InvalidLiteral({ - expected: S.Literal.parse(Dict.fromArray([("foo", "bar")])), - received: invalid->U.castAnyToUnknown, - }), - operation: Serializing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + invalid->S.serializeToUnknownWith(schema), + { + code: InvalidLiteral({ + expected: S.Literal.parse(Dict.fromArray([("foo", "bar")])), + received: invalid->U.castAnyToUnknown, + }), + operation: Serializing, + path: S.Path.empty, + }, + ) }) test("Fails to parse null", t => { let schema = factory() - t->U.assertErrorResult(%raw(`null`)->S.parseAnyWith(schema), { - code: InvalidLiteral({ - expected: S.Literal.parse(Dict.fromArray([("foo", "bar")])), - received: %raw(`null`), - }), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + %raw(`null`)->S.parseAnyWith(schema), + { + code: InvalidLiteral({ + expected: S.Literal.parse(Dict.fromArray([("foo", "bar")])), + received: %raw(`null`), + }), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Fails to parse value with excess fields", t => { let schema = factory() - t->U.assertErrorResult(%raw(`{"foo": "bar","excess":true}`)->S.parseAnyWith(schema), { - code: InvalidLiteral({ - expected: S.Literal.parse(Dict.fromArray([("foo", "bar")])), - received: %raw(`{"foo": "bar","excess": true}`), - }), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + %raw(`{"foo": "bar","excess":true}`)->S.parseAnyWith(schema), + { + code: InvalidLiteral({ + expected: S.Literal.parse(Dict.fromArray([("foo", "bar")])), + received: %raw(`{"foo": "bar","excess": true}`), + }), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Fails to parse non plain objects", t => { let schema = factory() - t->U.assertErrorResult(makeNotPlainValue()->S.parseAnyWith(schema), { - code: InvalidLiteral({ - expected: S.Literal.parse(Dict.fromArray([("foo", "bar")])), - received: makeNotPlainValue()->U.castAnyToUnknown, - }), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + makeNotPlainValue()->S.parseAnyWith(schema), + { + code: InvalidLiteral({ + expected: S.Literal.parse(Dict.fromArray([("foo", "bar")])), + received: makeNotPlainValue()->U.castAnyToUnknown, + }), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Compiled parse code snapshot", t => { diff --git a/packages/tests/src/core/S_literal_String_test.res b/packages/tests/src/core/S_literal_String_test.res index 3cc51609..13504d53 100644 --- a/packages/tests/src/core/S_literal_String_test.res +++ b/packages/tests/src/core/S_literal_String_test.res @@ -17,27 +17,33 @@ module Common = { test("Fails to parse invalid value", t => { let schema = factory() - t->U.assertErrorResult(invalidAny->S.parseAnyWith(schema), { - code: InvalidLiteral({ - expected: S.Literal.parse("ReScript is Great!"), - received: "Hello world!"->Obj.magic, - }), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + invalidAny->S.parseAnyWith(schema), + { + code: InvalidLiteral({ + expected: S.Literal.parse("ReScript is Great!"), + received: "Hello world!"->Obj.magic, + }), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Fails to parse invalid type", t => { let schema = factory() - t->U.assertErrorResult(invalidTypeAny->S.parseAnyWith(schema), { - code: InvalidLiteral({ - expected: S.Literal.parse("ReScript is Great!"), - received: invalidTypeAny, - }), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + invalidTypeAny->S.parseAnyWith(schema), + { + code: InvalidLiteral({ + expected: S.Literal.parse("ReScript is Great!"), + received: invalidTypeAny, + }), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Successfully serializes", t => { diff --git a/packages/tests/src/core/S_literal_Undefined_test.res b/packages/tests/src/core/S_literal_Undefined_test.res index 479e0e4a..43ab9c03 100644 --- a/packages/tests/src/core/S_literal_Undefined_test.res +++ b/packages/tests/src/core/S_literal_Undefined_test.res @@ -16,11 +16,14 @@ module Common = { test("Fails to parse invalid type", t => { let schema = factory() - t->U.assertErrorResult(invalidTypeAny->S.parseAnyWith(schema), { - code: InvalidLiteral({expected: S.Literal.parse(None), received: invalidTypeAny}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + invalidTypeAny->S.parseAnyWith(schema), + { + code: InvalidLiteral({expected: S.Literal.parse(None), received: invalidTypeAny}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Successfully serializes", t => { @@ -32,11 +35,14 @@ module Common = { test("Fails to serialize invalid value", t => { let schema = factory() - t->U.assertErrorResult(invalidValue->S.serializeToUnknownWith(schema), { - code: InvalidLiteral({expected: S.Literal.parse(None), received: invalidValue}), - operation: Serializing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + invalidValue->S.serializeToUnknownWith(schema), + { + code: InvalidLiteral({expected: S.Literal.parse(None), received: invalidValue}), + operation: Serializing, + path: S.Path.empty, + }, + ) }) test("Compiled parse code snapshot", t => { diff --git a/packages/tests/src/core/S_never_test.res b/packages/tests/src/core/S_never_test.res index 05298e2c..069e6e0e 100644 --- a/packages/tests/src/core/S_never_test.res +++ b/packages/tests/src/core/S_never_test.res @@ -7,21 +7,27 @@ module Common = { test("Fails to ", t => { let schema = factory() - t->U.assertErrorResult(any->S.parseAnyWith(schema), { - code: InvalidType({expected: S.never->S.toUnknown, received: any}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + any->S.parseAnyWith(schema), + { + code: InvalidType({expected: S.never->S.toUnknown, received: any}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Fails to serialize ", t => { let schema = factory() - t->U.assertErrorResult(any->S.serializeToUnknownWith(schema), { - code: InvalidType({expected: schema->S.toUnknown, received: any}), - operation: Serializing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + any->S.serializeToUnknownWith(schema), + { + code: InvalidType({expected: schema->S.toUnknown, received: any}), + operation: Serializing, + path: S.Path.empty, + }, + ) }) test("Compiled parse code snapshot", t => { @@ -46,11 +52,14 @@ module ObjectField = { } ) - t->U.assertErrorResult(%raw(`{"key":"value"}`)->S.parseAnyWith(schema), { - code: InvalidType({expected: S.never->S.toUnknown, received: %raw(`undefined`)}), - operation: Parsing, - path: S.Path.fromArray(["oldKey"]), - }) + t->U.assertErrorResult( + %raw(`{"key":"value"}`)->S.parseAnyWith(schema), + { + code: InvalidType({expected: S.never->S.toUnknown, received: %raw(`undefined`)}), + operation: Parsing, + path: S.Path.fromArray(["oldKey"]), + }, + ) }) test("Successfully parses a object with Never field when it's optional and not present", t => { diff --git a/packages/tests/src/core/S_null_test.res b/packages/tests/src/core/S_null_test.res index ba95afc1..8c6249e5 100644 --- a/packages/tests/src/core/S_null_test.res +++ b/packages/tests/src/core/S_null_test.res @@ -16,11 +16,14 @@ module Common = { test("Fails to parse", t => { let schema = factory() - t->U.assertErrorResult(invalidAny->S.parseAnyWith(schema), { - code: InvalidType({expected: schema->S.toUnknown, received: invalidAny}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + invalidAny->S.parseAnyWith(schema), + { + code: InvalidType({expected: schema->S.toUnknown, received: invalidAny}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Successfully serializes", t => { @@ -69,32 +72,41 @@ test("Successfully parses primitive", t => { test("Fails to parse JS undefined", t => { let schema = S.null(S.bool) - t->U.assertErrorResult(%raw(`undefined`)->S.parseAnyWith(schema), { - code: InvalidType({expected: schema->S.toUnknown, received: %raw(`undefined`)}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + %raw(`undefined`)->S.parseAnyWith(schema), + { + code: InvalidType({expected: schema->S.toUnknown, received: %raw(`undefined`)}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Fails to parse object with missing field that marked as null", t => { let fieldSchema = S.null(S.string) let schema = S.object(s => s.field("nullableField", fieldSchema)) - t->U.assertErrorResult(%raw(`{}`)->S.parseAnyWith(schema), { - code: InvalidType({expected: fieldSchema->S.toUnknown, received: %raw(`undefined`)}), - operation: Parsing, - path: S.Path.fromArray(["nullableField"]), - }) + t->U.assertErrorResult( + %raw(`{}`)->S.parseAnyWith(schema), + { + code: InvalidType({expected: fieldSchema->S.toUnknown, received: %raw(`undefined`)}), + operation: Parsing, + path: S.Path.fromArray(["nullableField"]), + }, + ) }) test("Fails to parse JS null when schema doesn't allow optional data", t => { let schema = S.bool - t->U.assertErrorResult(%raw(`null`)->S.parseAnyWith(schema), { - code: InvalidType({expected: schema->S.toUnknown, received: %raw(`null`)}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + %raw(`null`)->S.parseAnyWith(schema), + { + code: InvalidType({expected: schema->S.toUnknown, received: %raw(`null`)}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Successfully parses null and serializes it back for deprecated nullable schema", t => { diff --git a/packages/tests/src/core/S_nullable_test.res b/packages/tests/src/core/S_nullable_test.res index 1fe9bd79..a81bbd31 100644 --- a/packages/tests/src/core/S_nullable_test.res +++ b/packages/tests/src/core/S_nullable_test.res @@ -16,11 +16,14 @@ module NullCommon = { test("Fails to parse", t => { let schema = factory() - t->U.assertErrorResult(invalidAny->S.parseAnyWith(schema), { - code: InvalidType({expected: schema->S.toUnknown, received: invalidAny}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + invalidAny->S.parseAnyWith(schema), + { + code: InvalidType({expected: schema->S.toUnknown, received: invalidAny}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Successfully serializes (to undefined)", t => { diff --git a/packages/tests/src/core/S_object_escaping_test.res b/packages/tests/src/core/S_object_escaping_test.res index e837f0be..a3180588 100644 --- a/packages/tests/src/core/S_object_escaping_test.res +++ b/packages/tests/src/core/S_object_escaping_test.res @@ -219,11 +219,14 @@ test("Has proper error path when fails to parse object with quotes in a field na } ) - t->U.assertErrorResult(%raw(`{"\"\'\`": "bar"}`)->S.parseAnyWith(schema), { - code: OperationFailed("User error"), - operation: Parsing, - path: S.Path.fromArray(["\"\'\`"]), - }) + t->U.assertErrorResult( + %raw(`{"\"\'\`": "bar"}`)->S.parseAnyWith(schema), + { + code: OperationFailed("User error"), + operation: Parsing, + path: S.Path.fromArray(["\"\'\`"]), + }, + ) }) test("Has proper error path when fails to serialize object with quotes in a field name", t => { @@ -233,11 +236,14 @@ test("Has proper error path when fails to serialize object with quotes in a fiel ]) ) - t->U.assertErrorResult(Dict.fromArray([("\"\'\`", "bar")])->S.serializeToUnknownWith(schema), { - code: OperationFailed("User error"), - operation: Serializing, - path: S.Path.fromArray(["\"\'\`"]), - }) + t->U.assertErrorResult( + Dict.fromArray([("\"\'\`", "bar")])->S.serializeToUnknownWith(schema), + { + code: OperationFailed("User error"), + operation: Serializing, + path: S.Path.fromArray(["\"\'\`"]), + }, + ) }) test("Field name in a format of a path is handled properly", t => { @@ -247,9 +253,12 @@ test("Field name in a format of a path is handled properly", t => { } ) - t->U.assertErrorResult(%raw(`{"bar": "foo"}`)->S.parseAnyWith(schema), { - code: InvalidType({expected: S.string->S.toUnknown, received: %raw(`undefined`)}), - operation: Parsing, - path: S.Path.fromArray([`["abc"]["cde"]`]), - }) + t->U.assertErrorResult( + %raw(`{"bar": "foo"}`)->S.parseAnyWith(schema), + { + code: InvalidType({expected: S.string->S.toUnknown, received: %raw(`undefined`)}), + operation: Parsing, + path: S.Path.fromArray([`["abc"]["cde"]`]), + }, + ) }) diff --git a/packages/tests/src/core/S_object_test.res b/packages/tests/src/core/S_object_test.res index e2bcc5d5..a21da339 100644 --- a/packages/tests/src/core/S_object_test.res +++ b/packages/tests/src/core/S_object_test.res @@ -21,11 +21,14 @@ test("Fails to parse object with inlinable string field", t => { } ) - t->U.assertErrorResult(%raw(`{field: 123}`)->S.parseAnyWith(schema), { - code: InvalidType({expected: S.string->S.toUnknown, received: %raw(`123`)}), - operation: Parsing, - path: S.Path.fromArray(["field"]), - }) + t->U.assertErrorResult( + %raw(`{field: 123}`)->S.parseAnyWith(schema), + { + code: InvalidType({expected: S.string->S.toUnknown, received: %raw(`123`)}), + operation: Parsing, + path: S.Path.fromArray(["field"]), + }, + ) }) test( @@ -37,11 +40,14 @@ test( } ) - t->U.assertErrorResult(%raw(`{field: ["foo"]}`)->S.parseAnyWith(schema), { - code: OperationFailed("User error"), - operation: Parsing, - path: S.Path.fromArray(["field", "0"]), - }) + t->U.assertErrorResult( + %raw(`{field: ["foo"]}`)->S.parseAnyWith(schema), + { + code: OperationFailed("User error"), + operation: Parsing, + path: S.Path.fromArray(["field", "0"]), + }, + ) }, ) @@ -62,11 +68,14 @@ test("Fails to parse object with inlinable bool field", t => { } ) - t->U.assertErrorResult(%raw(`{field: 123}`)->S.parseAnyWith(schema), { - code: InvalidType({expected: S.bool->S.toUnknown, received: %raw(`123`)}), - operation: Parsing, - path: S.Path.fromArray(["field"]), - }) + t->U.assertErrorResult( + %raw(`{field: 123}`)->S.parseAnyWith(schema), + { + code: InvalidType({expected: S.bool->S.toUnknown, received: %raw(`123`)}), + operation: Parsing, + path: S.Path.fromArray(["field"]), + }, + ) }) test("Successfully parses object with unknown field (Noop operation)", t => { @@ -104,11 +113,14 @@ test("Fails to parse object with inlinable never field", t => { } ) - t->U.assertErrorResult(%raw(`{field: true}`)->S.parseAnyWith(schema), { - code: InvalidType({expected: S.never->S.toUnknown, received: %raw(`true`)}), - operation: Parsing, - path: S.Path.fromArray(["field"]), - }) + t->U.assertErrorResult( + %raw(`{field: true}`)->S.parseAnyWith(schema), + { + code: InvalidType({expected: S.never->S.toUnknown, received: %raw(`true`)}), + operation: Parsing, + path: S.Path.fromArray(["field"]), + }, + ) }) test("Successfully parses object with inlinable float field", t => { @@ -128,11 +140,14 @@ test("Fails to parse object with inlinable float field", t => { } ) - t->U.assertErrorResult(%raw(`{field: true}`)->S.parseAnyWith(schema), { - code: InvalidType({expected: S.float->S.toUnknown, received: %raw(`true`)}), - operation: Parsing, - path: S.Path.fromArray(["field"]), - }) + t->U.assertErrorResult( + %raw(`{field: true}`)->S.parseAnyWith(schema), + { + code: InvalidType({expected: S.float->S.toUnknown, received: %raw(`true`)}), + operation: Parsing, + path: S.Path.fromArray(["field"]), + }, + ) }) test("Successfully parses object with inlinable int field", t => { @@ -152,11 +167,14 @@ test("Fails to parse object with inlinable int field", t => { } ) - t->U.assertErrorResult(%raw(`{field: true}`)->S.parseAnyWith(schema), { - code: InvalidType({expected: S.int->S.toUnknown, received: %raw(`true`)}), - operation: Parsing, - path: S.Path.fromArray(["field"]), - }) + t->U.assertErrorResult( + %raw(`{field: true}`)->S.parseAnyWith(schema), + { + code: InvalidType({expected: S.int->S.toUnknown, received: %raw(`true`)}), + operation: Parsing, + path: S.Path.fromArray(["field"]), + }, + ) }) test("Successfully parses object with not inlinable empty object field", t => { @@ -177,11 +195,14 @@ test("Fails to parse object with not inlinable empty object field", t => { } ) - t->U.assertErrorResult(%raw(`{field: true}`)->S.parseAnyWith(schema), { - code: InvalidType({expected: fieldSchema->S.toUnknown, received: %raw(`true`)}), - operation: Parsing, - path: S.Path.fromArray(["field"]), - }) + t->U.assertErrorResult( + %raw(`{field: true}`)->S.parseAnyWith(schema), + { + code: InvalidType({expected: fieldSchema->S.toUnknown, received: %raw(`true`)}), + operation: Parsing, + path: S.Path.fromArray(["field"]), + }, + ) }) test("Fails to parse object when provided invalid data", t => { @@ -191,11 +212,14 @@ test("Fails to parse object when provided invalid data", t => { } ) - t->U.assertErrorResult(%raw(`12`)->S.parseAnyWith(schema), { - code: InvalidType({expected: schema->S.toUnknown, received: %raw(`12`)}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + %raw(`12`)->S.parseAnyWith(schema), + { + code: InvalidType({expected: schema->S.toUnknown, received: %raw(`12`)}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Successfully serializes object with single field", t => { @@ -266,11 +290,14 @@ test("Fails to parse object when transformed field has raises error", t => { } ) - t->U.assertErrorResult({"field": "bar"}->S.parseAnyWith(schema), { - code: OperationFailed("User error"), - operation: Parsing, - path: S.Path.fromArray(["field"]), - }) + t->U.assertErrorResult( + {"field": "bar"}->S.parseAnyWith(schema), + { + code: OperationFailed("User error"), + operation: Parsing, + path: S.Path.fromArray(["field"]), + }, + ) }) test("Shows transformed object field name in error path when fails to parse", t => { @@ -283,11 +310,14 @@ test("Shows transformed object field name in error path when fails to parse", t } ) - t->U.assertErrorResult({"originalFieldName": "bar"}->S.parseAnyWith(schema), { - code: OperationFailed("User error"), - operation: Parsing, - path: S.Path.fromArray(["originalFieldName"]), - }) + t->U.assertErrorResult( + {"originalFieldName": "bar"}->S.parseAnyWith(schema), + { + code: OperationFailed("User error"), + operation: Parsing, + path: S.Path.fromArray(["originalFieldName"]), + }, + ) }) test("Successfully serializes object with transformed field", t => { @@ -317,11 +347,14 @@ test("Fails to serializes object when transformed field has raises error", t => } ) - t->U.assertErrorResult({"field": "bar"}->S.serializeToUnknownWith(schema), { - code: OperationFailed("User error"), - operation: Serializing, - path: S.Path.fromArray(["field"]), - }) + t->U.assertErrorResult( + {"field": "bar"}->S.serializeToUnknownWith(schema), + { + code: OperationFailed("User error"), + operation: Serializing, + path: S.Path.fromArray(["field"]), + }, + ) }) test("Shows transformed object field name in error path when fails to serializes", t => { @@ -334,11 +367,14 @@ test("Shows transformed object field name in error path when fails to serializes } ) - t->U.assertErrorResult({"transformedFieldName": "bar"}->S.serializeToUnknownWith(schema), { - code: OperationFailed("User error"), - operation: Serializing, - path: S.Path.fromArray(["transformedFieldName"]), - }) + t->U.assertErrorResult( + {"transformedFieldName": "bar"}->S.serializeToUnknownWith(schema), + { + code: OperationFailed("User error"), + operation: Serializing, + path: S.Path.fromArray(["transformedFieldName"]), + }, + ) }) test("Shows transformed to nested object field name in error path when fails to serializes", t => { @@ -353,15 +389,18 @@ test("Shows transformed to nested object field name in error path when fails to } ) - t->U.assertErrorResult({ + t->U.assertErrorResult( + { "v1": { "transformedFieldName": "bar", }, - }->S.serializeToUnknownWith(schema), { - code: OperationFailed("User error"), - operation: Serializing, - path: S.Path.fromArray(["v1", "transformedFieldName"]), - }) + }->S.serializeToUnknownWith(schema), + { + code: OperationFailed("User error"), + operation: Serializing, + path: S.Path.fromArray(["v1", "transformedFieldName"]), + }, + ) }) test("Successfully parses object with optional fields", t => { @@ -867,13 +906,16 @@ test("Fails to serialize object schema with single field registered multiple tim "field2": field, } }) - t->U.assertErrorResult({"field1": "foo", "field2": "foo"}->S.serializeToUnknownWith(schema), { - code: InvalidOperation({ - description: `The field "field" is registered multiple times. If you want to duplicate the field, use S.transform instead`, - }), - operation: Serializing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + {"field1": "foo", "field2": "foo"}->S.serializeToUnknownWith(schema), + { + code: InvalidOperation({ + description: `The field "field" is registered multiple times. If you want to duplicate the field, use S.transform instead`, + }), + operation: Serializing, + path: S.Path.empty, + }, + ) }) test("Object schema parsing checks order", t => { diff --git a/packages/tests/src/core/S_object_withoutDeclaredFields_test.res b/packages/tests/src/core/S_object_withoutDeclaredFields_test.res index 7405c271..c738302f 100644 --- a/packages/tests/src/core/S_object_withoutDeclaredFields_test.res +++ b/packages/tests/src/core/S_object_withoutDeclaredFields_test.res @@ -45,9 +45,12 @@ test("Successfully serializes transformed value to empty object", t => { test("Fails to parse array data", t => { let schema = S.object(_ => ()) - t->U.assertErrorResult(%raw(`[]`)->S.parseAnyWith(schema), { - code: InvalidType({expected: schema->S.toUnknown, received: %raw(`[]`)}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + %raw(`[]`)->S.parseAnyWith(schema), + { + code: InvalidType({expected: schema->S.toUnknown, received: %raw(`[]`)}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) diff --git a/packages/tests/src/core/S_option_test.res b/packages/tests/src/core/S_option_test.res index 22eb7e3a..ede18133 100644 --- a/packages/tests/src/core/S_option_test.res +++ b/packages/tests/src/core/S_option_test.res @@ -16,11 +16,14 @@ module Common = { test("Fails to parse", t => { let schema = factory() - t->U.assertErrorResult(invalidAny->S.parseAnyWith(schema), { - code: InvalidType({expected: schema->S.toUnknown, received: invalidAny}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + invalidAny->S.parseAnyWith(schema), + { + code: InvalidType({expected: schema->S.toUnknown, received: invalidAny}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Successfully serializes", t => { @@ -69,21 +72,27 @@ test("Successfully parses primitive", t => { test("Fails to parse JS null", t => { let schema = S.option(S.bool) - t->U.assertErrorResult(%raw(`null`)->S.parseAnyWith(schema), { - code: InvalidType({expected: schema->S.toUnknown, received: %raw(`null`)}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + %raw(`null`)->S.parseAnyWith(schema), + { + code: InvalidType({expected: schema->S.toUnknown, received: %raw(`null`)}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Fails to parse JS undefined when schema doesn't allow optional data", t => { let schema = S.bool - t->U.assertErrorResult(%raw(`undefined`)->S.parseAnyWith(schema), { - code: InvalidType({expected: schema->S.toUnknown, received: %raw(`undefined`)}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + %raw(`undefined`)->S.parseAnyWith(schema), + { + code: InvalidType({expected: schema->S.toUnknown, received: %raw(`undefined`)}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Parses option nested in null as None instead of Some(None)", t => { diff --git a/packages/tests/src/core/S_parseJsonStringWith_test.res b/packages/tests/src/core/S_parseJsonStringWith_test.res index 437ed8e8..54a35e01 100644 --- a/packages/tests/src/core/S_parseJsonStringWith_test.res +++ b/packages/tests/src/core/S_parseJsonStringWith_test.res @@ -33,9 +33,12 @@ test("Fails to parse JSON", t => { test("Fails to parse", t => { let schema = S.bool - t->U.assertErrorResult("123"->S.parseJsonStringWith(schema), { - code: InvalidType({expected: schema->S.toUnknown, received: Obj.magic(123)}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + "123"->S.parseJsonStringWith(schema), + { + code: InvalidType({expected: schema->S.toUnknown, received: Obj.magic(123)}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) diff --git a/packages/tests/src/core/S_parseWith_test.res b/packages/tests/src/core/S_parseWith_test.res index b01256b4..bf7fa2fe 100644 --- a/packages/tests/src/core/S_parseWith_test.res +++ b/packages/tests/src/core/S_parseWith_test.res @@ -16,9 +16,12 @@ test("Successfully parses unknown", t => { test("Fails to parse", t => { let schema = S.bool - t->U.assertErrorResult(%raw("123")->S.parseWith(schema), { - code: InvalidType({expected: schema->S.toUnknown, received: %raw("123")}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + %raw("123")->S.parseWith(schema), + { + code: InvalidType({expected: schema->S.toUnknown, received: %raw("123")}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) diff --git a/packages/tests/src/core/S_preprocess_test.res b/packages/tests/src/core/S_preprocess_test.res index 9bf8240d..31b6e616 100644 --- a/packages/tests/src/core/S_preprocess_test.res +++ b/packages/tests/src/core/S_preprocess_test.res @@ -53,7 +53,10 @@ test("Successfully serializes", t => { test("Fails to serialize when user raises error in serializer", t => { let schema = S.string->S.preprocess(s => {serializer: _ => s.fail("User error")}) - t->U.assertErrorResult("Hello world!"->S.serializeToUnknownWith(schema), {code: OperationFailed("User error"), operation: Serializing, path: S.Path.empty}) + t->U.assertErrorResult( + "Hello world!"->S.serializeToUnknownWith(schema), + {code: OperationFailed("User error"), operation: Serializing, path: S.Path.empty}, + ) }) test("Preprocess operations applyed in the right order when parsing", t => { @@ -62,7 +65,10 @@ test("Preprocess operations applyed in the right order when parsing", t => { ->S.preprocess(s => {parser: _ => s.fail("First preprocess")}) ->S.preprocess(s => {parser: _ => s.fail("Second preprocess")}) - t->U.assertErrorResult(123->S.parseAnyWith(schema), {code: OperationFailed("Second preprocess"), operation: Parsing, path: S.Path.empty}) + t->U.assertErrorResult( + 123->S.parseAnyWith(schema), + {code: OperationFailed("Second preprocess"), operation: Parsing, path: S.Path.empty}, + ) }) test("Preprocess operations applyed in the right order when serializing", t => { @@ -71,11 +77,14 @@ test("Preprocess operations applyed in the right order when serializing", t => { ->S.preprocess(s => {serializer: _ => s.fail("First preprocess")}) ->S.preprocess(s => {serializer: _ => s.fail("Second preprocess")}) - t->U.assertErrorResult(123->S.serializeToUnknownWith(schema), { - code: OperationFailed("First preprocess"), - operation: Serializing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + 123->S.serializeToUnknownWith(schema), + { + code: OperationFailed("First preprocess"), + operation: Serializing, + path: S.Path.empty, + }, + ) }) test("Fails to parse async using parseAnyWith", t => { @@ -104,11 +113,14 @@ asyncTest("Fails to parse async with user error", t => { %raw(`"Hello world!"`) ->S.parseAsyncWith(schema) ->Promise.thenResolve(result => { - t->U.assertErrorResult(result, { - code: OperationFailed("User error"), - path: S.Path.empty, - operation: Parsing, - }) + t->U.assertErrorResult( + result, + { + code: OperationFailed("User error"), + path: S.Path.empty, + operation: Parsing, + }, + ) }) }) diff --git a/packages/tests/src/core/S_recursive_test.res b/packages/tests/src/core/S_recursive_test.res index 8c274cf6..b2afd14e 100644 --- a/packages/tests/src/core/S_recursive_test.res +++ b/packages/tests/src/core/S_recursive_test.res @@ -109,17 +109,20 @@ test("Fails to parse nested recursive object", t => { ) }) - t->U.assertErrorResult({ + t->U.assertErrorResult( + { "Id": "1", "Children": [ {"Id": "2", "Children": []}, {"Id": "3", "Children": [{"Id": "4", "Children": []}]}, ], - }->S.parseAnyWith(nodeSchema), { - code: OperationFailed("Invalid id"), - operation: Parsing, - path: S.Path.fromArray(["Children", "1", "Children", "0", "Id"]), - }) + }->S.parseAnyWith(nodeSchema), + { + code: OperationFailed("Invalid id"), + operation: Parsing, + path: S.Path.fromArray(["Children", "1", "Children", "0", "Id"]), + }, + ) }) test("Fails to parse nested recursive object inside of another object", t => { @@ -148,7 +151,8 @@ test("Fails to parse nested recursive object inside of another object", t => { ) ) - t->U.assertErrorResult({ + t->U.assertErrorResult( + { "recursive": { "Id": "1", "Children": [ @@ -156,11 +160,13 @@ test("Fails to parse nested recursive object inside of another object", t => { {"Id": "3", "Children": [{"Id": "4", "Children": []}]}, ], }, - }->S.parseAnyWith(schema), { - code: OperationFailed("Invalid id"), - operation: Parsing, - path: S.Path.fromArray(["recursive", "Children", "1", "Children", "0", "Id"]), - }) + }->S.parseAnyWith(schema), + { + code: OperationFailed("Invalid id"), + operation: Parsing, + path: S.Path.fromArray(["recursive", "Children", "1", "Children", "0", "Id"]), + }, + ) }) test("Fails to serialise nested recursive object", t => { @@ -182,14 +188,17 @@ test("Fails to serialise nested recursive object", t => { ) }) - t->U.assertErrorResult({ + t->U.assertErrorResult( + { id: "1", children: [{id: "2", children: []}, {id: "3", children: [{id: "4", children: []}]}], - }->S.serializeToUnknownWith(nodeSchema), { - code: OperationFailed("Invalid id"), - operation: Serializing, - path: S.Path.fromArray(["children", "1", "children", "0", "id"]), - }) + }->S.serializeToUnknownWith(nodeSchema), + { + code: OperationFailed("Invalid id"), + operation: Serializing, + path: S.Path.fromArray(["children", "1", "children", "0", "id"]), + }, + ) }) test( diff --git a/packages/tests/src/core/S_refine_test.res b/packages/tests/src/core/S_refine_test.res index 5b860e86..5901f4c4 100644 --- a/packages/tests/src/core/S_refine_test.res +++ b/packages/tests/src/core/S_refine_test.res @@ -7,11 +7,14 @@ test("Successfully refines on parsing", t => { }) t->Assert.deepEqual(%raw(`12`)->S.parseAnyWith(schema), Ok(12), ()) - t->U.assertErrorResult(%raw(`-12`)->S.parseAnyWith(schema), { - code: OperationFailed("Should be positive"), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + %raw(`-12`)->S.parseAnyWith(schema), + { + code: OperationFailed("Should be positive"), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Fails with custom path", t => { @@ -20,11 +23,14 @@ test("Fails with custom path", t => { s.fail(~path=S.Path.fromArray(["data", "myInt"]), "Should be positive") }) - t->U.assertErrorResult(%raw(`-12`)->S.parseAnyWith(schema), { - code: OperationFailed("Should be positive"), - operation: Parsing, - path: S.Path.fromArray(["data", "myInt"]), - }) + t->U.assertErrorResult( + %raw(`-12`)->S.parseAnyWith(schema), + { + code: OperationFailed("Should be positive"), + operation: Parsing, + path: S.Path.fromArray(["data", "myInt"]), + }, + ) }) test("Successfully refines on serializing", t => { @@ -34,11 +40,14 @@ test("Successfully refines on serializing", t => { }) t->Assert.deepEqual(12->S.serializeToUnknownWith(schema), Ok(%raw("12")), ()) - t->U.assertErrorResult(-12->S.serializeToUnknownWith(schema), { - code: OperationFailed("Should be positive"), - operation: Serializing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + -12->S.serializeToUnknownWith(schema), + { + code: OperationFailed("Should be positive"), + operation: Serializing, + path: S.Path.empty, + }, + ) }) test("Compiled parse code snapshot for simple object with refine", t => { diff --git a/packages/tests/src/core/S_serializeWith_test.res b/packages/tests/src/core/S_serializeWith_test.res index d6006da3..60aecf0c 100644 --- a/packages/tests/src/core/S_serializeWith_test.res +++ b/packages/tests/src/core/S_serializeWith_test.res @@ -71,109 +71,148 @@ test("Successfully serializes jsonable schemas", t => { test("Fails to serialize Option schema", t => { let schema = S.option(S.bool) - t->U.assertErrorResult(None->S.serializeWith(schema), { - code: InvalidJsonStruct(schema->S.toUnknown), - operation: Serializing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + None->S.serializeWith(schema), + { + code: InvalidJsonStruct(schema->S.toUnknown), + operation: Serializing, + path: S.Path.empty, + }, + ) }) test("Fails to serialize Undefined literal", t => { let schema = S.literal() - t->U.assertErrorResult(()->S.serializeWith(schema), { - code: InvalidJsonStruct(schema->S.toUnknown), - operation: Serializing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + ()->S.serializeWith(schema), + { + code: InvalidJsonStruct(schema->S.toUnknown), + operation: Serializing, + path: S.Path.empty, + }, + ) }) test("Fails to serialize Function literal", t => { let fn = () => () let schema = S.literal(fn) - t->U.assertErrorResult(fn->S.serializeWith(schema), { - code: InvalidJsonStruct(schema->S.toUnknown), - operation: Serializing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + fn->S.serializeWith(schema), + { + code: InvalidJsonStruct(schema->S.toUnknown), + operation: Serializing, + path: S.Path.empty, + }, + ) }) test("Fails to serialize Object literal", t => { let error = %raw(`new Error("foo")`) let schema = S.literal(error) - t->U.assertErrorResult(error->S.serializeWith(schema), { - code: InvalidJsonStruct(schema->S.toUnknown), - operation: Serializing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + error->S.serializeWith(schema), + { + code: InvalidJsonStruct(schema->S.toUnknown), + operation: Serializing, + path: S.Path.empty, + }, + ) }) test("Fails to serialize Symbol literal", t => { let symbol = %raw(`Symbol()`) let schema = S.literal(symbol) - t->U.assertErrorResult(symbol->S.serializeWith(schema), { - code: InvalidJsonStruct(schema->S.toUnknown), - operation: Serializing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + symbol->S.serializeWith(schema), + { + code: InvalidJsonStruct(schema->S.toUnknown), + operation: Serializing, + path: S.Path.empty, + }, + ) }) test("Fails to serialize BigInt literal", t => { let bigint = %raw(`1234n`) let schema = S.literal(bigint) - t->U.assertErrorResult(bigint->S.serializeWith(schema), { - code: InvalidJsonStruct(schema->S.toUnknown), - operation: Serializing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + bigint->S.serializeWith(schema), + { + code: InvalidJsonStruct(schema->S.toUnknown), + operation: Serializing, + path: S.Path.empty, + }, + ) }) test("Fails to serialize Dict literal with invalid field", t => { let dict = %raw(`{"foo": 123n}`) let schema = S.literal(dict) - t->U.assertErrorResult(dict->S.serializeWith(schema), { - code: InvalidJsonStruct(schema->S.toUnknown), - operation: Serializing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + dict->S.serializeWith(schema), + { + code: InvalidJsonStruct(schema->S.toUnknown), + operation: Serializing, + path: S.Path.empty, + }, + ) }) test("Fails to serialize NaN literal", t => { let schema = S.literal(%raw(`NaN`)) - t->U.assertErrorResult(()->S.serializeWith(schema), { - code: InvalidJsonStruct(schema->S.toUnknown), - operation: Serializing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + ()->S.serializeWith(schema), + { + code: InvalidJsonStruct(schema->S.toUnknown), + operation: Serializing, + path: S.Path.empty, + }, + ) }) test("Fails to serialize Unknown schema", t => { - t->U.assertErrorResult(Obj.magic(123)->S.serializeWith(S.unknown), {code: InvalidJsonStruct(S.unknown), operation: Serializing, path: S.Path.empty}) + t->U.assertErrorResult( + Obj.magic(123)->S.serializeWith(S.unknown), + {code: InvalidJsonStruct(S.unknown), operation: Serializing, path: S.Path.empty}, + ) }) test("Fails to serialize Never schema", t => { - t->U.assertErrorResult(Obj.magic(123)->S.serializeWith(S.never), { - code: InvalidType({expected: S.never->S.toUnknown, received: Obj.magic(123)}), - operation: Serializing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + Obj.magic(123)->S.serializeWith(S.never), + { + code: InvalidType({expected: S.never->S.toUnknown, received: Obj.magic(123)}), + operation: Serializing, + path: S.Path.empty, + }, + ) }) test("Fails to serialize object with invalid nested schema", t => { - t->U.assertErrorResult(Obj.magic(true)->S.serializeWith(S.object(s => s.field("foo", S.unknown))), { - code: InvalidJsonStruct(S.unknown), - operation: Serializing, - path: S.Path.fromArray(["foo"]), - }) + t->U.assertErrorResult( + Obj.magic(true)->S.serializeWith(S.object(s => s.field("foo", S.unknown))), + { + code: InvalidJsonStruct(S.unknown), + operation: Serializing, + path: S.Path.fromArray(["foo"]), + }, + ) }) test("Fails to serialize tuple with invalid nested schema", t => { - t->U.assertErrorResult(Obj.magic(true)->S.serializeWith(S.tuple1(S.unknown)), { - code: InvalidJsonStruct(S.unknown), - operation: Serializing, - path: S.Path.fromArray(["0"]), - }) + t->U.assertErrorResult( + Obj.magic(true)->S.serializeWith(S.tuple1(S.unknown)), + { + code: InvalidJsonStruct(S.unknown), + operation: Serializing, + path: S.Path.fromArray(["0"]), + }, + ) }) test("Fails to serialize union if one of the items is an invalid schema", t => { - t->U.assertErrorResult("foo"->S.serializeWith(S.union([S.string, S.unknown->(U.magic: S.t => S.t)])), {code: InvalidJsonStruct(S.unknown), operation: Serializing, path: S.Path.empty}) + t->U.assertErrorResult( + "foo"->S.serializeWith(S.union([S.string, S.unknown->(U.magic: S.t => S.t)])), + {code: InvalidJsonStruct(S.unknown), operation: Serializing, path: S.Path.empty}, + ) }) diff --git a/packages/tests/src/core/S_string_test.res b/packages/tests/src/core/S_string_test.res index 19415d1c..7e4b7314 100644 --- a/packages/tests/src/core/S_string_test.res +++ b/packages/tests/src/core/S_string_test.res @@ -15,11 +15,14 @@ module Common = { test("Fails to parse", t => { let schema = factory() - t->U.assertErrorResult(invalidAny->S.parseAnyWith(schema), { - code: InvalidType({expected: schema->S.toUnknown, received: invalidAny}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + invalidAny->S.parseAnyWith(schema), + { + code: InvalidType({expected: schema->S.toUnknown, received: invalidAny}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Successfully serializes", t => { diff --git a/packages/tests/src/core/S_transform_test.res b/packages/tests/src/core/S_transform_test.res index 5588e8df..1bea5a29 100644 --- a/packages/tests/src/core/S_transform_test.res +++ b/packages/tests/src/core/S_transform_test.res @@ -27,11 +27,14 @@ asyncTest( test("Fails to parse primitive with transform when parser isn't provided", t => { let schema = S.string->S.transform(_ => {serializer: value => value}) - t->U.assertErrorResult("Hello world!"->S.parseAnyWith(schema), { - code: InvalidOperation({description: "The S.transform parser is missing"}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + "Hello world!"->S.parseAnyWith(schema), + { + code: InvalidOperation({description: "The S.transform parser is missing"}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Fails to parse when user raises error in a Transformed Primitive parser", t => { @@ -58,11 +61,14 @@ test("Uses the path from failWithError called in the transform parser", t => { }), ) - t->U.assertErrorResult(["Hello world!"]->S.parseAnyWith(schema), { - code: OperationFailed("User error"), - operation: Parsing, - path: S.Path.fromArray(["0", "a", "b"]), - }) + t->U.assertErrorResult( + ["Hello world!"]->S.parseAnyWith(schema), + { + code: OperationFailed("User error"), + operation: Parsing, + path: S.Path.fromArray(["0", "a", "b"]), + }, + ) }) test("Uses the path from failWithError called in the transform serializer", t => { @@ -79,11 +85,14 @@ test("Uses the path from failWithError called in the transform serializer", t => }), ) - t->U.assertErrorResult(["Hello world!"]->S.serializeWith(schema), { - code: OperationFailed("User error"), - operation: Serializing, - path: S.Path.fromArray(["0", "a", "b"]), - }) + t->U.assertErrorResult( + ["Hello world!"]->S.serializeWith(schema), + { + code: OperationFailed("User error"), + operation: Serializing, + path: S.Path.fromArray(["0", "a", "b"]), + }, + ) }) test("Transform parser passes through non rescript-schema errors", t => { @@ -143,17 +152,23 @@ test("Successfully serializes primitive with transformation to another type", t test("Transformed Primitive serializing fails when serializer isn't provided", t => { let schema = S.string->S.transform(_ => {parser: value => value}) - t->U.assertErrorResult("Hello world!"->S.serializeToUnknownWith(schema), { - code: InvalidOperation({description: "The S.transform serializer is missing"}), - operation: Serializing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + "Hello world!"->S.serializeToUnknownWith(schema), + { + code: InvalidOperation({description: "The S.transform serializer is missing"}), + operation: Serializing, + path: S.Path.empty, + }, + ) }) test("Fails to serialize when user raises error in a Transformed Primitive serializer", t => { let schema = S.string->S.transform(s => {serializer: _ => s.fail("User error")}) - t->U.assertErrorResult("Hello world!"->S.serializeToUnknownWith(schema), {code: OperationFailed("User error"), operation: Serializing, path: S.Path.empty}) + t->U.assertErrorResult( + "Hello world!"->S.serializeToUnknownWith(schema), + {code: OperationFailed("User error"), operation: Serializing, path: S.Path.empty}, + ) }) test("Transform operations applyed in the right order when parsing", t => { @@ -162,7 +177,10 @@ test("Transform operations applyed in the right order when parsing", t => { ->S.transform(s => {parser: _ => s.fail("First transform")}) ->S.transform(s => {parser: _ => s.fail("Second transform")}) - t->U.assertErrorResult(123->S.parseAnyWith(schema), {code: OperationFailed("First transform"), operation: Parsing, path: S.Path.empty}) + t->U.assertErrorResult( + 123->S.parseAnyWith(schema), + {code: OperationFailed("First transform"), operation: Parsing, path: S.Path.empty}, + ) }) test("Transform operations applyed in the right order when serializing", t => { @@ -171,11 +189,14 @@ test("Transform operations applyed in the right order when serializing", t => { ->S.transform(s => {serializer: _ => s.fail("First transform")}) ->S.transform(s => {serializer: _ => s.fail("Second transform")}) - t->U.assertErrorResult(123->S.serializeToUnknownWith(schema), { - code: OperationFailed("Second transform"), - operation: Serializing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + 123->S.serializeToUnknownWith(schema), + { + code: OperationFailed("Second transform"), + operation: Serializing, + path: S.Path.empty, + }, + ) }) test( @@ -200,13 +221,16 @@ test("Fails to parse schema with transform having both parser and asyncParser", let schema = S.string->S.transform(_ => {parser: _ => (), asyncParser: _ => () => Promise.resolve()}) - t->U.assertErrorResult("foo"->S.parseAnyWith(schema), { - code: InvalidOperation({ - description: "The S.transform doesn\'t allow parser and asyncParser at the same time. Remove parser in favor of asyncParser.", - }), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + "foo"->S.parseAnyWith(schema), + { + code: InvalidOperation({ + description: "The S.transform doesn\'t allow parser and asyncParser at the same time. Remove parser in favor of asyncParser.", + }), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Fails to parse async using parseAnyWith", t => { @@ -251,11 +275,14 @@ asyncTest("Fails to parse async with user error", t => { %raw(`"Hello world!"`) ->S.parseAsyncWith(schema) ->Promise.thenResolve(result => { - t->U.assertErrorResult(result, { - code: OperationFailed("User error"), - path: S.Path.empty, - operation: Parsing, - }) + t->U.assertErrorResult( + result, + { + code: OperationFailed("User error"), + path: S.Path.empty, + operation: Parsing, + }, + ) }) }) diff --git a/packages/tests/src/core/S_tuple1_test.res b/packages/tests/src/core/S_tuple1_test.res index 64ba55e3..5fbbae1a 100644 --- a/packages/tests/src/core/S_tuple1_test.res +++ b/packages/tests/src/core/S_tuple1_test.res @@ -16,24 +16,30 @@ module Common = { test("Fails to parse invalid value", t => { let schema = factory() - t->U.assertErrorResult(invalidAny->S.parseAnyWith(schema), { - code: InvalidTupleSize({ - expected: 1, - received: 2, - }), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + invalidAny->S.parseAnyWith(schema), + { + code: InvalidTupleSize({ + expected: 1, + received: 2, + }), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Fails to parse invalid type", t => { let schema = factory() - t->U.assertErrorResult(invalidTypeAny->S.parseAnyWith(schema), { - code: InvalidType({expected: schema->S.toUnknown, received: invalidTypeAny}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + invalidTypeAny->S.parseAnyWith(schema), + { + code: InvalidType({expected: schema->S.toUnknown, received: invalidTypeAny}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Successfully serializes", t => { diff --git a/packages/tests/src/core/S_tuple2_test.res b/packages/tests/src/core/S_tuple2_test.res index cd656353..22c638cc 100644 --- a/packages/tests/src/core/S_tuple2_test.res +++ b/packages/tests/src/core/S_tuple2_test.res @@ -16,24 +16,30 @@ module Common = { test("Fails to parse invalid value", t => { let schema = factory() - t->U.assertErrorResult(invalidAny->S.parseAnyWith(schema), { - code: InvalidTupleSize({ - expected: 2, - received: 1, - }), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + invalidAny->S.parseAnyWith(schema), + { + code: InvalidTupleSize({ + expected: 2, + received: 1, + }), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Fails to parse invalid type", t => { let schema = factory() - t->U.assertErrorResult(invalidTypeAny->S.parseAnyWith(schema), { - code: InvalidType({expected: schema->S.toUnknown, received: invalidTypeAny}), - operation: Parsing, - path: S.Path.empty, - }) + t->U.assertErrorResult( + invalidTypeAny->S.parseAnyWith(schema), + { + code: InvalidType({expected: schema->S.toUnknown, received: invalidTypeAny}), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Successfully serializes", t => { diff --git a/packages/tests/src/core/S_union_test.res b/packages/tests/src/core/S_union_test.res index 6081b31b..556caa5a 100644 --- a/packages/tests/src/core/S_union_test.res +++ b/packages/tests/src/core/S_union_test.res @@ -209,36 +209,39 @@ module Advanced = { }) test("Fails to parse with invalid data type", t => { - t->U.assertErrorResult(%raw(`"Hello world!"`)->S.parseAnyWith(shapeSchema), { - code: InvalidUnion([ - U.error({ - code: InvalidType({ - expected: circleSchema->S.toUnknown, - received: %raw(`"Hello world!"`), - }), - operation: Parsing, - path: S.Path.empty, + t->U.assertErrorResult( + %raw(`"Hello world!"`)->S.parseAnyWith(shapeSchema), + { + code: InvalidUnion([ + U.error({ + code: InvalidType({ + expected: circleSchema->S.toUnknown, + received: %raw(`"Hello world!"`), }), - U.error({ - code: InvalidType({ - expected: squareSchema->S.toUnknown, - received: %raw(`"Hello world!"`), - }), - operation: Parsing, - path: S.Path.empty, + operation: Parsing, + path: S.Path.empty, + }), + U.error({ + code: InvalidType({ + expected: squareSchema->S.toUnknown, + received: %raw(`"Hello world!"`), }), - U.error({ - code: InvalidType({ - expected: triangleSchema->S.toUnknown, - received: %raw(`"Hello world!"`), - }), - operation: Parsing, - path: S.Path.empty, + operation: Parsing, + path: S.Path.empty, + }), + U.error({ + code: InvalidType({ + expected: triangleSchema->S.toUnknown, + received: %raw(`"Hello world!"`), }), - ]), - operation: Parsing, - path: S.Path.empty, - }) + operation: Parsing, + path: S.Path.empty, + }), + ]), + operation: Parsing, + path: S.Path.empty, + }, + ) }) test("Fails to serialize incomplete schema", t => {