whitespace
This commit is contained in:
parent
6544975379
commit
9d2448669e
2 changed files with 37 additions and 5 deletions
|
@ -1426,6 +1426,7 @@ comments_test_() ->
|
|||
)}
|
||||
].
|
||||
|
||||
|
||||
escape_forward_slash_test_() ->
|
||||
[
|
||||
{"escape forward slash test", ?_assertEqual(
|
||||
|
@ -1434,6 +1435,7 @@ escape_forward_slash_test_() ->
|
|||
)}
|
||||
].
|
||||
|
||||
|
||||
noncharacters_test_() ->
|
||||
[
|
||||
{"noncharacters - badjson",
|
||||
|
@ -1444,6 +1446,7 @@ noncharacters_test_() ->
|
|||
}
|
||||
].
|
||||
|
||||
|
||||
extended_noncharacters_test_() ->
|
||||
[
|
||||
{"extended noncharacters - badjson",
|
||||
|
@ -1454,6 +1457,7 @@ extended_noncharacters_test_() ->
|
|||
}
|
||||
].
|
||||
|
||||
|
||||
surrogates_test_() ->
|
||||
[
|
||||
{"surrogates - badjson",
|
||||
|
@ -1464,6 +1468,7 @@ surrogates_test_() ->
|
|||
}
|
||||
].
|
||||
|
||||
|
||||
control_test_() ->
|
||||
[
|
||||
{"control characters - badjson",
|
||||
|
@ -1471,6 +1476,7 @@ control_test_() ->
|
|||
}
|
||||
].
|
||||
|
||||
|
||||
reserved_test_() ->
|
||||
[
|
||||
{"reserved noncharacters - badjson",
|
||||
|
@ -1480,6 +1486,7 @@ reserved_test_() ->
|
|||
?_assertEqual(check_replaced(reserved_space()), [])
|
||||
}
|
||||
].
|
||||
|
||||
|
||||
good_characters_test_() ->
|
||||
[
|
||||
|
@ -1497,6 +1504,7 @@ check_bad(List) ->
|
|||
check(List, [], [])
|
||||
).
|
||||
|
||||
|
||||
check_replaced(List) ->
|
||||
lists:dropwhile(fun({_, [{string, <<16#fffd/utf8>>}|_]}) -> true
|
||||
; (_) -> false
|
||||
|
@ -1504,11 +1512,13 @@ check_replaced(List) ->
|
|||
check(List, [loose_unicode], [])
|
||||
).
|
||||
|
||||
|
||||
check_good(List) ->
|
||||
lists:dropwhile(fun({_, [{string, _}|_]}) -> true ; (_) -> false end,
|
||||
check(List, [], [])
|
||||
).
|
||||
|
||||
|
||||
check([], _Opts, Acc) -> Acc;
|
||||
check([H|T], Opts, Acc) ->
|
||||
R = decode(to_fake_utf(H, utf8), Opts),
|
||||
|
@ -1524,7 +1534,8 @@ decode(JSON, Opts) ->
|
|||
|
||||
|
||||
noncharacters() -> lists:seq(16#fffe, 16#ffff).
|
||||
|
||||
|
||||
|
||||
extended_noncharacters() ->
|
||||
[16#1fffe, 16#1ffff, 16#2fffe, 16#2ffff]
|
||||
++ [16#3fffe, 16#3ffff, 16#4fffe, 16#4ffff]
|
||||
|
@ -1535,20 +1546,26 @@ extended_noncharacters() ->
|
|||
++ [16#dfffe, 16#dffff, 16#efffe, 16#effff]
|
||||
++ [16#ffffe, 16#fffff, 16#10fffe, 16#10ffff].
|
||||
|
||||
|
||||
surrogates() -> lists:seq(16#d800, 16#dfff).
|
||||
|
||||
|
||||
control_characters() -> lists:seq(1, 31).
|
||||
|
||||
|
||||
reserved_space() -> lists:seq(16#fdd0, 16#fdef).
|
||||
|
||||
|
||||
good() -> [32, 33]
|
||||
++ lists:seq(16#23, 16#5b)
|
||||
++ lists:seq(16#5d, 16#d7ff)
|
||||
++ lists:seq(16#e000, 16#fdcf)
|
||||
++ lists:seq(16#fdf0, 16#fffd).
|
||||
|
||||
|
||||
|
||||
good_extended() -> lists:seq(16#100000, 16#10fffd).
|
||||
|
||||
|
||||
%% erlang refuses to encode certain codepoints, so fake them all
|
||||
to_fake_utf(N, utf8) when N < 16#0080 -> <<34/utf8, N:8, 34/utf8>>;
|
||||
to_fake_utf(N, utf8) when N < 16#0800 ->
|
||||
|
|
|
@ -455,6 +455,7 @@ encode_test_() ->
|
|||
}
|
||||
].
|
||||
|
||||
|
||||
surrogates_test_() ->
|
||||
[
|
||||
{"surrogates - badjson",
|
||||
|
@ -464,7 +465,8 @@ surrogates_test_() ->
|
|||
?_assertEqual(check_replaced(surrogates()), [])
|
||||
}
|
||||
].
|
||||
|
||||
|
||||
|
||||
good_characters_test_() ->
|
||||
[
|
||||
{"acceptable codepoints",
|
||||
|
@ -475,6 +477,7 @@ good_characters_test_() ->
|
|||
}
|
||||
].
|
||||
|
||||
|
||||
reserved_test_() ->
|
||||
[
|
||||
{"reserved noncharacters - badjson",
|
||||
|
@ -485,6 +488,7 @@ reserved_test_() ->
|
|||
}
|
||||
].
|
||||
|
||||
|
||||
noncharacters_test_() ->
|
||||
[
|
||||
{"noncharacters - badjson",
|
||||
|
@ -495,6 +499,7 @@ noncharacters_test_() ->
|
|||
}
|
||||
].
|
||||
|
||||
|
||||
extended_noncharacters_test_() ->
|
||||
[
|
||||
{"extended noncharacters - badjson",
|
||||
|
@ -511,6 +516,7 @@ check_bad(List) ->
|
|||
check(List, [], [])
|
||||
).
|
||||
|
||||
|
||||
check_replaced(List) ->
|
||||
lists:dropwhile(fun({_, [{string, <<16#fffd/utf8>>}|_]}) -> true
|
||||
; (_) -> false
|
||||
|
@ -518,11 +524,13 @@ check_replaced(List) ->
|
|||
check(List, [loose_unicode], [])
|
||||
).
|
||||
|
||||
|
||||
check_good(List) ->
|
||||
lists:dropwhile(fun({_, [{string, _}|_]}) -> true ; (_) -> false end,
|
||||
check(List, [], [])
|
||||
).
|
||||
|
||||
|
||||
check([], _Opts, Acc) -> Acc;
|
||||
check([H|T], Opts, Acc) ->
|
||||
R = encode(to_fake_utf(H, utf8), Opts),
|
||||
|
@ -530,7 +538,8 @@ check([H|T], Opts, Acc) ->
|
|||
|
||||
|
||||
noncharacters() -> lists:seq(16#fffe, 16#ffff).
|
||||
|
||||
|
||||
|
||||
extended_noncharacters() ->
|
||||
[16#1fffe, 16#1ffff, 16#2fffe, 16#2ffff]
|
||||
++ [16#3fffe, 16#3ffff, 16#4fffe, 16#4ffff]
|
||||
|
@ -541,14 +550,19 @@ extended_noncharacters() ->
|
|||
++ [16#dfffe, 16#dffff, 16#efffe, 16#effff]
|
||||
++ [16#ffffe, 16#fffff, 16#10fffe, 16#10ffff].
|
||||
|
||||
|
||||
surrogates() -> lists:seq(16#d800, 16#dfff).
|
||||
|
||||
|
||||
reserved_space() -> lists:seq(16#fdd0, 16#fdef).
|
||||
|
||||
|
||||
good() -> lists:seq(16#0000, 16#d7ff) ++ lists:seq(16#e000, 16#fdcf) ++ lists:seq(16#fdf0, 16#fffd).
|
||||
|
||||
|
||||
|
||||
good_extended() -> lists:seq(16#100000, 16#10fffd).
|
||||
|
||||
|
||||
%% erlang refuses to encode certain codepoints, so fake them all
|
||||
to_fake_utf(N, utf8) when N < 16#0080 -> <<N:8>>;
|
||||
to_fake_utf(N, utf8) when N < 16#0800 ->
|
||||
|
@ -561,4 +575,5 @@ to_fake_utf(N, utf8) ->
|
|||
<<0:3, W:3, Z:6, Y:6, X:6>> = <<N:24>>,
|
||||
<<2#11110:5, W:3, 2#10:2, Z:6, 2#10:2, Y:6, 2#10:2, X:6>>.
|
||||
|
||||
|
||||
-endif.
|
Loading…
Add table
Add a link
Reference in a new issue