diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/gleam_json_js_ffi_test.gleam | 10 | ||||
-rw-r--r-- | test/gleam_json_test.gleam | 21 |
2 files changed, 18 insertions, 13 deletions
diff --git a/test/gleam_json_js_ffi_test.gleam b/test/gleam_json_js_ffi_test.gleam index cecfe20..b1ddb3b 100644 --- a/test/gleam_json_js_ffi_test.gleam +++ b/test/gleam_json_js_ffi_test.gleam @@ -39,7 +39,7 @@ pub fn chromium_unexpected_byte_test() { "Unexpected token a in JSON at position 5" |> StandardError |> get_json_decode_error("{\"b\":a}") - |> should.equal(UnexpectedByte(byte: "0x61", position: 5)) + |> should.equal(UnexpectedByte("0x61")) } @target(javascript) @@ -47,7 +47,7 @@ pub fn spidermonkey_unexpected_byte_test() { "JSON.parse: expected property name or '}' at line 1 column 6 of the JSON data" |> StandardError |> get_json_decode_error("{\"b\":a}") - |> should.equal(UnexpectedByte(byte: "0x61", position: 5)) + |> should.equal(UnexpectedByte("0x61")) } @target(javascript) @@ -55,7 +55,7 @@ pub fn javascript_core_unexpected_byte_test() { "JSON Parse error: Unexpected identifier \"a\"" |> StandardError |> get_json_decode_error("{\"b\":a}") - |> should.equal(UnexpectedByte(byte: "0x61", position: 0)) + |> should.equal(UnexpectedByte("0x61")) } @target(javascript) @@ -63,12 +63,12 @@ pub fn spidermonkey_multiline_unexpected_byte_test() { "JSON.parse: expected property name or '}' at line 2 column 6 of the JSON data" |> StandardError |> get_json_decode_error("{\n\"b\": a\n}") - |> should.equal(UnexpectedByte(byte: "0x61", position: 7)) + |> should.equal(UnexpectedByte("0x61")) "JSON.parse: expected double-quoted property name at line 3 column 1 of the JSON data" |> StandardError |> get_json_decode_error("{\n\"b\": \"x\",\na\n}") - |> should.equal(UnexpectedByte(byte: "0x61", position: 12)) + |> should.equal(UnexpectedByte("0x61")) } @target(javascript) diff --git a/test/gleam_json_test.gleam b/test/gleam_json_test.gleam index 3e22f00..fcc4a62 100644 --- a/test/gleam_json_test.gleam +++ b/test/gleam_json_test.gleam @@ -1,6 +1,7 @@ import gleam/dynamic import gleam/json.{type Json} import gleam/option.{None, Some} +import gleam/string import gleam/string_builder import gleeunit import gleeunit/should @@ -21,11 +22,8 @@ pub fn decode_empty_test() { pub fn decode_unexpected_byte_test() { let assert Error(error) = json.decode(from: "[}", using: dynamic.int) - let assert json.UnexpectedByte(byte, index) = error + let assert json.UnexpectedByte(byte) = error let assert "0x7D" = byte - - // V8 does not report the position of the unexpected byte any more. - let assert True = index == 1 || index == -1 } pub fn decode_unexpected_format_test() { @@ -45,11 +43,8 @@ pub fn decode_bits_empty_test() { pub fn decode_bits_unexpected_byte_test() { let assert Error(error) = json.decode(from: "[}", using: dynamic.int) - let assert json.UnexpectedByte(byte, index) = error + let assert json.UnexpectedByte(byte) = error let assert "0x7D" = byte - - // V8 does not report the position of the unexpected byte any more. - let assert True = index == 1 || index == -1 } pub fn decode_bits_unexpected_format_test() { @@ -57,6 +52,16 @@ pub fn decode_bits_unexpected_format_test() { |> should.equal(Error(json.UnexpectedFormat([empty_list_decode_error()]))) } +pub fn decode_unexpected_sequence_test() { + let assert Error(error) = + json.decode(from: "\"\\uxxxx\"", using: dynamic.float) + case error { + json.UnexpectedSequence("\\uxxxx") -> Nil + json.UnexpectedByte("0x78") -> Nil + _ -> panic as { "unexpected error: " <> string.inspect(error) } + } +} + pub fn encode_string_test() { json.string("hello") |> should_encode("\"hello\"") |