Skip to content

Commit 9d5da0e

Browse files
committed
Fix tests
1 parent 25fd65e commit 9d5da0e

File tree

2 files changed

+30
-29
lines changed

2 files changed

+30
-29
lines changed

lib/jason.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ defmodule Jason do
6868
%{}
6969
7070
iex> Jason.decode!("invalid")
71-
** (Jason.DecodeError) unexpected byte at position 0: 0x69 ('i')
71+
** (Jason.DecodeError) unexpected byte at position 0: 0x69 ("i")
7272
7373
"""
7474
@spec decode!(iodata, [decode_opt]) :: term | no_return

test/decode_test.exs

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ defmodule Jason.DecodeTest do
44
alias Jason.DecodeError
55

66
test "numbers" do
7-
assert_fail_with "-", "unexpected end of input at position 1"
8-
assert_fail_with "--1", "unexpected byte at position 1: 0x2D ('-')"
9-
assert_fail_with "01", "unexpected byte at position 1: 0x31 ('1')"
10-
assert_fail_with ".1", "unexpected byte at position 0: 0x2E ('.')"
11-
assert_fail_with "1.", "unexpected end of input at position 2"
12-
assert_fail_with "1e", "unexpected end of input at position 2"
13-
assert_fail_with "1.0e+", "unexpected end of input at position 5"
14-
assert_fail_with "1e999", "unexpected sequence at position 0: \"1e999\""
7+
assert_fail_with "-", ~S|unexpected end of input at position 1|
8+
assert_fail_with "--1", ~S|unexpected byte at position 1: 0x2D ("-")|
9+
assert_fail_with "01", ~S|unexpected byte at position 1: 0x31 ("1")|
10+
assert_fail_with ".1", ~S|unexpected byte at position 0: 0x2E (".")|
11+
assert_fail_with "1.", ~S|unexpected end of input at position 2|
12+
assert_fail_with "1e", ~S|unexpected end of input at position 2|
13+
assert_fail_with "1.0e+", ~S|unexpected end of input at position 5|
14+
assert_fail_with "1e999", ~S|unexpected sequence at position 0: "1e999"|
1515

1616
assert parse!("0") == 0
1717
assert parse!("1") == 1
@@ -33,17 +33,18 @@ defmodule Jason.DecodeTest do
3333
assert parse!("123456789.123456789e123") == 123456789.123456789e123
3434
end
3535
test "strings" do
36-
assert_fail_with ~s("), "unexpected end of input at position 1"
37-
assert_fail_with ~s("\\"), "unexpected end of input at position 3"
38-
assert_fail_with ~s("\\k"), "unexpected byte at position 2: 0x6B ('k')"
39-
assert_fail_with <<?\", 128, ?\">>, "unexpected byte at position 1: 0x80"
40-
assert_fail_with ~s("\\u2603\\"), "unexpected end of input at position 9"
41-
assert_fail_with ~s("Here's a snowman for you: ☃. Good day!), "unexpected end of input at position 41"
42-
assert_fail_with ~s("𝄞), "unexpected end of input at position 5"
43-
assert_fail_with ~s(\u001F), "unexpected byte at position 0: 0x1F"
44-
assert_fail_with ~s("\\ud8aa\\udcxx"), "unexpected sequence at position 7: \"\\\\udcxx\""
45-
assert_fail_with ~s("\\ud8aa\\uda00"), "unexpected sequence at position 1: \"\\\\ud8aa\\\\uda00\""
46-
assert_fail_with ~s("\\uxxxx"), "unexpected sequence at position 1: \"\\\\uxxxx\""
36+
assert_fail_with ~s("), ~S|unexpected end of input at position 1|
37+
assert_fail_with ~s("\\"), ~S|unexpected end of input at position 3|
38+
assert_fail_with ~s("\\k"), ~S|unexpected byte at position 2: 0x6B ("k")|
39+
assert_fail_with ~s("a\r"), ~S|unexpected byte at position 2: 0xD ("\r")|
40+
assert_fail_with <<?\", 128, ?\">>, ~S|unexpected byte at position 1: 0x80|
41+
assert_fail_with ~s("\\u2603\\"), ~S|unexpected end of input at position 9|
42+
assert_fail_with ~s("Here's a snowman for you: ☃. Good day!), ~S|unexpected end of input at position 41|
43+
assert_fail_with ~s("𝄞), ~S|unexpected end of input at position 5|
44+
assert_fail_with ~s(\u001F), ~S|unexpected byte at position 0: 0x1F|
45+
assert_fail_with ~s("\\ud8aa\\udcxx"), ~S|unexpected sequence at position 7: "\\udcxx"|
46+
assert_fail_with ~s("\\ud8aa\\uda00"), ~S|unexpected sequence at position 1: "\\ud8aa\\uda00"|
47+
assert_fail_with ~s("\\uxxxx"), ~S|unexpected sequence at position 1: "\\uxxxx"|
4748

4849
assert parse!(~s("\\"\\\\\\/\\b\\f\\n\\r\\t")) == ~s("\\/\b\f\n\r\t)
4950
assert parse!(~s("\\u2603")) == "☃"
@@ -55,10 +56,10 @@ defmodule Jason.DecodeTest do
5556
end
5657

5758
test "objects" do
58-
assert_fail_with "{", "unexpected end of input at position 1"
59-
assert_fail_with "{,", "unexpected byte at position 1: 0x2C (',')"
60-
assert_fail_with ~s({"foo"}), "unexpected byte at position 6: 0x7D ('}')"
61-
assert_fail_with ~s({"foo": "bar",}), "unexpected byte at position 14: 0x7D ('}')"
59+
assert_fail_with "{", ~S|unexpected end of input at position 1|
60+
assert_fail_with "{,", ~S|unexpected byte at position 1: 0x2C (",")|
61+
assert_fail_with ~s({"foo"}), ~S|unexpected byte at position 6: 0x7D ("}")|
62+
assert_fail_with ~s({"foo": "bar",}), ~S|unexpected byte at position 14: 0x7D ("}")|
6263

6364
assert parse!("{}") == %{}
6465
assert parse!(~s({"foo": "bar"})) == %{"foo" => "bar"}
@@ -111,9 +112,9 @@ defmodule Jason.DecodeTest do
111112
end
112113

113114
test "arrays" do
114-
assert_fail_with "[", "unexpected end of input at position 1"
115-
assert_fail_with "[,", "unexpected byte at position 1: 0x2C (',')"
116-
assert_fail_with "[1,]", "unexpected byte at position 3: 0x5D (']')"
115+
assert_fail_with "[", ~S|unexpected end of input at position 1|
116+
assert_fail_with "[,", ~S|unexpected byte at position 1: 0x2C (",")|
117+
assert_fail_with "[1,]", ~S|unexpected byte at position 3: 0x5D ("]")|
117118

118119
assert parse!("[]") == []
119120
assert parse!("[1, 2, 3]") == [1, 2, 3]
@@ -122,8 +123,8 @@ defmodule Jason.DecodeTest do
122123
end
123124

124125
test "whitespace" do
125-
assert_fail_with "", "unexpected end of input at position 0"
126-
assert_fail_with " ", "unexpected end of input at position 4"
126+
assert_fail_with "", ~S|unexpected end of input at position 0|
127+
assert_fail_with " ", ~S|unexpected end of input at position 4|
127128

128129
assert parse!(" [ ] ") == []
129130
assert parse!(" { } ") == %{}

0 commit comments

Comments
 (0)