Permalink
Browse files

unit tests on parse transform extension

  • Loading branch information...
1 parent e2db7aa commit 1432ca1dd50bb4a1f103b9939a9b95568349abff @eiriniar eiriniar committed Jun 28, 2011
Showing with 31 additions and 12 deletions.
  1. +4 −4 src/proper_typeserver.erl
  2. +10 −0 test/no_out_of_forall_test.erl
  3. +17 −8 test/proper_tests.erl
@@ -36,7 +36,7 @@
%%% The use of native types in properties is subject to the following usage
%%% rules:
%%% <ul>
-%%% <li>Native types cannot be used outside of `?FORALL's.</li>
+%%% <li>Native types cannot be used outside of `?FORALL's.</li> *****
%%% <li>Inside `?FORALL's, native types can be combined with other native
%%% types, and even with PropEr types, inside tuples and lists (the constructs
%%% `[...]', `{...}' and `++' are all allowed).</li>
@@ -47,7 +47,7 @@
%%% <li>Anything other than a tuple constructor, list constructor, `++'
%%% application, local or remote call will automatically be considered a
%%% PropEr type constructor and not be processed further by the parse
-%%% transform.</li>
+%%% transform.</li> *****
%%% <li>Parametric native types are fully supported; of course, they can only
%%% appear instantiated in a `?FORALL'. The arguments of parametric native
%%% types are always interpreted as native types.</li>
@@ -67,9 +67,9 @@
%%% <li>`?SUCHTHAT', `?SUCHTHATMAYBE', `non_empty', `noshrink': these work
%%% with native types too</li>
%%% <li>`?LAZY', `?SHRINK', `resize', `?SIZED': these don't work with native
-%%% types</li>
+%%% types</li> ???
%%% <li>`?LET', `?LETSHRINK': only the top-level base type can be a native
-%%% type</li>
+%%% type</li> ???
%%% </ul></li>
%%% <li>Native type declarations in the `?FORALL's of a module can reference any
%%% custom type declared in a `-type' or `-opaque' attribute of the same
@@ -25,8 +25,18 @@
-module(no_out_of_forall_test).
-export([]).
+-type local_type() :: integer().
+-type parametric(T) :: {0,T}.
+
-include_lib("proper/include/proper.hrl").
foo() -> ?LET(X, types_test1:exp1(), {42,X}).
+bar2() -> ?LAZY(rec_props_test2:exp2()).
+bar3() -> ?SHRINK(local_type(), [42, local_type()]).
+bar4() -> ?SIZED(Size, resize(Size * 2, parametric(local_type()))).
+
prop_1() -> ?FORALL(_, foo(), true).
+prop_2() -> ?FORALL(_, bar2(), true).
+prop_3() -> ?FORALL(_, bar3(), true).
+prop_4() -> ?FORALL(_, bar4(), true).
View
@@ -513,14 +513,15 @@ undefined_symb_calls() ->
{call,erlang,'+',[1,2,3]}].
combinations() ->
- [{[{1,[1,3,5,7,9,10]}, {2,[2,4,6,8,11]}], 5, 11, [1,2,3,4,5,6,7,8,9,10,11], 2, 2,
- [{1,[1,3,5,7,8,11]}, {2,[2,4,6,9,10]}]},
+ [{[{1,[1,3,5,7,9,10]}, {2,[2,4,6,8,11]}], 5, 11, [1,2,3,4,5,6,7,8,9,10,11],
+ 2, 2, [{1,[1,3,5,7,8,11]}, {2,[2,4,6,9,10]}]},
{[{1,[1,3,5]}, {2,[7,8,9]}, {3,[2,4,6]}], 3, 9, [1,3,5,7,8,9], 3, 2,
[{1,[6,8,9]}, {2,[1,3,5]}, {3,[2,4,7]}]}].
-first_comb() -> [{10,3,3,[{1,[7,8,9,10]}, {2,[4,5,6]}, {3,[1,2,3]}]},
- {11,5,2,[{1,[6,7,8,9,10,11]}, {2,[1,2,3,4,5]}]},
- {12,3,4,[{1,[10,11,12]}, {2,[7,8,9]}, {3,[4,5,6]}, {4,[1,2,3]}]}].
+first_comb() ->
+ [{10,3,3,[{1,[7,8,9,10]}, {2,[4,5,6]}, {3,[1,2,3]}]},
+ {11,5,2,[{1,[6,7,8,9,10,11]}, {2,[1,2,3,4,5]}]},
+ {12,3,4,[{1,[10,11,12]}, {2,[7,8,9]}, {3,[4,5,6]}, {4,[1,2,3]}]}].
lists_to_zip() ->
[{[],[],[]},
@@ -564,7 +565,8 @@ valid_command_sequences() ->
[{a,5}], [{a,5}], []},
{pdict_statem, [], [{init,[]},
{set,{var,1},{call,erlang,put,[a,{var,start_value}]}},
- {set,{var,2},{call,erlang,put,[b,{var,another_start_value}]}},
+ {set,{var,2},{call,erlang,put,
+ [b,{var,another_start_value}]}},
{set,{var,3},{call,erlang,get,[b]}},
{set,{var,4},{call,erlang,get,[b]}}],
[{b,{var,another_start_value}}, {a,{var,start_value}}], [{b,-1}, {a, 0}],
@@ -701,7 +703,10 @@ parse_transform_test_() ->
[?_passes(auto_export_test1:prop_1()),
?_assertError(undef, auto_export_test2:prop_1()),
?_assertError(undef, no_native_parse_test:prop_1()),
- ?_passes(no_out_of_forall_test:prop_1())].
+ ?_passes(no_out_of_forall_test:prop_1()),
+ ?_passes(no_out_of_forall_test:prop_2()),
+ ?_passes(no_out_of_forall_test:prop_3()),
+ ?_passes(no_out_of_forall_test:prop_4())].
native_type_props_test_() ->
[?_passes(?FORALL({X,Y}, {my_native_type(),my_proper_type()},
@@ -736,7 +741,11 @@ native_type_props_test_() ->
?_passes(?FORALL(L, vector(2,my_native_type()),
length(L) =:= 2
andalso lists:all(fun erlang:is_integer/1, L))),
- ?_passes(?FORALL(F, function(0,my_native_type()), is_integer(F()))),
+ ?_passes(?FORALL(F, function(0, my_native_type()), is_integer(F()))),
+ ?_passes(begin
+ Foo = function(0, my_native_type()),
+ ?FORALL(F, Foo, is_integer(F()))
+ end),
?_passes(?FORALL(X, union([my_proper_type(),my_native_type()]),
is_integer(X) orelse is_atom(X))),
?_passes(begin

0 comments on commit 1432ca1

Please sign in to comment.