diff options
author | mrkutly <mark.sauer.utley@gmail.com> | 2022-06-09 20:32:10 -0400 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2022-06-11 18:39:10 +0100 |
commit | 88858b8d3cc9dd1f6bdfbbd346a23a85fdddf439 (patch) | |
tree | e9956a6163aef6837f11e561b24179a0973ad850 | |
parent | 6ef6802c983dca7f9d72f0b2e4906d8f11a3c6a2 (diff) | |
download | gleam_json-88858b8d3cc9dd1f6bdfbbd346a23a85fdddf439.tar.gz gleam_json-88858b8d3cc9dd1f6bdfbbd346a23a85fdddf439.zip |
expect decode errors based on runtime
-rw-r--r-- | test/gleam_json_test.gleam | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/test/gleam_json_test.gleam b/test/gleam_json_test.gleam index 6460e51..95af8c0 100644 --- a/test/gleam_json_test.gleam +++ b/test/gleam_json_test.gleam @@ -27,9 +27,7 @@ pub fn decode_unexpected_byte_test() { pub fn decode_unexpected_format_test() { json.decode(from: "[]", using: dynamic.int) - |> should.equal(Error(json.UnexpectedFormat([ - dynamic.DecodeError(expected: "Int", found: "List", path: []), - ]))) + |> should.equal(Error(json.UnexpectedFormat([empty_list_decode_error()]))) } pub fn decode_bits_test() { @@ -49,9 +47,7 @@ pub fn decode_bits_unexpected_byte_test() { pub fn decode_bits_unexpected_format_test() { json.decode_bits(from: <<"[]":utf8>>, using: dynamic.int) - |> should.equal(Error(json.UnexpectedFormat([ - dynamic.DecodeError(expected: "Int", found: "List", path: []), - ]))) + |> should.equal(Error(json.UnexpectedFormat([empty_list_decode_error()]))) } pub fn encode_string_test() { @@ -126,3 +122,15 @@ fn should_encode(data: Json, expected: String) { |> string_builder.to_string |> should.equal(json.to_string(data)) } + +if erlang { + fn empty_list_decode_error() -> dynamic.DecodeError { + dynamic.DecodeError(expected: "Int", found: "List", path: []) + } +} + +if javascript { + fn empty_list_decode_error() { + dynamic.DecodeError(expected: "Int", found: "Tuple of 0 elements", path: []) + } +} |