diff --git a/rebar.config b/rebar.config index 7ee1bcd..b8371a9 100644 --- a/rebar.config +++ b/rebar.config @@ -16,7 +16,7 @@ {"darwin10.*-32$", "LDFLAGS", "-arch i386"} ]}. -{eunit_opts, [{file, "test/props.erl"}]}. +{eunit_opts, [verbose, {report,{eunit_surefire,[{dir,"."}]}}]}. {deps, [{proper_stdlib, ".*", {git, "https://github.com/spawngrid/proper_stdlib.git", "master"}}, diff --git a/test/jiffy_SUITE.erl b/test/jiffy_SUITE.erl deleted file mode 100644 index 0806037..0000000 --- a/test/jiffy_SUITE.erl +++ /dev/null @@ -1,25 +0,0 @@ --module(jiffy_SUITE). --include_lib("proper/include/proper.hrl"). --include_lib("proper_stdlib/include/proper_ct.hrl"). --compile(export_all). - -all() -> proper_ct:testcases(?MODULE). - -init_per_testcase(tc_prop_foo, Config) -> - [{proper, [{numtests, 1000}]} | Config]. - --type json_any() :: json_list() - | json_dict() - | json_number() - | json_string() - | json_null(). --type json_list() :: list(json_any()). --type json_dict() :: {[{json_key(), json_any()}]}. --type json_key() :: binary(). --type json_number() :: integer() | float(). --type json_string() :: binary(). --type json_null() :: null. - -prop_foo() -> - ?FORALL(Data, json_any(), - Data == jiffy:decode(jiffy:encode(Data))). diff --git a/test/proper_tests.erl b/test/proper_tests.erl new file mode 100644 index 0000000..1bccf40 --- /dev/null +++ b/test/proper_tests.erl @@ -0,0 +1,89 @@ +-module(proper_tests). +-include_lib("proper/include/proper.hrl"). +%%-include_lib("proper_stdlib/include/proper_ct.hrl"). +-include_lib("eunit/include/eunit.hrl"). +-export([proper_test_/0]). + +all() -> proper_ct:testcases(?MODULE). + +init_per_testcase(tc_prop_foo, Config) -> + [{proper, [{numtests, 1000}]} | Config]. + +-type json_any() :: json_list() + | json_dict() + | json_number() + | json_string() + | json_null(). +-type json_list() :: list(json_any()). +-type json_dict() :: {[{json_key(), json_any()}]}. +-type json_key() :: binary(). +-type json_number() :: integer() | float(). +-type json_string() :: binary(). +-type json_null() :: null. + +%% Atomic types +json_null() -> + null. + +json_string() -> + ?LET(Str, proper_stdgen:utf8_bin(), + binary:replace(Str, <<"\"">>, <<"\\\"">>, [global])). %good enough + +json_number() -> + oneof([integer(), float()]). + +json_boolean() -> + oneof([true, false]). + +json_atomic() -> + oneof([json_null(), + json_string(), + json_number(), + json_boolean()]). + +%% Compound types +json_object() -> + ?SIZED(S, json_object(S)). +json_object(0) -> + json_atomic(); +json_object(S) -> + frequency([{1, json_object(0)}, + {3, json_list()}, + {9, ?LAZY( + ?LETSHRINK( + [Node], + [{list({json_string(), json_object(S - 1)})}], + Node + ))}]). + +json_list() -> + list(json_object()). + +tree(G) -> + ?SIZED(S, tree(S, G)). +tree(0, _) -> + leaf; +tree(S, G) -> + frequency([ + {1, tree(0, G)}, + {9, ?LAZY( + ?LETSHRINK( + [L, R], + [tree(S div 2, G), tree(S div 2, G)], + {node, G, L, R} + ))} + ]). + +prop_foo() -> +%% ?FORALL(Data, json_any(), +%% Data == jiffy:decode(jiffy:encode(Data))). + ?FORALL(Data, json_object(), + begin + %io:format(user, "Data: ~p~n", [Data]), + Data == jiffy:decode(jiffy:encode(Data)) + end). + +proper_test_() -> + {timeout, 600, + ?_assertEqual([], proper:module(proper_tests, [{to_file, user}, + {numtests, 10}]))}.