diff options
author | Alexander Shorin <kxepal@apache.org> | 2014-06-04 13:22:13 +0400 |
---|---|---|
committer | Alexander Shorin <kxepal@apache.org> | 2014-06-17 01:41:45 +0400 |
commit | db4989f5ef55e32b99ca91dfa2e371e2bf1958d7 (patch) | |
tree | 52e05d24950bfa40de30d246dea74513e1ef7a90 | |
parent | a09e85a35f5b4b5f58cd3340d04195680d911abf (diff) | |
download | couchdb-db4989f5ef55e32b99ca91dfa2e371e2bf1958d7.tar.gz |
Port 190-json-stream-parse.t etap test suite to eunit
-rw-r--r-- | test/couchdb/Makefile.am | 1 | ||||
-rw-r--r--[-rwxr-xr-x] | test/couchdb/json_stream_parse_tests.erl (renamed from test/etap/190-json-stream-parse.t) | 97 | ||||
-rw-r--r-- | test/etap/Makefile.am | 1 |
3 files changed, 33 insertions, 66 deletions
diff --git a/test/couchdb/Makefile.am b/test/couchdb/Makefile.am index 9ab266f85..6025ac600 100644 --- a/test/couchdb/Makefile.am +++ b/test/couchdb/Makefile.am @@ -46,6 +46,7 @@ eunit_files = \ couchdb_update_conflicts_tests.erl \ couchdb_vhosts_tests.erl \ couchdb_views_tests.erl \ + json_stream_parse_tests.erl \ test_request.erl \ test_web.erl \ couch_eunit.hrl diff --git a/test/etap/190-json-stream-parse.t b/test/couchdb/json_stream_parse_tests.erl index 49ea58f83..92303b65e 100755..100644 --- a/test/etap/190-json-stream-parse.t +++ b/test/couchdb/json_stream_parse_tests.erl @@ -1,4 +1,3 @@ -#!/usr/bin/env escript % Licensed under the Apache License, Version 2.0 (the "License"); you may not % use this file except in compliance with the License. You may obtain a copy of % the License at @@ -11,67 +10,11 @@ % License for the specific language governing permissions and limitations under % the License. -main(_) -> - test_util:init_code_path(), - etap:plan(99), - case (catch test()) of - ok -> - etap:end_tests(); - Other -> - etap:diag("Test died abnormally: ~p", [Other]), - etap:bail("Bad return value.") - end, - ok. +-module(json_stream_parse_tests). -test() -> - crypto:start(), - ok = test_raw_json_input(), - ok = test_1_byte_data_function(), - ok = test_multiple_bytes_data_function(). +-include("couch_eunit.hrl"). - -test_raw_json_input() -> - etap:diag("Tests with raw JSON string as the input."), - lists:foreach( - fun({EJson, JsonString, Desc}) -> - etap:is( - equiv(EJson, json_stream_parse:to_ejson(JsonString)), - true, - Desc) - end, - cases()), - ok. - - -test_1_byte_data_function() -> - etap:diag("Tests with a 1 byte output data function as the input."), - lists:foreach( - fun({EJson, JsonString, Desc}) -> - DataFun = fun() -> single_byte_data_fun(JsonString) end, - etap:is( - equiv(EJson, json_stream_parse:to_ejson(DataFun)), - true, - Desc) - end, - cases()), - ok. - - -test_multiple_bytes_data_function() -> - etap:diag("Tests with a multiple bytes output data function as the input."), - lists:foreach( - fun({EJson, JsonString, Desc}) -> - DataFun = fun() -> multiple_bytes_data_fun(JsonString) end, - etap:is( - equiv(EJson, json_stream_parse:to_ejson(DataFun)), - true, - Desc) - end, - cases()), - ok. - - -cases() -> +-define(CASES, [ {1, "1", "integer numeric literial"}, {3.1416, "3.14160", "float numeric literal"}, % text representation may truncate, trail zeroes @@ -117,7 +60,35 @@ cases() -> {[-123, <<"foo">>, {[{<<"bar">>, []}]}, null], "[-123,\"foo\",{\"bar\":[]},null]", "complex array literal"} - ]. + ] +). + + +raw_json_input_test_() -> + Tests = lists:map( + fun({EJson, JsonString, Desc}) -> + {Desc, + ?_assert(equiv(EJson, json_stream_parse:to_ejson(JsonString)))} + end, ?CASES), + {"Tests with raw JSON string as the input", Tests}. + +one_byte_data_fun_test_() -> + Tests = lists:map( + fun({EJson, JsonString, Desc}) -> + DataFun = fun() -> single_byte_data_fun(JsonString) end, + {Desc, + ?_assert(equiv(EJson, json_stream_parse:to_ejson(DataFun)))} + end, ?CASES), + {"Tests with a 1 byte output data function as the input", Tests}. + +test_multiple_bytes_data_fun_test_() -> + Tests = lists:map( + fun({EJson, JsonString, Desc}) -> + DataFun = fun() -> multiple_bytes_data_fun(JsonString) end, + {Desc, + ?_assert(equiv(EJson, json_stream_parse:to_ejson(DataFun)))} + end, ?CASES), + {"Tests with a multiple bytes output data function as the input", Tests}. %% Test for equivalence of Erlang terms. @@ -139,7 +110,6 @@ equiv(false, false) -> equiv(null, null) -> true. - %% Object representation and traversal order is unknown. %% Use the sledgehammer and sort property lists. equiv_object(Props1, Props2) -> @@ -152,20 +122,17 @@ equiv_object(Props1, Props2) -> end, Pairs). - %% Recursively compare tuple elements for equivalence. equiv_list([], []) -> true; equiv_list([V1 | L1], [V2 | L2]) -> equiv(V1, V2) andalso equiv_list(L1, L2). - single_byte_data_fun([]) -> done; single_byte_data_fun([H | T]) -> {<<H>>, fun() -> single_byte_data_fun(T) end}. - multiple_bytes_data_fun([]) -> done; multiple_bytes_data_fun(L) -> diff --git a/test/etap/Makefile.am b/test/etap/Makefile.am index b92faf13c..72718e8f7 100644 --- a/test/etap/Makefile.am +++ b/test/etap/Makefile.am @@ -32,7 +32,6 @@ fixture_files = \ fixtures/test.couch tap_files = \ - 190-json-stream-parse.t \ 200-view-group-no-db-leaks.t \ 201-view-group-shutdown.t \ 210-os-proc-pool.t \ |