diff --git a/src/glc_lib.erl b/src/glc_lib.erl index 787cb3c..75b3989 100644 --- a/src/glc_lib.erl +++ b/src/glc_lib.erl @@ -60,6 +60,11 @@ matches({Key, '<', Term}, Event) -> {true, Term2} -> Term2 < Term; false -> false end; +matches({Key, '=<', Term}, Event) -> + case gre:find(Key, Event) of + {true, Term2} -> Term2 =< Term; + false -> false + end; matches({Key, '=', Term}, Event) -> case gre:find(Key, Event) of {true, Term2} -> Term2 =:= Term; @@ -75,6 +80,11 @@ matches({Key, '>', Term}, Event) -> {true, Term2} -> Term2 > Term; false -> false end; +matches({Key, '>=', Term}, Event) -> + case gre:find(Key, Event) of + {true, Term2} -> Term2 >= Term; + false -> false + end; matches({Key, '*'}, Event) -> case gre:find(Key, Event) of {true, _} -> true; @@ -97,10 +107,14 @@ repeat(Query, Fun) -> -spec onoutput(glc_ops:op()) -> output | no_return(). onoutput({_, '<', _}) -> output; +onoutput({_, '=<', _}) -> + output; onoutput({_, '=', _}) -> output; onoutput({_, '>', _}) -> output; +onoutput({_, '>=', _}) -> + output; onoutput({_, '*'}) -> output; onoutput({_, '!'}) -> @@ -382,12 +396,34 @@ delete_from_any_test() -> default_is_output_test_() -> [?_assertEqual(output, glc_lib:onoutput(glc:lt(a, 1))), + ?_assertEqual(output, glc_lib:onoutput(glc:lte(a, 1))), ?_assertEqual(output, glc_lib:onoutput(glc:eq(a, 1))), ?_assertEqual(output, glc_lib:onoutput(glc:gt(a, 1))), + ?_assertEqual(output, glc_lib:onoutput(glc:gte(a, 1))), ?_assertEqual(output, glc_lib:onoutput(glc:wc(a))), ?_assertEqual(output, glc_lib:onoutput(glc:nf(a))) ]. +matches_test_() -> + Event = gre:make([{a, 2}], [list]), + [?_assertEqual(true, glc_lib:matches(glc:lt(a, 3), Event)), + ?_assertEqual(true, glc_lib:matches(glc:lte(a, 2), Event)), + ?_assertEqual(true, glc_lib:matches(glc:eq(a, 2), Event)), + ?_assertEqual(true, glc_lib:matches(glc:gt(a, 1), Event)), + ?_assertEqual(true, glc_lib:matches(glc:gte(a, 2), Event)), + ?_assertEqual(true, glc_lib:matches(glc:wc(a), Event)), + ?_assertEqual(true, glc_lib:matches(glc:nf(b), Event)), + + ?_assertEqual(false, glc_lib:matches(glc:lt(a, 2), Event)), + ?_assertEqual(false, glc_lib:matches(glc:lte(a, 1), Event)), + ?_assertEqual(false, glc_lib:matches(glc:eq(a, 3), Event)), + ?_assertEqual(false, glc_lib:matches(glc:gt(a, 2), Event)), + ?_assertEqual(false, glc_lib:matches(glc:gte(a, 3), Event)), + ?_assertEqual(false, glc_lib:matches(glc:wc(b), Event)), + ?_assertEqual(false, glc_lib:matches(glc:nf(a), Event)) + ]. + + -ifdef(PROPER). diff --git a/src/glc_ops.erl b/src/glc_ops.erl index 837fce4..36927e5 100644 --- a/src/glc_ops.erl +++ b/src/glc_ops.erl @@ -21,6 +21,7 @@ ]). -type op() :: + {atom(), '<', term()} | {atom(), '=<', term()} | {atom(), '=', term()} | {atom(), '!=', term()} |