pad out test tests
This commit is contained in:
parent
ba42f75780
commit
6ca54ae3d7
2 changed files with 77 additions and 3 deletions
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
-export([init/1, handle_event/2]).
|
-export([init/1, handle_event/2]).
|
||||||
-export([empty_array/0, empty_object/0]).
|
-export([empty_array/0, empty_object/0]).
|
||||||
|
-export([literals/0, naked_literals/0]).
|
||||||
|
-export([integers/0, naked_integers/0]).
|
||||||
|
|
||||||
|
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
|
||||||
|
@ -14,4 +17,67 @@ handle_event(Event, State) -> [Event] ++ State.
|
||||||
|
|
||||||
|
|
||||||
empty_array() -> [{"empty array", <<"[]">>, [], [start_array, end_array, end_json]}].
|
empty_array() -> [{"empty array", <<"[]">>, [], [start_array, end_array, end_json]}].
|
||||||
empty_object() -> [{"empty object", <<"{}">>, [{}], [start_object, end_object, end_json]}].
|
empty_object() -> [{"empty object", <<"{}">>, [{}], [start_object, end_object, end_json]}].
|
||||||
|
|
||||||
|
|
||||||
|
naked_integers() ->
|
||||||
|
Raw = [
|
||||||
|
1, 2, 3,
|
||||||
|
127, 128, 129,
|
||||||
|
255, 256, 257,
|
||||||
|
65534, 65535, 65536,
|
||||||
|
18446744073709551616,
|
||||||
|
18446744073709551617
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
integer_to_list(X),
|
||||||
|
list_to_binary(integer_to_list(X)),
|
||||||
|
X,
|
||||||
|
[{integer, X}, end_json]
|
||||||
|
}
|
||||||
|
|| X <- Raw ++ [ -1 * Y || Y <- Raw ] ++ [0]
|
||||||
|
] ++ [{"-0", <<"-0">>, 0, [{integer, 0}, end_json]}].
|
||||||
|
|
||||||
|
integers() ->
|
||||||
|
[ wrap_with_array(Test) || Test <- naked_integers() ]
|
||||||
|
++ [ wrap_with_object(Test) || Test <- naked_integers() ].
|
||||||
|
|
||||||
|
|
||||||
|
naked_literals() ->
|
||||||
|
[
|
||||||
|
{
|
||||||
|
atom_to_list(Literal),
|
||||||
|
atom_to_binary(Literal, unicode),
|
||||||
|
Literal,
|
||||||
|
[{literal, Literal}, end_json]
|
||||||
|
}
|
||||||
|
|| Literal <- [true, false, null]
|
||||||
|
].
|
||||||
|
|
||||||
|
literals() ->
|
||||||
|
[ wrap_with_array(Test) || Test <- naked_literals() ]
|
||||||
|
++ [ wrap_with_object(Test) || Test <- naked_literals() ].
|
||||||
|
|
||||||
|
|
||||||
|
wrap_with_array({Title, JSON, Term, Events}) ->
|
||||||
|
{
|
||||||
|
"[" ++ Title ++ "]",
|
||||||
|
<<"[", JSON/binary, "]">>,
|
||||||
|
[Term],
|
||||||
|
[start_array, strip_end(Events), end_array, end_json]
|
||||||
|
}.
|
||||||
|
|
||||||
|
|
||||||
|
wrap_with_object({Title, JSON, Term, Events}) ->
|
||||||
|
{
|
||||||
|
"{\"key\":" ++ Title ++ "}",
|
||||||
|
<<"{\"key\":", JSON/binary, "}">>,
|
||||||
|
[{<<"key">>, Term}],
|
||||||
|
[start_object, {key, <<"key">>}, strip_end(Events), end_object, end_json]
|
||||||
|
}.
|
||||||
|
|
||||||
|
|
||||||
|
strip_end(Events) ->
|
||||||
|
[end_json|Rest] = lists:reverse(Events),
|
||||||
|
lists:reverse(Rest).
|
|
@ -116,13 +116,21 @@ opts_test_() ->
|
||||||
|
|
||||||
valid_json_test_() ->
|
valid_json_test_() ->
|
||||||
Data = jsx:empty_array()
|
Data = jsx:empty_array()
|
||||||
++ jsx:empty_object(),
|
++ jsx:empty_object()
|
||||||
|
++ jsx:literals()
|
||||||
|
++ jsx:naked_literals()
|
||||||
|
++ jsx:integers()
|
||||||
|
++ jsx:naked_integers(),
|
||||||
[ {Title, ?_assertEqual(true, is_json(JSON, []))} || {Title, JSON, _, _} <- Data ].
|
[ {Title, ?_assertEqual(true, is_json(JSON, []))} || {Title, JSON, _, _} <- Data ].
|
||||||
|
|
||||||
|
|
||||||
valid_term_test_() ->
|
valid_term_test_() ->
|
||||||
Data = jsx:empty_array()
|
Data = jsx:empty_array()
|
||||||
++ jsx:empty_object(),
|
++ jsx:empty_object()
|
||||||
|
++ jsx:literals()
|
||||||
|
++ jsx:naked_literals()
|
||||||
|
++ jsx:integers()
|
||||||
|
++ jsx:naked_integers(),
|
||||||
[ {Title, ?_assertEqual(true, is_term(Term, []))} || {Title, _, Term, _} <- Data ].
|
[ {Title, ?_assertEqual(true, is_term(Term, []))} || {Title, _, Term, _} <- Data ].
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue