Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 38 lines (30 sloc) 0.798 kb
c1520ab [t/spec] tests for action stubs in grammars
moritz authored
1 use v6;
2
3 use Test;
4 plan 5;
5
6 # TODO: needs specs and smartlinks
7
8 grammar A::Test::Grammar {
9 rule TOP { <a> <b> }
10 token a { 'a' \w+ {*} }
11 token b { 'b' \w+ {*} }
12 }
13
14 class An::Action1 {
15 has $.in-a = 0;
16 has $.in-b = 0;
17 has $.calls = '';
18 method a($/) {
19 $!in-a++;
20 $!calls ~= 'a';
21 }
22 method b($x) {
23 $!in-b++;
24 $!calls ~= 'b';
25 }
26 }
27
28 ok A::Test::Grammar.parse('alpha beta'), 'basic sanity: .parse works';
29 my $action = An::Action1.new();
30 lives_ok { A::Test::Grammar.parse('alpha beta', :action($action)) },
31 'parse with :action (and no make) lives';
32 is $action.in-a, 1, 'first action has been called';
33 is $action.in-b, 1, 'second action has been called';
34 is $action.calls, 'ab', '... and in the right order';
35
36
37 # vim: ft=perl6
Something went wrong with that request. Please try again.