Skip to content

Commit

Permalink
Include map() as a PropEr type generator
Browse files Browse the repository at this point in the history
While at it, remove the `?LAZY()` call from its body and also place
some generators in the right -or at least same- order in proper.hrl
and in proper_types.erl
  • Loading branch information
kostis committed Oct 27, 2022
1 parent 3bbd252 commit b4a6374
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
8 changes: 4 additions & 4 deletions include/proper.hrl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%%% -*- coding: utf-8; erlang-indent-level: 2 -*-
%%% -------------------------------------------------------------------
%%% Copyright 2010-2021 Manolis Papadakis <[email protected]>,
%%% Copyright 2010-2022 Manolis Papadakis <[email protected]>,
%%% Eirini Arvaniti <[email protected]>,
%%% and Kostis Sagonas <[email protected]>
%%%
Expand All @@ -19,7 +19,7 @@
%%% You should have received a copy of the GNU General Public License
%%% along with PropEr. If not, see <http://www.gnu.org/licenses/>.

%%% @copyright 2010-2021 Manolis Papadakis, Eirini Arvaniti, and Kostis Sagonas
%%% @copyright 2010-2022 Manolis Papadakis, Eirini Arvaniti, and Kostis Sagonas
%%% @version {@version}
%%% @author Manolis Papadakis
%%% @doc User header file: This file should be included in each file containing
Expand Down Expand Up @@ -58,8 +58,8 @@

-import(proper_types, [integer/0, non_neg_integer/0, pos_integer/0,
neg_integer/0, range/2, float/0, non_neg_float/0,
number/0, boolean/0, byte/0, char/0, list/0, tuple/0,
string/0, wunion/1, term/0, timeout/0, arity/0]).
number/0, boolean/0, arity/0, byte/0, char/0, list/0,
tuple/0, map/0, string/0, term/0, timeout/0, wunion/1]).
-import(proper_types, [int/0, nat/0, largeint/0, real/0, bool/0, choose/2,
elements/1, oneof/1, frequency/1, return/1, default/2,
orderedlist/1, function0/1, function1/1, function2/1,
Expand Down
23 changes: 11 additions & 12 deletions src/proper_types.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1113,11 +1113,6 @@ function_is_instance(Type, X) ->
%% TODO: what if it's not a function we produced?
andalso equal_types(RetType, proper_gen:get_ret_type(X)).

%% @doc A map associating keys and values of unspecified types (of any term()).
-spec map() -> proper_types:type().
map() ->
?LAZY(map(any(), any())).

%% @doc A map whose keys are defined by the generator `K' and values
%% by the generator `V'.
-spec map(K::raw_type(), V::raw_type()) -> proper_types:type().
Expand Down Expand Up @@ -1177,6 +1172,10 @@ number() -> union([integer(), float()]).
-spec boolean() -> proper_types:type().
boolean() -> union(['false', 'true']).

%% @equiv integer(0, 255)
-spec arity() -> proper_types:type().
arity() -> integer(0, 255).

%% @equiv integer(0, 255)
-spec byte() -> proper_types:type().
byte() -> integer(0, 255).
Expand All @@ -1197,14 +1196,14 @@ list() -> list(any()).
-spec tuple() -> proper_types:type().
tuple() -> loose_tuple(any()).

%% @equiv map(any(), any())
-spec map() -> proper_types:type().
map() -> map(any(), any()).

%% @equiv list(char())
-spec string() -> proper_types:type().
string() -> list(char()).

%% @equiv weighted_union(FreqChoices)
-spec wunion([{frequency(),raw_type()},...]) -> proper_types:type().
wunion(FreqChoices) -> weighted_union(FreqChoices).

%% @equiv any()
-spec term() -> proper_types:type().
term() -> any().
Expand All @@ -1213,9 +1212,9 @@ term() -> any().
-spec timeout() -> proper_types:type().
timeout() -> union([non_neg_integer(), 'infinity']).

%% @equiv integer(0, 255)
-spec arity() -> proper_types:type().
arity() -> integer(0, 255).
%% @equiv weighted_union(FreqChoices)
-spec wunion([{frequency(),raw_type()},...]) -> proper_types:type().
wunion(FreqChoices) -> weighted_union(FreqChoices).


%%------------------------------------------------------------------------------
Expand Down

0 comments on commit b4a6374

Please sign in to comment.