diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/gleam/dynamic_test.gleam | 211 |
1 files changed, 131 insertions, 80 deletions
diff --git a/test/gleam/dynamic_test.gleam b/test/gleam/dynamic_test.gleam index 2c8c96e..f6622aa 100644 --- a/test/gleam/dynamic_test.gleam +++ b/test/gleam/dynamic_test.gleam @@ -19,12 +19,16 @@ pub fn bit_string_test() { 1 |> dynamic.from |> dynamic.bit_string - |> should.equal(Error(DecodeError(expected: "BitString", found: "Int"))) + |> should.equal(Error([ + DecodeError(expected: "BitString", found: "Int", path: []), + ])) [] |> dynamic.from |> dynamic.bit_string - |> should.equal(Error(DecodeError(expected: "BitString", found: "List"))) + |> should.equal(Error([ + DecodeError(expected: "BitString", found: "List", path: []), + ])) } if erlang { @@ -50,12 +54,16 @@ pub fn string_test() { 1 |> dynamic.from |> dynamic.string - |> should.equal(Error(DecodeError(expected: "String", found: "Int"))) + |> should.equal(Error([ + DecodeError(expected: "String", found: "Int", path: []), + ])) [] |> dynamic.from |> dynamic.string - |> should.equal(Error(DecodeError(expected: "String", found: "List"))) + |> should.equal(Error([ + DecodeError(expected: "String", found: "List", path: []), + ])) } if erlang { @@ -63,7 +71,9 @@ if erlang { <<65535:16>> |> dynamic.from |> dynamic.string - |> should.equal(Error(DecodeError(expected: "String", found: "BitString"))) + |> should.equal(Error([ + DecodeError(expected: "String", found: "BitString", path: []), + ])) } } @@ -81,7 +91,7 @@ pub fn int_test() { [] |> dynamic.from |> dynamic.int - |> should.equal(Error(DecodeError(expected: "Int", found: "List"))) + |> should.equal(Error([DecodeError(expected: "Int", found: "List", path: [])])) } pub fn float_test() { @@ -98,7 +108,9 @@ pub fn float_test() { [] |> dynamic.from |> dynamic.float - |> should.equal(Error(DecodeError(expected: "Float", found: "List"))) + |> should.equal(Error([ + DecodeError(expected: "Float", found: "List", path: []), + ])) } if erlang { @@ -106,12 +118,16 @@ if erlang { 1 |> dynamic.from |> dynamic.float - |> should.equal(Error(DecodeError(expected: "Float", found: "Int"))) + |> should.equal(Error([ + DecodeError(expected: "Float", found: "Int", path: []), + ])) 1.0 |> dynamic.from |> dynamic.int - |> should.equal(Error(DecodeError(expected: "Int", found: "Float"))) + |> should.equal(Error([ + DecodeError(expected: "Int", found: "Float", path: []), + ])) } } @@ -143,17 +159,19 @@ pub fn bool_test() { 1 |> dynamic.from |> dynamic.bool - |> should.equal(Error(DecodeError(expected: "Bool", found: "Int"))) + |> should.equal(Error([DecodeError(expected: "Bool", found: "Int", path: [])])) 1.5 |> dynamic.from |> dynamic.bool - |> should.equal(Error(DecodeError(expected: "Bool", found: "Float"))) + |> should.equal(Error([ + DecodeError(expected: "Bool", found: "Float", path: []), + ])) [] |> dynamic.from |> dynamic.bool - |> should.equal(Error(DecodeError(expected: "Bool", found: "List"))) + |> should.equal(Error([DecodeError(expected: "Bool", found: "List", path: [])])) } pub fn list_test() { @@ -235,10 +253,9 @@ if javascript { Ok(123) |> dynamic.from |> dynamic.field("Nope", dynamic.int) - |> should.equal(Error(DecodeError( - expected: "Value with field \"Nope\"", - found: "Result", - ))) + |> should.equal(Error([ + DecodeError(expected: "Value with field \"Nope\"", found: "Result"), + ])) } } @@ -265,7 +282,7 @@ pub fn field_test() { map.new() |> map.insert("ok", 3) |> dynamic.from - |> dynamic.field("ok", dynamic.float) + |> dynamic.field("ok", dynamic.string) |> should.be_error map.new() @@ -300,15 +317,20 @@ pub fn element_test() { ok_one_tuple |> dynamic.from |> dynamic.element(1, dynamic.string) - |> should.equal(Error(DecodeError(expected: "String", found: "Int"))) + |> should.equal(Error([ + DecodeError(expected: "String", found: "Int", path: []), + ])) ok_one_tuple |> dynamic.from |> dynamic.element(2, dynamic.int) - |> should.equal(Error(DecodeError( - expected: "Tuple of at least 3 elements", - found: "Tuple of 2 elements", - ))) + |> should.equal(Error([ + DecodeError( + path: [], + expected: "Tuple of at least 3 elements", + found: "Tuple of 2 elements", + ), + ])) ok_one_tuple |> dynamic.from @@ -318,26 +340,29 @@ pub fn element_test() { ok_one_tuple |> dynamic.from |> dynamic.element(-3, dynamic.int) - |> should.equal(Error(DecodeError( - expected: "Tuple of at least 3 elements", - found: "Tuple of 2 elements", - ))) + |> should.equal(Error([ + DecodeError( + path: [], + expected: "Tuple of at least 3 elements", + found: "Tuple of 2 elements", + ), + ])) 1 |> dynamic.from |> dynamic.element(-3, dynamic.int) - |> should.equal(Error(DecodeError(expected: "Tuple", found: "Int"))) + |> should.equal(Error([DecodeError(expected: "Tuple", found: "Int", path: [])])) 1 |> dynamic.from |> dynamic.element(0, dynamic.int) - |> should.equal(Error(DecodeError(expected: "Tuple", found: "Int"))) + |> should.equal(Error([DecodeError(expected: "Tuple", found: "Int", path: [])])) map.new() |> map.insert(1, "ok") |> dynamic.from |> dynamic.element(0, dynamic.int) - |> should.equal(Error(DecodeError(expected: "Tuple", found: "Map"))) + |> should.equal(Error([DecodeError(expected: "Tuple", found: "Map", path: [])])) } pub fn tuple2_test() { @@ -354,23 +379,27 @@ pub fn tuple2_test() { #(1, "") |> dynamic.from |> dynamic.tuple2(dynamic.int, dynamic.int) - |> should.equal(Error(DecodeError(expected: "Int", found: "String"))) + |> should.equal(Error([ + DecodeError(expected: "Int", found: "String", path: []), + ])) #(1, 2, 3) |> dynamic.from |> dynamic.tuple2(dynamic.int, dynamic.int) - |> should.equal(Error(DecodeError( - expected: "Tuple of 2 elements", - found: "Tuple of 3 elements", - ))) + |> should.equal(Error([ + DecodeError( + path: [], + expected: "Tuple of 2 elements", + found: "Tuple of 3 elements", + ), + ])) 1 |> dynamic.from |> dynamic.tuple2(dynamic.int, dynamic.int) - |> should.equal(Error(DecodeError( - expected: "Tuple of 2 elements", - found: "Int", - ))) + |> should.equal(Error([ + DecodeError(path: [], expected: "Tuple of 2 elements", found: "Int"), + ])) } pub fn tuple3_test() { @@ -387,23 +416,27 @@ pub fn tuple3_test() { #(1, 2, "") |> dynamic.from |> dynamic.tuple3(dynamic.int, dynamic.int, dynamic.int) - |> should.equal(Error(DecodeError(expected: "Int", found: "String"))) + |> should.equal(Error([ + DecodeError(expected: "Int", found: "String", path: []), + ])) #(1, 2) |> dynamic.from |> dynamic.tuple3(dynamic.int, dynamic.int, dynamic.int) - |> should.equal(Error(DecodeError( - expected: "Tuple of 3 elements", - found: "Tuple of 2 elements", - ))) + |> should.equal(Error([ + DecodeError( + path: [], + expected: "Tuple of 3 elements", + found: "Tuple of 2 elements", + ), + ])) 1 |> dynamic.from |> dynamic.tuple3(dynamic.int, dynamic.int, dynamic.int) - |> should.equal(Error(DecodeError( - expected: "Tuple of 3 elements", - found: "Int", - ))) + |> should.equal(Error([ + DecodeError(path: [], expected: "Tuple of 3 elements", found: "Int"), + ])) } pub fn tuple4_test() { @@ -420,23 +453,27 @@ pub fn tuple4_test() { #(1, 2, 3, "") |> dynamic.from |> dynamic.tuple4(dynamic.int, dynamic.int, dynamic.int, dynamic.int) - |> should.equal(Error(DecodeError(expected: "Int", found: "String"))) + |> should.equal(Error([ + DecodeError(expected: "Int", found: "String", path: []), + ])) #(1, 2) |> dynamic.from |> dynamic.tuple4(dynamic.int, dynamic.int, dynamic.int, dynamic.int) - |> should.equal(Error(DecodeError( - expected: "Tuple of 4 elements", - found: "Tuple of 2 elements", - ))) + |> should.equal(Error([ + DecodeError( + path: [], + expected: "Tuple of 4 elements", + found: "Tuple of 2 elements", + ), + ])) 1 |> dynamic.from |> dynamic.tuple4(dynamic.int, dynamic.int, dynamic.int, dynamic.int) - |> should.equal(Error(DecodeError( - expected: "Tuple of 4 elements", - found: "Int", - ))) + |> should.equal(Error([ + DecodeError(path: [], expected: "Tuple of 4 elements", found: "Int"), + ])) } pub fn tuple5_test() { @@ -471,7 +508,9 @@ pub fn tuple5_test() { dynamic.int, dynamic.int, ) - |> should.equal(Error(DecodeError(expected: "Int", found: "String"))) + |> should.equal(Error([ + DecodeError(expected: "Int", found: "String", path: []), + ])) #(1, 2) |> dynamic.from @@ -482,10 +521,13 @@ pub fn tuple5_test() { dynamic.int, dynamic.int, ) - |> should.equal(Error(DecodeError( - expected: "Tuple of 5 elements", - found: "Tuple of 2 elements", - ))) + |> should.equal(Error([ + DecodeError( + path: [], + expected: "Tuple of 5 elements", + found: "Tuple of 2 elements", + ), + ])) 1 |> dynamic.from @@ -496,10 +538,9 @@ pub fn tuple5_test() { dynamic.int, dynamic.int, ) - |> should.equal(Error(DecodeError( - expected: "Tuple of 5 elements", - found: "Int", - ))) + |> should.equal(Error([ + DecodeError(path: [], expected: "Tuple of 5 elements", found: "Int"), + ])) } pub fn tuple6_test() { @@ -537,7 +578,9 @@ pub fn tuple6_test() { dynamic.int, dynamic.int, ) - |> should.equal(Error(DecodeError(expected: "Int", found: "String"))) + |> should.equal(Error([ + DecodeError(expected: "Int", found: "String", path: []), + ])) #(1, 2) |> dynamic.from @@ -549,10 +592,13 @@ pub fn tuple6_test() { dynamic.int, dynamic.int, ) - |> should.equal(Error(DecodeError( - expected: "Tuple of 6 elements", - found: "Tuple of 2 elements", - ))) + |> should.equal(Error([ + DecodeError( + path: [], + expected: "Tuple of 6 elements", + found: "Tuple of 2 elements", + ), + ])) 1 |> dynamic.from @@ -564,10 +610,9 @@ pub fn tuple6_test() { dynamic.int, dynamic.int, ) - |> should.equal(Error(DecodeError( - expected: "Tuple of 6 elements", - found: "Int", - ))) + |> should.equal(Error([ + DecodeError(path: [], expected: "Tuple of 6 elements", found: "Int"), + ])) } pub fn map_test() { @@ -579,7 +624,7 @@ pub fn map_test() { 1 |> dynamic.from |> dynamic.map - |> should.equal(Error(DecodeError(expected: "Map", found: "Int"))) + |> should.equal(Error([DecodeError(expected: "Map", found: "Int", path: [])])) } pub fn shallow_list_test() { @@ -601,7 +646,7 @@ pub fn shallow_list_test() { 1 |> dynamic.from |> dynamic.shallow_list - |> should.equal(Error(DecodeError(expected: "List", found: "Int"))) + |> should.equal(Error([DecodeError(expected: "List", found: "Int", path: [])])) } pub fn result_test() { @@ -618,17 +663,23 @@ pub fn result_test() { Ok("1") |> dynamic.from |> dynamic.result(ok: dynamic.int, error: dynamic.string) - |> should.equal(Error(DecodeError(expected: "Int", found: "String"))) + |> should.equal(Error([ + DecodeError(expected: "Int", found: "String", path: []), + ])) Error(1) |> dynamic.from |> dynamic.result(ok: dynamic.int, error: dynamic.string) - |> should.equal(Error(DecodeError(expected: "String", found: "Int"))) + |> should.equal(Error([ + DecodeError(expected: "String", found: "Int", path: []), + ])) 1 |> dynamic.from |> dynamic.result(ok: dynamic.int, error: dynamic.string) - |> should.equal(Error(DecodeError(expected: "Result", found: "Int"))) + |> should.equal(Error([ + DecodeError(expected: "Result", found: "Int", path: []), + ])) } pub fn any_test() { @@ -653,5 +704,5 @@ pub fn any_test() { "" |> dynamic.from |> decoder - |> should.equal(Error(DecodeError("Float or Int", "String"))) + |> should.equal(Error([DecodeError("another type", "String", path: [])])) } |