Replace etap with eunit for the test suite Finally got off my butt and started using EUnit.
Project: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/commit/11ab9738 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/tree/11ab9738 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/diff/11ab9738 Branch: refs/heads/master Commit: 11ab9738102c84f7add66c281e4733949b909bf9 Parents: 25a3010 Author: Paul J. Davis <[email protected]> Authored: Mon Jun 16 20:58:26 2014 -0500 Committer: Paul J. Davis <[email protected]> Committed: Mon Jun 16 20:58:26 2014 -0500 ---------------------------------------------------------------------- test/001-yajl-tests.t | 30 - test/002-literals.t | 21 - test/003-numbers.t | 118 - test/004-strings.t | 127 -- test/005-arrays.t | 36 - test/006-maps.t | 36 - test/007-compound.t | 41 - test/008-halfword.t | 15 - test/009-reg-issue-24.t | 3459 ---------------------------- test/010-short-doubles.t | 29 - test/etap.erl | 612 ----- test/jiffy_01_yajl_tests.erl | 33 + test/jiffy_02_literal_tests.erl | 28 + test/jiffy_03_number_tests.erl | 134 ++ test/jiffy_04_string_tests.erl | 147 ++ test/jiffy_05_array_tests.erl | 56 + test/jiffy_06_object_tests.erl | 56 + test/jiffy_07_compound_tests.erl | 61 + test/jiffy_08_halfword_tests.erl | 16 + test/jiffy_09_reg_issue_24_tests.erl | 3462 +++++++++++++++++++++++++++++ test/jiffy_10_short_double_tests.erl | 34 + test/jiffy_11_proper_tests.erl | 164 ++ test/jiffy_tests.erl | 153 -- test/jiffy_util.hrl | 25 + test/util.erl | 44 - 25 files changed, 4216 insertions(+), 4721 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/11ab9738/test/001-yajl-tests.t ---------------------------------------------------------------------- diff --git a/test/001-yajl-tests.t b/test/001-yajl-tests.t deleted file mode 100755 index b89fbee..0000000 --- a/test/001-yajl-tests.t +++ /dev/null @@ -1,30 +0,0 @@ -#! /usr/bin/env escript -% This file is part of Jiffy released under the MIT license. -% See the LICENSE file for more information. - -main([]) -> - code:add_pathz("test"), - code:add_pathz("ebin"), - - Cases = read_cases(), - - etap:plan(length(Cases)), - lists:foreach(fun(Case) -> test(Case) end, Cases), - etap:end_tests(). - -test({Name, Json, {error, _}=Erl}) -> - etap:is((catch jiffy:decode(Json)), Erl, Name); -test({Name, Json, Erl}) -> - etap:is(jiffy:decode(Json), Erl, Name). - -read_cases() -> - CasesPath = filename:join(["test", "cases", "*.json"]), - FileNames = lists:sort(filelib:wildcard(CasesPath)), - lists:map(fun(F) -> make_pair(F) end, FileNames). - -make_pair(FileName) -> - {ok, Json} = file:read_file(FileName), - {BaseName, _} = lists:splitwith(fun(C) -> C /= $. end, FileName), - ErlFname = BaseName ++ ".eterm", - {ok, [Term]} = file:consult(ErlFname), - {BaseName, Json, Term}. http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/11ab9738/test/002-literals.t ---------------------------------------------------------------------- diff --git a/test/002-literals.t b/test/002-literals.t deleted file mode 100755 index 8df7255..0000000 --- a/test/002-literals.t +++ /dev/null @@ -1,21 +0,0 @@ -#! /usr/bin/env escript -% This file is part of Jiffy released under the MIT license. -% See the LICENSE file for more information. - -main([]) -> - code:add_pathz("ebin"), - code:add_pathz("test"), - - etap:plan(6), - etap:is(jiffy:decode(<<"true">>), true, "DEC: true -> true"), - etap:is(jiffy:encode(true), <<"true">>, "ENC: true -> true"), - - etap:is(jiffy:decode(<<"false">>), false, "DEC: false -> false"), - etap:is(jiffy:encode(false), <<"false">>, "ENC: false -> false"), - - etap:is(jiffy:decode(<<"null">>), null, "DEC: null -> null"), - etap:is(jiffy:encode(null), <<"null">>, "ENC: null -> null"), - - etap:end_tests(). - - http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/11ab9738/test/003-numbers.t ---------------------------------------------------------------------- diff --git a/test/003-numbers.t b/test/003-numbers.t deleted file mode 100755 index 2ac2ab4..0000000 --- a/test/003-numbers.t +++ /dev/null @@ -1,118 +0,0 @@ -#! /usr/bin/env escript -% This file is part of Jiffy released under the MIT license. -% See the LICENSE file for more information. - -main([]) -> - code:add_pathz("ebin"), - code:add_pathz("test"), - - etap:plan(59 + 2 * length(double_conversion_tests())), - util:test_good(good()), - util:test_errors(errors()), - run_double_conversion_tests(), - etap:end_tests(). - - -run_double_conversion_tests() -> - lists:foreach(fun(Double) -> - Descr = io_lib:format("~f", [Double]), - etap:is(jiffy:decode(jiffy:encode(Double)), Double, Descr), - NegDouble = -1.0 * Double, - NegDescr = io_lib:format("~f", [NegDouble]), - etap:is(jiffy:decode(jiffy:encode(NegDouble)), NegDouble, NegDescr) - end, double_conversion_tests()). - -good() -> - [ - {<<"0">>, 0}, - {<<"-0">>, 0, <<"0">>}, - {<<"1">>, 1}, - {<<"12">>, 12}, - {<<"-3">>, -3}, - {<<"1234567890123456789012345">>, 1234567890123456789012345}, - {<<"1310050760199">>, 1310050760199}, - { - <<"1234567890123456789012345.0">>, - 1.23456789012345678e24, - <<"1.2345678901234568e+24">> - }, - { - <<"1234567890123456789012345.0E3">>, - 1.2345678901234569e27, - <<"1.2345678901234569e+27">> - }, - { - <<"1234567890123456789012345012">>, - 1234567890123456789012345012, - <<"1234567890123456789012345012">> - }, - {<<"1.0">>, 1.0}, - { - <<"0.000000000000000000000000000000000001">>, - 1.0E-36, - <<"1e-36">> - }, - {<<"0.75">>, 0.75}, - {<<"2.0123456789">>, 2.0123456789, <<"2.0123456789">>}, - {<<"2.4234324E24">>, 2.4234324E24, <<"2.4234324e+24">>}, - {<<"-3.1416">>, -3.1416, <<"-3.1416">>}, - {<<"1E4">>, 10000.0, <<"10000.0">>}, - {<<"1.0E+01">>, 10.0, <<"10.0">>}, - {<<"1e1">>, 10.0, <<"10.0">>}, - {<<"3.0E2">>, 300.0, <<"300.0">>}, - {<<"0E3">>, 0.0, <<"0.0">>}, - {<<"1.5E3">>, 1500.0, <<"1500.0">>}, - {<<"2.5E-1">>, 0.25, <<"0.25">>}, - {<<"-0.325E+2">>, -32.5, <<"-32.5">>} - ]. - - -errors() -> - [ - <<"02">>, - <<"-01">>, - <<"+12">>, - <<"-">>, - <<"1.">>, - <<".1">>, - <<"1.-1">>, - <<"1E">>, - <<"1-E2">>, - <<"2E +3">>, - <<"1EA">> - ]. - - -double_conversion_tests() -> - [ - 0.0, - 0.00000001, - 0.000000012, - 0.0000000123, - 0.0000001, - 0.00000012, - 0.000000123, - 0.000001, - 0.00001, - 0.01, - 0.0123, - 0.1, - 0.3, - 1.0, - 1.0e20, - 1.0e21, - 9.0, - 10.0, - 90.0, - 90.12, - 10000.0, - 12345.0, - 12345.0e23, - 100000.0, - 100000000000000000000.0, - 111111111111111111111.0, - 1111111111111111111111.0, - 11111111111111111111111.0 - ]. - - http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/11ab9738/test/004-strings.t ---------------------------------------------------------------------- diff --git a/test/004-strings.t b/test/004-strings.t deleted file mode 100755 index d0214d5..0000000 --- a/test/004-strings.t +++ /dev/null @@ -1,127 +0,0 @@ -#! /usr/bin/env escript -% This file is part of Jiffy released under the MIT license. -% See the LICENSE file for more information. - -main([]) -> - code:add_pathz("ebin"), - code:add_pathz("test"), - - etap:plan(115), - util:test_good(good()), - util:test_good(uescaped(), [uescape]), - util:test_errors(errors()), - - test_utf8(utf8_cases()), - - etap:end_tests(). - -good() -> - [ - {<<"\"\"">>, <<"">>}, - {<<"\"/\"">>, <<"/">>}, - {<<"\"0\"">>, <<"0">>}, - {<<"\"foo\"">>, <<"foo">>}, - {<<"\"\\\"foobar\\\"\"">>, <<"\"foobar\"">>}, - {<<"\"\\n\\n\\n\"">>, <<"\n\n\n">>}, - {<<"\"\\\" \\b\\f\\r\\n\\t\\\"\"">>, <<"\" \b\f\r\n\t\"">>}, - {<<"\"foo\\u0005bar\"">>, <<"foo", 5, "bar">>}, - { - <<"\"\\uD834\\uDD1E\"">>, - <<240, 157, 132, 158>>, - <<34, 240, 157, 132, 158, 34>> - }, - {<<"\"\\uFFFF\"">>, <<239,191,191>>, <<34,239,191,191,34>>}, - {<<"\"\\uFFFE\"">>, <<239,191,190>>, <<34,239,191,190,34>>} - ]. - -uescaped() -> - [ - { - <<"\"\\u8CA8\\u5481\\u3002\\u0091\\u0091\"">>, - <<232,178,168,229,146,129,227,128,130,194,145,194,145>> - }, - { - <<"\"\\uD834\\uDD1E\"">>, - <<240, 157, 132, 158>> - }, - { - <<"\"\\uD83D\\uDE0A\"">>, - <<240, 159, 152, 138>> - } - ]. - -errors() -> - [ - "\"", - <<"\"foo">>, - <<"\"", 0, "\"">>, - <<"\"\\g\"">>, - <<"\"\\uD834foo\\uDD1E\"">>, - % CouchDB-345 - <<34,78,69,73,77,69,78,32,70,216,82,82,32,70,65,69,78,33,34>> - ]. - -test_utf8([]) -> - ok; -test_utf8([{Case, Fixed} | Rest]) -> - etap:fun_is( - fun({error, invalid_string}) -> true; (Else) -> Else end, - (catch jiffy:encode(Case)), - lists:flatten(io_lib:format("Invalid utf-8: ~p", [Case])) - ), - etap:fun_is( - fun(Fixed) -> true; (Else) -> Else end, - jiffy:encode(Case, [force_utf8]), - lists:flatten(io_lib:format("Fixed correctly: ~p", [Fixed])) - ), - Case2 = <<34, Case/binary, 34>>, - etap:fun_is( - fun({error, {_, invalid_string}}) -> true; (Else) -> Else end, - (catch jiffy:decode(Case2)), - lists:flatten(io_lib:format("Invalid utf-8: ~p", [Case2])) - ), - test_utf8(Rest). - -utf8_cases() -> - [ - % Stray continuation byte - {<<16#C2, 16#81, 16#80>>, <<16#C2, 16#81, 16#EF, 16#BF, 16#BD>>}, - {<<"foo", 16#80, "bar">>, <<"foo", 16#EF, 16#BF, 16#BD, "bar">>}, - - % Not enough extension bytes - {<<16#C0>>, <<16#EF, 16#BF, 16#BD>>}, - - {<<16#E0>>, <<16#EF, 16#BF, 16#BD>>}, - {<<16#E0, 16#80>>, <<16#EF, 16#BF, 16#BD>>}, - - {<<16#F0>>, <<16#EF, 16#BF, 16#BD>>}, - {<<16#F0, 16#80>>, <<16#EF, 16#BF, 16#BD>>}, - {<<16#F0, 16#80, 16#80>>, <<16#EF, 16#BF, 16#BD>>}, - - {<<16#F8>>, <<16#EF, 16#BF, 16#BD>>}, - {<<16#F8, 16#80>>, <<16#EF, 16#BF, 16#BD>>}, - {<<16#F8, 16#80, 16#80>>, <<16#EF, 16#BF, 16#BD>>}, - {<<16#F8, 16#80, 16#80, 16#80>>, <<16#EF, 16#BF, 16#BD>>}, - - {<<16#FC>>, <<16#EF, 16#BF, 16#BD>>}, - {<<16#FC, 16#80>>, <<16#EF, 16#BF, 16#BD>>}, - {<<16#FC, 16#80, 16#80>>, <<16#EF, 16#BF, 16#BD>>}, - {<<16#FC, 16#80, 16#80, 16#80>>, <<16#EF, 16#BF, 16#BD>>}, - {<<16#FC, 16#80, 16#80, 16#80, 16#80>>, <<16#EF, 16#BF, 16#BD>>}, - - % No data in high bits. - {<<16#C0, 16#80>>, <<"\"\\u0000\"">>}, - {<<16#C1, 16#80>>, <<"\"\\u0000\"">>}, - - {<<16#E0, 16#80, 16#80>>, <<"\"\\u0000\"">>}, - {<<16#E0, 16#90, 16#80>>, <<"\"\\u0000\"">>}, - - {<<16#F0, 16#80, 16#80, 16#80>>, <<"\"\\u0000\"">>}, - {<<16#F0, 16#88, 16#80, 16#80>>, <<"\"\\u0000\"">>}, - - {<<16#F8, 16#80, 16#80, 16#80, 16#80>>, <<"\"\\u0000\"">>}, - {<<16#F8, 16#84, 16#80, 16#80, 16#80>>, <<"\"\\u0000\"">>}, - - {<<16#FC, 16#80, 16#80, 16#80, 16#80, 16#80>>, <<"\"\\u0000\"">>}, - {<<16#FC, 16#82, 16#80, 16#80, 16#80, 16#80>>, <<"\"\\u0000\"">>} - ]. http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/11ab9738/test/005-arrays.t ---------------------------------------------------------------------- diff --git a/test/005-arrays.t b/test/005-arrays.t deleted file mode 100755 index 1c43c0e..0000000 --- a/test/005-arrays.t +++ /dev/null @@ -1,36 +0,0 @@ -#! /usr/bin/env escript -% This file is part of Jiffy released under the MIT license. -% See the LICENSE file for more information. - -main([]) -> - code:add_pathz("ebin"), - code:add_pathz("test"), - - etap:plan(18), - util:test_good(good()), - util:test_errors(errors()), - etap:end_tests(). - -good() -> - [ - {<<"[]">>, []}, - {<<"[\t[\n]\r]">>, [[]], <<"[[]]">>}, - {<<"[\t123, \r true\n]">>, [123, true], <<"[123,true]">>}, - {<<"[1,\"foo\"]">>, [1, <<"foo">>]}, - {<<"[11993444355.0,1]">>, [11993444355.0,1]}, - { - <<"[\"\\u00A1\",\"\\u00FC\"]">>, - [<<194, 161>>, <<195, 188>>], - <<"[\"", 194, 161, "\",\"", 195, 188, "\"]">> - } - ]. - -errors() -> - [ - <<"[">>, - <<"]">>, - <<"[,]">>, - <<"[123">>, - <<"[123,]">>, - <<"[32 true]">> - ]. http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/11ab9738/test/006-maps.t ---------------------------------------------------------------------- diff --git a/test/006-maps.t b/test/006-maps.t deleted file mode 100755 index 45e715c..0000000 --- a/test/006-maps.t +++ /dev/null @@ -1,36 +0,0 @@ -#! /usr/bin/env escript -% This file is part of Jiffy released under the MIT license. -% See the LICENSE file for more information. - -main([]) -> - code:add_pathz("ebin"), - code:add_pathz("test"), - - etap:plan(15), - util:test_good(good()), - util:test_errors(errors()), - etap:end_tests(). - -good() -> - [ - {<<"{}">>, {[]}}, - {<<"{\"foo\": \"bar\"}">>, - {[{<<"foo">>, <<"bar">>}]}, - <<"{\"foo\":\"bar\"}">>}, - {<<"\n\n{\"foo\":\r \"bar\",\n \"baz\"\t: 123 }">>, - {[{<<"foo">>, <<"bar">>}, {<<"baz">>, 123}]}, - <<"{\"foo\":\"bar\",\"baz\":123}">>} - ]. - -errors() -> - [ - <<"{">>, - <<"{,}">>, - <<"{123:true}">>, - <<"{false:123}">>, - <<"{:\"stuff\"}">>, - <<"{\"key\":}">>, - <<"{\"key\": 123">>, - <<"{\"key\": 123 true">>, - <<"{\"key\": 123,}">> - ]. http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/11ab9738/test/007-compound.t ---------------------------------------------------------------------- diff --git a/test/007-compound.t b/test/007-compound.t deleted file mode 100755 index 2770971..0000000 --- a/test/007-compound.t +++ /dev/null @@ -1,41 +0,0 @@ -#! /usr/bin/env escript -% This file is part of Jiffy released under the MIT license. -% See the LICENSE file for more information. - -main([]) -> - code:add_pathz("ebin"), - code:add_pathz("test"), - - etap:plan(12), - util:test_good(good()), - util:test_errors(errors()), - etap:end_tests(). - -good() -> - [ - {<<"[{}]">>, [{[]}]}, - {<<"{\"foo\":[123]}">>, {[{<<"foo">>, [123]}]}}, - {<<"{\"foo\":{\"bar\":true}}">>, - {[{<<"foo">>, {[{<<"bar">>, true}]} }]} }, - {<<"{\"foo\":[],\"bar\":{\"baz\":true},\"alice\":\"bob\"}">>, - {[ - {<<"foo">>, []}, - {<<"bar">>, {[{<<"baz">>, true}]}}, - {<<"alice">>, <<"bob">>} - ]} - }, - {<<"[-123,\"foo\",{\"bar\":[]},null]">>, - [ - -123, - <<"foo">>, - {[{<<"bar">>, []}]}, - null - ] - } - ]. - -errors() -> - [ - <<"[{}">>, - <<"}]">> - ]. http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/11ab9738/test/008-halfword.t ---------------------------------------------------------------------- diff --git a/test/008-halfword.t b/test/008-halfword.t deleted file mode 100755 index 56f0439..0000000 --- a/test/008-halfword.t +++ /dev/null @@ -1,15 +0,0 @@ -#! /usr/bin/env escript -% This file is part of Jiffy released under the MIT license. -% See the LICENSE file for more information. - -main([]) -> - code:add_pathz("ebin"), - code:add_pathz("test"), - - etap:plan(unknown), - - etap:is(jiffy:decode(<<"1">>) =:= 1, true, "1 =:= 1"), - etap:is(jiffy:decode(<<"1">>) == 1, true, "1 == 1"), - - etap:end_tests(). -
