more tests, more bugs fixed

This commit is contained in:
alisdair sullivan 2010-08-03 21:15:24 -07:00
parent 3ea3eba7b3
commit 5413c837d4
2 changed files with 12 additions and 4 deletions

View file

@ -70,15 +70,18 @@ collect({event, Start, Next}, Acc, Opts) when Start =:= start_object; Start =:=
collect(Next(), [[]|Acc], Opts); collect(Next(), [[]|Acc], Opts);
%% special case for empty object %% special case for empty object
collect({event, end_object, Next}, [[], Parent|Rest], Opts) -> collect({event, end_object, Next}, [[], Parent|Rest], Opts) when is_list(Parent) ->
collect(Next(), [[[{}]] ++ Parent] ++ Rest, Opts); collect(Next(), [[[{}]] ++ Parent] ++ Rest, Opts);
%% reverse the array/object accumulator before prepending it to it's parent %% reverse the array/object accumulator before prepending it to it's parent
collect({event, end_object, Next}, [Current, Parent|Rest], Opts) when is_list(Parent) -> collect({event, end_object, Next}, [Current, Parent|Rest], Opts) when is_list(Parent) ->
collect(Next(), [[lists:reverse(Current)] ++ Parent] ++ Rest, Opts); collect(Next(), [[lists:reverse(Current)] ++ Parent] ++ Rest, Opts);
collect({event, end_array, Next}, [Current, Parent|Rest], Opts) when is_list(Parent) -> collect({event, end_array, Next}, [Current, Parent|Rest], Opts) when is_list(Parent) ->
collect(Next(), [[lists:reverse(Current)] ++ Parent] ++ Rest, Opts); collect(Next(), [[lists:reverse(Current)] ++ Parent] ++ Rest, Opts);
collect({event, Start, Next}, [Current, Key, Parent|Rest], Opts) %% special case for empty object
when Start =:= end_object; Start =:= end_array -> collect({event, end_object, Next}, [[], Key, Parent|Rest], Opts) ->
collect(Next(), [[{Key, [{}]}] ++ Parent] ++ Rest, Opts);
collect({event, End, Next}, [Current, Key, Parent|Rest], Opts)
when End =:= end_object; End =:= end_array ->
collect(Next(), [[{Key, lists:reverse(Current)}] ++ Parent] ++ Rest, Opts); collect(Next(), [[{Key, lists:reverse(Current)}] ++ Parent] ++ Rest, Opts);
collect({event, end_json, _Next}, [[Acc]], _Opts) -> collect({event, end_json, _Next}, [[Acc]], _Opts) ->

View file

@ -46,7 +46,7 @@ test(Dir) ->
ValidJSONTests = load_tests(Dir), ValidJSONTests = load_tests(Dir),
etap:plan((length(ValidJSONTests) * 10) + 9), etap:plan((length(ValidJSONTests) * 10) + 13),
run_jsx_tests(ValidJSONTests), run_jsx_tests(ValidJSONTests),
etap:is(multi_decode(multi_json_body(), []), multi_test_result(), "multi terms"), etap:is(multi_decode(multi_json_body(), []), multi_test_result(), "multi terms"),
@ -59,6 +59,11 @@ test(Dir) ->
?to_json([{<<"key">>, <<"value">>}, {<<"another key">>, []}], <<"{\"key\":\"value\",\"another key\":[]}">>, "object to json"), ?to_json([{<<"key">>, <<"value">>}, {<<"another key">>, []}], <<"{\"key\":\"value\",\"another key\":[]}">>, "object to json"),
?to_erep(<<"[true, 1, -0.5e7, \"hello world\"]">>, [true, 1, -0.5e7, <<"hello world">>], "array to erep"), ?to_erep(<<"[true, 1, -0.5e7, \"hello world\"]">>, [true, 1, -0.5e7, <<"hello world">>], "array to erep"),
?to_json([true, 1, -0.5e7, <<"hello world">>], <<"[true,1,-5000000.0,\"hello world\"]">>, "array to json"), ?to_json([true, 1, -0.5e7, <<"hello world">>], <<"[true,1,-5000000.0,\"hello world\"]">>, "array to json"),
?to_erep(<<"[[[]]]">>, [[[]]], "deep array to erep"),
?to_json([[[]]], <<"[[[]]]">>, "deep array to json"),
?to_erep(<<"{\"a\":{\"a\":{\"a\":{}}}}">>, [{<<"a">>, [{<<"a">>, [{<<"a">>, [{}]}]}]}], "deep object to erep"),
?to_json([{<<"a">>, [{<<"a">>, [{<<"a">>, [{}]}]}]}], <<"{\"a\":{\"a\":{\"a\":{}}}}">>, "deep object to json"),
etap:end_tests(). etap:end_tests().