Permalink
Browse files

Add test for regexp

  • Loading branch information...
1 parent 8628ed4 commit 797633eaad90461bab7c3cb8c87499ce3c4f711a @nevar nevar committed Dec 26, 2012
Showing with 9 additions and 1 deletion.
  1. +1 −1 src/neotoma_peg.erl
  2. +8 −0 test/test_combinators.erl
View
@@ -13,6 +13,6 @@
-export([p/4, p/5]).
-export([setup_memo/0, release_memo/0]).
--export([p_eof/0, p_optional/1, p_not/1, p_assert/1, p_seq/1, p_and/1, p_choose/1, p_zero_or_more/1, p_one_or_more/1, p_label/2, p_string/1, p_anything/0, p_charclass/1, line/1, column/1]).
+-export([p_eof/0, p_optional/1, p_not/1, p_assert/1, p_seq/1, p_and/1, p_choose/1, p_zero_or_more/1, p_one_or_more/1, p_label/2, p_string/1, p_anything/0, p_charclass/1, p_regexp/1, line/1, column/1]).
-include("priv/peg_includes.hrl").
@@ -85,6 +85,14 @@ charclass_test_() ->
?_assertEqual({fail,{expected, {character_class, "[+]"}, ?STARTINDEX}}, (neotoma_peg:p_charclass(<<"[+]">>))(<<"----">>,?STARTINDEX))
].
+regexp_test_() ->
+ RegexpFun = neotoma_peg:p_regexp(<<"a*">>),
+ [
+ ?_assertEqual({<<"">>,<<"bbb">>,{{line,1},{column,1}}}, RegexpFun(<<"bbb">>,?STARTINDEX)),
+ ?_assertEqual({<<"a">>,<<"bbb">>,{{line,1},{column,2}}}, RegexpFun(<<"abbb">>,?STARTINDEX)),
+ ?_assertEqual({<<"aaa">>,<<"bbb">>,{{line,1},{column,4}}}, RegexpFun(<<"aaabbb">>,?STARTINDEX))
+ ].
+
line_test() ->
?assertEqual(1, neotoma_peg:line({{line,1},{column,2}})).

0 comments on commit 797633e

Please sign in to comment.