tests working, finally
This commit is contained in:
parent
843b3cdf24
commit
55f1f18366
2 changed files with 17 additions and 11 deletions
|
@ -1,4 +1,6 @@
|
|||
{eunit_compile_opts, [{d, test}]}.
|
||||
%% edit eunit_test_path if you want to run your own tests, use "../" not "./" as
|
||||
%% rebar changes to working dir to .eunit when running tests
|
||||
{eunit_compile_opts, [{d, test}, {d, eunit_test_path, "../test/cases"}]}.
|
||||
|
||||
%% uncomment to get verbose output from test suite
|
||||
{eunit_opts, [verbose]}.
|
||||
|
|
|
@ -42,24 +42,28 @@ test() -> erlang:error(notest).
|
|||
-else.
|
||||
|
||||
jsx_decoder_test_() ->
|
||||
jsx_decoder_gen(load_tests("./test/cases"), [utf8, utf16, {utf16, little}, utf32, {utf32, little}], fun decode/2).
|
||||
|
||||
jsx_incremental_test_() ->
|
||||
jsx_decoder_gen(load_tests("./test/cases"), [utf8, utf16, {utf16, little}, utf32, {utf32, little}], fun incremental_decode/2).
|
||||
jsx_decoder_gen(load_tests(?eunit_test_path)).
|
||||
|
||||
|
||||
jsx_decoder_gen([_Test|Rest], [], F) ->
|
||||
jsx_decoder_gen(Rest, [utf8, utf16, {utf16, little}, utf32, {utf32, little}], F);
|
||||
jsx_decoder_gen([], _, _) ->
|
||||
[];
|
||||
jsx_decoder_gen([Test|_] = Tests, [Encoding|Encodings], F) ->
|
||||
jsx_decoder_gen([]) -> [];
|
||||
jsx_decoder_gen(Tests) -> jsx_decoder_gen(Tests, [utf8, utf16, {utf16, little}, utf32, {utf32, little}]).
|
||||
|
||||
jsx_decoder_gen([_Test|Rest], []) ->
|
||||
jsx_decoder_gen(Rest);
|
||||
jsx_decoder_gen([Test|_] = Tests, [Encoding|Encodings]) ->
|
||||
Name = lists:flatten(proplists:get_value(name, Test) ++ " :: " ++ io_lib:format("~p", [Encoding])),
|
||||
JSON = unicode:characters_to_binary(proplists:get_value(json, Test), unicode, Encoding),
|
||||
JSX = proplists:get_value(jsx, Test),
|
||||
Flags = proplists:get_value(jsx_flags, Test, []),
|
||||
{generator,
|
||||
fun() ->
|
||||
[{Name, ?_assert(F(JSON, Flags) =:= JSX)} | jsx_decoder_gen(Tests, Encodings, F)]
|
||||
[{Name, ?_assert(decode(JSON, Flags) =:= JSX)}
|
||||
| {generator,
|
||||
fun() -> [{Name ++ " incremental", ?_assert(incremental_decode(JSON, Flags) =:= JSX)}
|
||||
| jsx_decoder_gen(Tests, Encodings)]
|
||||
end
|
||||
}
|
||||
]
|
||||
end
|
||||
}.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue