extend tests to decoder, encoder and parser

This commit is contained in:
alisdair sullivan 2013-02-11 18:22:45 -08:00
parent 7f3cb6e496
commit eaf19cde9c
3 changed files with 66 additions and 0 deletions

View file

@ -726,6 +726,8 @@ zero(<<?comma, Rest/binary>>, Handler, [Acc, array|Stack], Opts) ->
value(Rest, handle_event(format_number(Acc), Handler, Opts), [array|Stack], Opts);
zero(<<?decimalpoint, Rest/binary>>, Handler, [Acc|Stack], Opts) ->
initial_decimal(Rest, Handler, [{Acc, []}|Stack], Opts);
zero(<<S, Rest/binary>>, Handler, [Acc|Stack], Opts) when S =:= $e; S =:= $E ->
e(Rest, Handler, [{Acc, [], []}|Stack], Opts);
zero(<<S, Rest/binary>>, Handler, [Acc|Stack], Opts) when ?is_whitespace(S) ->
maybe_done(Rest, handle_event(format_number(Acc), Handler, Opts), Stack, Opts);
zero(<<?solidus, Rest/binary>>, Handler, [Acc|Stack], Opts=#opts{comments=true}) ->
@ -1610,4 +1612,25 @@ to_fake_utf(N, utf8) ->
<<34/utf8, 2#11110:5, W:3, 2#10:2, Z:6, 2#10:2, Y:6, 2#10:2, X:6, 34/utf8>>.
decode_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(
Events ++ [end_json],
start(JSON, {jsx, []}, [], #opts{})
)
} || {Title, JSON, _, Events} <- Data
].
-endif.

View file

@ -136,4 +136,25 @@ clean_string(Bin, Opts) -> jsx_utils:clean_string(Bin, Opts).
-include_lib("eunit/include/eunit.hrl").
encode_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(
Events ++ [end_json],
start(Term, {jsx, []}, #opts{})
)
} || {Title, _, Term, Events} <- Data
].
-endif.

View file

@ -169,4 +169,26 @@ clean_string(Bin, Opts) -> jsx_utils:clean_string(Bin, Opts).
-include_lib("eunit/include/eunit.hrl").
decode_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(
Events ++ [end_json],
value(Events ++ [end_json], {jsx, []}, [], #opts{})
)
} || {Title, _, _, Events} <- Data
].
-endif.