first tentative steps towards more comprehensive and flexible test suite

This commit is contained in:
alisdair sullivan 2013-02-06 22:28:26 -08:00
parent 51cafcfb64
commit ba42f75780
3 changed files with 31 additions and 18 deletions

View file

@ -34,9 +34,8 @@
-export_type([json_term/0, json_text/0]).
%% test handler
-ifdef(TEST).
-export([init/1, handle_event/2]).
-include("jsx_tests.hrl").
-endif.
@ -151,19 +150,4 @@ encoder(Handler, State, Opts) -> jsx_encoder:encoder(Handler, State, Opts).
-spec parser(Handler::module(), State::any(), Opts::list()) -> parser().
parser(Handler, State, Opts) -> jsx_parser:parser(Handler, State, Opts).
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
%% stub test handler
init([]) -> [].
handle_event(end_json, State) -> lists:reverse([end_json] ++ State);
handle_event(Event, State) -> [Event] ++ State.
-endif.
parser(Handler, State, Opts) -> jsx_parser:parser(Handler, State, Opts).

17
src/jsx_tests.hrl Normal file
View file

@ -0,0 +1,17 @@
%% data and helper functions for tests
-export([init/1, handle_event/2]).
-export([empty_array/0, empty_object/0]).
-include_lib("eunit/include/eunit.hrl").
%% test handler
init([]) -> [].
handle_event(end_json, State) -> lists:reverse([end_json] ++ State);
handle_event(Event, State) -> [Event] ++ State.
empty_array() -> [{"empty array", <<"[]">>, [], [start_array, end_array, end_json]}].
empty_object() -> [{"empty object", <<"{}">>, [{}], [start_object, end_object, end_json]}].

View file

@ -114,4 +114,16 @@ opts_test_() ->
].
valid_json_test_() ->
Data = jsx:empty_array()
++ jsx:empty_object(),
[ {Title, ?_assertEqual(true, is_json(JSON, []))} || {Title, JSON, _, _} <- Data ].
valid_term_test_() ->
Data = jsx:empty_array()
++ jsx:empty_object(),
[ {Title, ?_assertEqual(true, is_term(Term, []))} || {Title, _, Term, _} <- Data ].
-endif.