Permalink
Browse files

[t/spec] tests for action stubs in grammars

git-svn-id: http://svn.pugscode.org/pugs@25691 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information...
1 parent 42bb43b commit c1520abb04b7974fb783ee33cdf97bceb99b3ded moritz committed Mar 4, 2009
Showing with 37 additions and 0 deletions.
  1. +37 −0 S05-grammar/action-stubs.t
View
@@ -0,0 +1,37 @@
+use v6;
+
+use Test;
+plan 5;
+
+# TODO: needs specs and smartlinks
+
+grammar A::Test::Grammar {
+ rule TOP { <a> <b> }
+ token a { 'a' \w+ {*} }
+ token b { 'b' \w+ {*} }
+}
+
+class An::Action1 {
+ has $.in-a = 0;
+ has $.in-b = 0;
+ has $.calls = '';
+ method a($/) {
+ $!in-a++;
+ $!calls ~= 'a';
+ }
+ method b($x) {
+ $!in-b++;
+ $!calls ~= 'b';
+ }
+}
+
+ok A::Test::Grammar.parse('alpha beta'), 'basic sanity: .parse works';
+my $action = An::Action1.new();
+lives_ok { A::Test::Grammar.parse('alpha beta', :action($action)) },
+ 'parse with :action (and no make) lives';
+is $action.in-a, 1, 'first action has been called';
+is $action.in-b, 1, 'second action has been called';
+is $action.calls, 'ab', '... and in the right order';
+
+
+# vim: ft=perl6

0 comments on commit c1520ab

Please sign in to comment.