1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
-module(json2_SUITE).
-include("testsuite.hrl").
-compile(export_all).
all() ->
[
json2_decode_valid,
json2_decode_invalid,
json2_decode_invalid_utf8
].
groups() ->
[
].
%%====================================================================
init_per_suite(Config) ->
Config.
end_per_suite(_Config) ->
ok.
init_per_group(_Group, Config) ->
Config.
end_per_group(_Group, _Config) ->
ok.
init_per_testcase(_Test, Config) ->
Config.
end_per_testcase(_Test, _Config) ->
ok.
%%====================================================================
json2_decode_valid(_Config) ->
Dir = filename:join(?srcdir, "json2_SUITE_data/valid"),
Tests = filelib:wildcard(filename:join(Dir, "*.json")),
[begin
{ok, Bin} = file:read_file(T),
Str = unicode:characters_to_list(Bin),
?assertMatch({T, {ok, _}}, {T, json2:decode_string(Str)})
end || T <- Tests],
ok.
json2_decode_invalid(_Config) ->
Dir = filename:join(?srcdir, "json2_SUITE_data/invalid"),
Tests = filelib:wildcard(filename:join(Dir, "*.json")),
[begin
{ok, Bin} = file:read_file(T),
Str = unicode:characters_to_list(Bin),
?assertMatch({T, {error, _}}, {T, json2:decode_string(Str)})
end || T <- Tests],
ok.
json2_decode_invalid_utf8(_Config) ->
Str1 = [$", 16#d848, $"], %% high surrogate only
Str2 = [$", 16#dc49, $"], %% low surrogate only
?assertMatch({Str1, {error, _}}, {Str1, json2:decode_string(Str1)}),
?assertMatch({Str2, {error, _}}, {Str2, json2:decode_string(Str2)}),
ok.
|