Skip to content

Commit 61041f0

Browse files
Improvements and tests
Co-authored-by: Jan Uhlig <juhlig@hnc-agency.org>
1 parent a76d552 commit 61041f0

File tree

5 files changed

+21
-11
lines changed

5 files changed

+21
-11
lines changed

include/proper.hrl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@
4646
%% Basic types
4747
%%------------------------------------------------------------------------------
4848

49-
-import(proper_types, [integer/2, float/2, atom/0, binary/0, binary/1,
50-
bitstring/0, bitstring/1, list/1, vector/2, union/1,
51-
weighted_union/1, tuple/1, loose_tuple/1, exactly/1,
52-
fixed_list/1, function/2, map/2, any/0]).
49+
-import(proper_types, [integer/2, float/2, atom/0, existing_atom/0, binary/0,
50+
binary/1, bitstring/0, bitstring/1, list/1, vector/2,
51+
union/1, weighted_union/1, tuple/1, loose_tuple/1,
52+
exactly/1, fixed_list/1, function/2, map/2, any/0]).
5353

5454

5555
%%------------------------------------------------------------------------------

src/proper_gen.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
any_gen/1, native_type_gen/2, safe_weighted_union_gen/1,
4747
safe_union_gen/1]).
4848

49-
-export([existing_atom_gen/1]).
49+
-export([existing_atom_gen/0]).
5050

5151
%% Public API types
5252
-export_type([instance/0, seed/0, size/0]).
@@ -421,10 +421,10 @@ atom_rev(Atom) ->
421421
{'$used', atom_to_list(Atom), Atom}.
422422

423423
%% @private
424-
-spec existing_atom_gen(size()) -> atom().
424+
-spec existing_atom_gen() -> atom().
425425
%% We make sure we never clash with internal atoms by ignoring atoms starting with
426426
%% the character '$'.
427-
existing_atom_gen(_Size) ->
427+
existing_atom_gen() ->
428428
case get('$existing_atoms') of
429429
undefined ->
430430
{NextIndex, Atoms} = get_existing_atoms(0, #{}),

src/proper_types.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ atom() ->
683683
-spec existing_atom() -> proper_types:type().
684684
existing_atom() ->
685685
?BASIC([
686-
{generator, fun proper_gen:existing_atom_gen/1},
686+
{generator, fun proper_gen:existing_atom_gen/0},
687687
{reverse_gen, fun proper_gen:atom_rev/1},
688688
{is_instance, fun atom_is_instance/1},
689689
{noshrink, true}

src/proper_typeserver.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@
187187

188188
%% CAUTION: all these must be sorted
189189
-define(STD_TYPES_0,
190-
[any,arity,atom,binary,bitstring,bool,boolean,byte,char,float,integer,
191-
list,neg_integer,nil,non_neg_integer,number,pos_integer,string,term,
192-
timeout]).
190+
[any,arity,atom,binary,bitstring,bool,boolean,byte,char,existing_atom,
191+
float,integer,list,neg_integer,nil,non_neg_integer,number,pos_integer,
192+
string,term,timeout]).
193193
-define(HARD_ADTS,
194194
%% gb_trees:iterator and gb_sets:iterator are NOT hardcoded
195195
[{{array,0},array}, {{array,1},proper_array},

test/proper_tests.erl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,6 +1398,16 @@ sampleshrink_test_() ->
13981398
?_shrinksTo([a], Gen)},
13991399
?_test(proper_gen:sampleshrink(Gen))]}].
14001400

1401+
existing_atom_test() ->
1402+
N = erlang:system_info(atom_count),
1403+
{ok, Atom} = proper_gen:pick(proper_types:existing_atom()),
1404+
?assert(erlang:is_atom(Atom)),
1405+
?assertEqual(N, erlang:system_info(atom_count)).
1406+
1407+
default_atom_test() ->
1408+
N = erlang:system_info(atom_count),
1409+
?assert(proper:quickcheck(?FORALL(_, any(), true), [{default_atom_generator, existing_atom}])),
1410+
?assertEqual(N, erlang:system_info(atom_count)).
14011411

14021412
%%------------------------------------------------------------------------------
14031413
%% Performance tests

0 commit comments

Comments
 (0)