|
@ -1,8 +1,11 @@ |
|
|
-module(util). |
|
|
-module(util). |
|
|
-export([test_good/1, test_errors/1]). |
|
|
|
|
|
|
|
|
-export([test_good/1, test_good/2, test_errors/1]). |
|
|
|
|
|
|
|
|
test_good(Cases) -> |
|
|
test_good(Cases) -> |
|
|
lists:foreach(fun(Case) -> check_good(Case) end, Cases). |
|
|
|
|
|
|
|
|
test_good(Cases, []). |
|
|
|
|
|
|
|
|
|
|
|
test_good(Cases, Options) -> |
|
|
|
|
|
lists:foreach(fun(Case) -> check_good(Case, Options) end, Cases). |
|
|
|
|
|
|
|
|
test_errors(Cases) -> |
|
|
test_errors(Cases) -> |
|
|
lists:foreach(fun(Case) -> check_error(Case) end, Cases). |
|
|
lists:foreach(fun(Case) -> check_error(Case) end, Cases). |
|
@ -13,18 +16,18 @@ ok_dec(J, _E) -> |
|
|
ok_enc(E, _J) -> |
|
|
ok_enc(E, _J) -> |
|
|
lists:flatten(io_lib:format("Encoded ~p", [E])). |
|
|
lists:flatten(io_lib:format("Encoded ~p", [E])). |
|
|
|
|
|
|
|
|
do_encode(E) -> |
|
|
|
|
|
iolist_to_binary(jiffy:encode(E)). |
|
|
|
|
|
|
|
|
do_encode(E, Options) -> |
|
|
|
|
|
iolist_to_binary(jiffy:encode(E, Options)). |
|
|
|
|
|
|
|
|
error_mesg(J) -> |
|
|
error_mesg(J) -> |
|
|
lists:flatten(io_lib:format("Decoding ~p returns an error.", [J])). |
|
|
lists:flatten(io_lib:format("Decoding ~p returns an error.", [J])). |
|
|
|
|
|
|
|
|
check_good({J, E}) -> |
|
|
|
|
|
|
|
|
check_good({J, E}, Options) -> |
|
|
etap:is(jiffy:decode(J), E, ok_dec(J, E)), |
|
|
etap:is(jiffy:decode(J), E, ok_dec(J, E)), |
|
|
etap:is(do_encode(E), J, ok_enc(E, J)); |
|
|
|
|
|
check_good({J, E, J2}) -> |
|
|
|
|
|
|
|
|
etap:is(do_encode(E, Options), J, ok_enc(E, J)); |
|
|
|
|
|
check_good({J, E, J2}, Options) -> |
|
|
etap:is(jiffy:decode(J), E, ok_dec(J, E)), |
|
|
etap:is(jiffy:decode(J), E, ok_dec(J, E)), |
|
|
etap:is(do_encode(E), J2, ok_enc(E, J2)). |
|
|
|
|
|
|
|
|
etap:is(do_encode(E, Options), J2, ok_enc(E, J2)). |
|
|
|
|
|
|
|
|
check_error({J, E}) -> |
|
|
check_error({J, E}) -> |
|
|
etap:fun_is( |
|
|
etap:fun_is( |
|
|