Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

v0.2.1 - bugs in qlc; test cases added

  • Loading branch information...
commit 305c2d4f00ed635cbf7723bf8e2e1e21af79239e 1 parent f6ac2d7
Ulf Wiger authored
Showing with 42 additions and 2 deletions.
  1. +1 −1  src/gproc.app.src
  2. +2 −1  src/gproc.erl
  3. +39 −0 test/gproc_tests.erl
View
2  src/gproc.app.src
@@ -5,7 +5,7 @@
{application, gproc,
[
{description, "GPROC"},
- {vsn, "0.2.0"},
+ {vsn, "0.2.1"},
{id, "GPROC"},
{registered, [ ] },
%% NOTE: do not list applications which are load-only!
View
3  src/gproc.erl
@@ -1132,9 +1132,10 @@ pattern([{{A,B,C},Gs,As}], Scope) ->
[{HeadPat, rewrite(Gs,Vars), rewrite(As,Vars)}];
pattern([{Head, Gs, As}], Scope) ->
?l,
+ {S, T} = get_s_t(Scope),
case is_var(Head) of
{true,_N} ->
- HeadPat = {{{type(Scope),'_','_'},'_'},'_','_'},
+ HeadPat = {{{T,S,'_'},'_'},'_','_'},
Vs = [{Head, obj_prod()}],
%% {HeadPat, Vs} = headpat(Scope, A,B,C),
%% the headpat function should somehow verify that Head is
View
39 test/gproc_tests.erl
@@ -20,6 +20,7 @@
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
+-include_lib("stdlib/include/qlc.hrl").
reg_test_() ->
{setup,
@@ -54,6 +55,8 @@ reg_test_() ->
, ?_test(t_is_clean())
, {spawn, ?_test(t_select())}
, ?_test(t_is_clean())
+ , {spawn, ?_test(t_qlc())}
+ , ?_test(t_is_clean())
]}.
t_simple_reg() ->
@@ -223,6 +226,42 @@ t_select() ->
{all,all},
[{{'_',self(),'_'},[],['$_']}])).
+t_qlc() ->
+ ?assertEqual(true, gproc:reg({n, l, {n,1}}, x)),
+ ?assertEqual(true, gproc:reg({n, l, {n,2}}, y)),
+ ?assertEqual(true, gproc:reg({p, l, {p,1}}, x)),
+ ?assertEqual(true, gproc:reg({p, l, {p,2}}, y)),
+ ?assertEqual(true, gproc:reg({c, l, {c,1}}, 1)),
+ ?assertEqual(true, gproc:reg({a, l, {c,1}}, undefined)),
+ %% local names
+ Exp1 = [{{n,l,{n,1}},self(),x},
+ {{n,l,{n,2}},self(),y}],
+ ?assertEqual(Exp1,
+ qlc:e(qlc:q([N || N <- gproc:table(names)]))),
+ ?assertEqual(Exp1,
+ qlc:e(qlc:q([N || {{n,l,_},_,_} = N <- gproc:table(names)]))),
+
+ %% mactch local names on value
+ Exp2 = [{{n,l,{n,1}},self(),x}],
+ ?assertEqual(Exp2,
+ qlc:e(qlc:q([N || {{n,l,_},_,x} = N <- gproc:table(names)]))),
+
+ %% match all on value
+ Exp3 = [{{n,l,{n,1}},self(),x},
+ {{p,l,{p,1}},self(),x}],
+ ?assertEqual(Exp3,
+ qlc:e(qlc:q([N || {_,_,x} = N <- gproc:table(all)]))),
+
+ %% match all on pid
+ Exp4 = [{{a,l,{c,1}},self(),1},
+ {{c,l,{c,1}},self(),1},
+ {{n,l,{n,1}},self(),x},
+ {{n,l,{n,2}},self(),y},
+ {{p,l,{p,1}},self(),x},
+ {{p,l,{p,2}},self(),y}
+ ],
+ ?assertEqual(Exp4,
+ qlc:e(qlc:q([X || X <- gproc:table(all)]))).
t_loop() ->
receive
Please sign in to comment.
Something went wrong with that request. Please try again.