From d8cde35e4565128b564443f805d78957b2230af9 Mon Sep 17 00:00:00 2001 From: alisdair sullivan Date: Mon, 4 Feb 2013 23:51:02 -0800 Subject: [PATCH] add formatting tests to jsx_to_json --- src/jsx_to_json.erl | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/jsx_to_json.erl b/src/jsx_to_json.erl index 085836f..bea2088 100644 --- a/src/jsx_to_json.erl +++ b/src/jsx_to_json.erl @@ -209,4 +209,47 @@ opts_test_() -> ]. +space_test_() -> + [ + {"no space", ?_assertEqual([], space(#opts{space=0}))}, + {"one space", ?_assertEqual(<<" ">>, space(#opts{space=1}))}, + {"four spaces", ?_assertEqual(<<" ">>, space(#opts{space=4}))} + ]. + + +indent_test_() -> + [ + {"no indent", ?_assertEqual([], indent(#opts{indent=0, depth=1}))}, + {"indent 1 depth 1", ?_assertEqual( + [[?newline], ?space], + indent(#opts{indent=1, depth=1}) + )}, + {"indent 1 depth 2", ?_assertEqual( + [[[?newline], ?space], ?space], + indent(#opts{indent=1, depth=2}) + )}, + {"indent 4 depth 1", ?_assertEqual( + [[?newline], <<" ">>], + indent(#opts{indent=4, depth=1}) + )}, + {"indent 4 depth 2", ?_assertEqual( + [[[?newline], <<" ">>], <<" ">>], + indent(#opts{indent=4, depth=2}) + )} + ]. + + +indent_or_space_test_() -> + [ + {"no indent so space", ?_assertEqual( + <<" ">>, + indent_or_space(#opts{space=1, indent=0, depth=1}) + )}, + {"indent so no space", ?_assertEqual( + [[?newline], ?space], + indent_or_space(#opts{space=1, indent=1, depth=1}) + )} + ]. + + -endif. \ No newline at end of file