break special decodeable forms out to own test data
This commit is contained in:
parent
086803cc95
commit
e6380bc3a3
4 changed files with 69 additions and 13 deletions
|
@ -6,6 +6,7 @@
|
|||
-export([literals/0, naked_literals/0]).
|
||||
-export([integers/0, naked_integers/0]).
|
||||
-export([floats/0, naked_floats/0]).
|
||||
-export([decodeables/0]).
|
||||
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
@ -49,7 +50,7 @@ naked_integers() ->
|
|||
[{integer, X}]
|
||||
}
|
||||
|| X <- Raw ++ [ -1 * Y || Y <- Raw ] ++ [0]
|
||||
] ++ [{"-0", <<"-0">>, 0, [{integer, 0}]}].
|
||||
].
|
||||
|
||||
integers() ->
|
||||
[ wrap_with_array(Test) || Test <- naked_integers() ]
|
||||
|
@ -80,13 +81,7 @@ naked_floats() ->
|
|||
[{float, X}]
|
||||
}
|
||||
|| X <- Raw ++ [ -1 * Y || Y <- Raw ]
|
||||
]
|
||||
++ [{"-0.0", <<"-0.0">>, 0.0, [{float, 0.0}]}]
|
||||
++ [{"1e0", <<"1e0">>, 1.0, [{float, 1.0}]}]
|
||||
++ [{"0e0", <<"0e0">>, 0.0, [{float, 0.0}]}]
|
||||
++ [{"1e4", <<"1e4">>, 1.0e4, [{float, 1.0e4}]}]
|
||||
++ [{"0e4", <<"0e4">>, 0.0, [{float, 0.0}]}]
|
||||
++ [{"-1e0", <<"-1e0">>, -1.0, [{float, -1.0}]}].
|
||||
].
|
||||
|
||||
|
||||
floats() ->
|
||||
|
@ -95,6 +90,22 @@ floats() ->
|
|||
++ [listify(naked_floats())]
|
||||
++ [objectify(naked_floats())].
|
||||
|
||||
decodeables() ->
|
||||
Tests = [
|
||||
{"-0.0", <<"-0.0">>, 0.0, [{float, 0.0}]},
|
||||
{"1e0", <<"1e0">>, 1.0, [{float, 1.0}]},
|
||||
{"0e0", <<"0e0">>, 0.0, [{float, 0.0}]},
|
||||
{"1e4", <<"1e4">>, 1.0e4, [{float, 1.0e4}]},
|
||||
{"0e4", <<"0e4">>, 0.0, [{float, 0.0}]},
|
||||
{"-1e0", <<"-1e0">>, -1.0, [{float, -1.0}]},
|
||||
{"-0", <<"-0">>, 0, [{integer, 0}]}
|
||||
],
|
||||
[ wrap_with_array(Test) || Test <- Tests ]
|
||||
++ [ wrap_with_object(Test) || Test <- Tests ]
|
||||
++ [listify(Tests)]
|
||||
++ [objectify(Tests)].
|
||||
|
||||
|
||||
sane_float_to_list(X) ->
|
||||
[Output] = io_lib:format("~p", [X]),
|
||||
Output.
|
||||
|
@ -147,7 +158,7 @@ listify([], {_, JSON, Term, Events}) ->
|
|||
binary_to_list(<<"["/utf8, JSON/binary, "]"/utf8>>),
|
||||
<<"["/utf8, JSON/binary, "]"/utf8>>,
|
||||
Term,
|
||||
[start_array, Events, end_array]
|
||||
[start_array] ++ Events ++ [end_array]
|
||||
};
|
||||
listify([Test|Rest], Acc) ->
|
||||
{_, A, M, X} = Acc,
|
||||
|
|
|
@ -291,4 +291,25 @@ format_test_() ->
|
|||
].
|
||||
|
||||
|
||||
handle_event_test_() ->
|
||||
Data = jsx:empty_array()
|
||||
++ jsx:deep_array()
|
||||
++ jsx:really_deep_array()
|
||||
++ jsx:empty_object()
|
||||
++ jsx:literals()
|
||||
++ jsx:naked_literals()
|
||||
++ jsx:integers()
|
||||
++ jsx:naked_integers()
|
||||
++ jsx:floats()
|
||||
++ jsx:naked_floats(),
|
||||
[
|
||||
{
|
||||
Title, ?_assertEqual(
|
||||
JSON,
|
||||
lists:foldl(fun handle_event/2, {start, [], #opts{}}, Events ++ [end_json])
|
||||
)
|
||||
} || {Title, JSON, _, Events} <- Data
|
||||
].
|
||||
|
||||
|
||||
-endif.
|
|
@ -265,4 +265,27 @@ post_decoders_test_() ->
|
|||
)}
|
||||
].
|
||||
|
||||
|
||||
handle_event_test_() ->
|
||||
Data = jsx:empty_array()
|
||||
++ jsx:deep_array()
|
||||
++ jsx:really_deep_array()
|
||||
++ jsx:empty_object()
|
||||
++ jsx:literals()
|
||||
++ jsx:naked_literals()
|
||||
++ jsx:integers()
|
||||
++ jsx:naked_integers()
|
||||
++ jsx:floats()
|
||||
++ jsx:naked_floats()
|
||||
++ jsx:decodeables(),
|
||||
[
|
||||
{
|
||||
Title, ?_assertEqual(
|
||||
Term,
|
||||
lists:foldl(fun handle_event/2, {[[]], #opts{}}, Events ++ [end_json])
|
||||
)
|
||||
} || {Title, _, Term, Events} <- Data
|
||||
].
|
||||
|
||||
|
||||
-endif.
|
||||
|
|
|
@ -124,7 +124,8 @@ handle_event_test_() ->
|
|||
++ jsx:integers()
|
||||
++ jsx:naked_integers()
|
||||
++ jsx:floats()
|
||||
++ jsx:naked_floats(),
|
||||
++ jsx:naked_floats()
|
||||
++ jsx:decodeables(),
|
||||
[
|
||||
{
|
||||
Title, ?_assertEqual(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue