From 4a3f2a3fa4054695b976217ef35b83df4cfddb0a Mon Sep 17 00:00:00 2001 From: alisdair sullivan Date: Mon, 11 Feb 2013 16:36:46 -0800 Subject: [PATCH] add test for objectify generator --- src/jsx_tests.hrl | 57 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/src/jsx_tests.hrl b/src/jsx_tests.hrl index 2efd265..bcaf3ac 100644 --- a/src/jsx_tests.hrl +++ b/src/jsx_tests.hrl @@ -181,10 +181,63 @@ objectify([], {_, JSON, Term, Events}) -> }; objectify([Test|Rest], Acc) -> {_, A, M, X} = Acc, - {_, B, N, [Y]} = Test, + {_, B, N, Y} = Test, objectify(Rest, { null, <>, M ++ [{B, N}], - X ++ [{key, B}, Y] + X ++ [{key, B}] ++ Y }). + + +listify_test_() -> + {"listify test", ?_assertEqual( + { + "[true,1,\"hello world\",{}]", + <<"[true,1,\"hello world\",{}]">>, + [true, 1, <<"hello world">>, [{}]], + [ + start_array, + {literal, true}, + {integer, 1}, + {string, <<"hello world">>}, + start_object, + end_object, + end_array + ] + }, + listify([ + {"true", <<"true">>, true, [{literal, true}]}, + {"1", <<"1">>, 1, [{integer, 1}]}, + {"hello world", <<"\"hello world\"">>, <<"hello world">>, [{string, <<"hello world">>}]}, + {"{}", <<"{}">>, [{}], [start_object, end_object]} + ]) + )}. + +objectify_test_() -> + {"objectify test", ?_assertEqual( + { + "{\"true\":true,\"1\":1,\"\"hello world\"\":\"hello world\",\"[]\":[]}", + <<"{\"true\":true,\"1\":1,\"\"hello world\"\":\"hello world\",\"[]\":[]}">>, + [{<<"true">>, true}, {<<"1">>, 1}, {<<"\"hello world\"">>, <<"hello world">>}, {<<"[]">>, []}], + [ + start_object, + {key, <<"true">>}, + {literal, true}, + {key, <<"1">>}, + {integer, 1}, + {key, <<"\"hello world\"">>}, + {string, <<"hello world">>}, + {key, <<"[]">>}, + start_array, + end_array, + end_object + ] + }, + objectify([ + {"true", <<"true">>, true, [{literal, true}]}, + {"1", <<"1">>, 1, [{integer, 1}]}, + {"hello world", <<"\"hello world\"">>, <<"hello world">>, [{string, <<"hello world">>}]}, + {"[]", <<"[]">>, [], [start_array, end_array]} + ]) + )}.