Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Some more LTM tests for protoregexes.
  • Loading branch information
jnthn committed Nov 18, 2011
1 parent e3a23f0 commit 08133b6
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion S05-grammar/protoregex.t
@@ -1,6 +1,6 @@
use v6;
use Test;
plan 19;
plan 25;

grammar Alts {
token TOP { ^ <alt> $ };
Expand Down Expand Up @@ -72,6 +72,33 @@ grammar LTM {
proto token quant3 { * }
token quant3:sym<a> { aaa }
token quant3:sym<b> { a* }

proto token declok { <*> }
token declok:sym<a> {
:my $x := 42;
.+
}
token declok:sym<b> { aa }

proto token cap1 { <*> }
token cap1:sym<a> { (.+) }
token cap1:sym<b> { aa }

proto token cap2 { <*> }
token cap2:sym<a> { $<x>=[.+] }
token cap2:sym<b> { aa }

proto token ass1 { <*> }
token ass1:sym<a> { a <?{ 1 }> .+ }
token ass1:sym<b> { aa }

proto token ass2 { <*> }
token ass2:sym<a> { a <!{ 0 }> .+ }
token ass2:sym<b> { aa }

proto token block { <*> }
token block:sym<a> { a {} .+ }
token block:sym<b> { aa }
}

is ~LTM.parse('foobar', :rule('lit')), 'foobar', 'LTM picks longest literal';
Expand All @@ -82,5 +109,11 @@ is ~LTM.parse('..', :rule('cclass4')), '..', '...and negated ones like \W';
is ~LTM.parse('ab', :rule('quant1')), 'ab', 'LTM and ? quantifier';
is ~LTM.parse('abbb', :rule('quant2')), 'abbb', 'LTM, ? and + quantifiers';
is ~LTM.parse('aaaa', :rule('quant3')), 'aaaa', 'LTM and * quantifier';
is ~LTM.parse('aaa', :rule('declok')), 'aaa', ':my declarations do not terminate LTM';
is ~LTM.parse('aaa', :rule('cap1')), 'aaa', 'Positional captures do not terminate LTM';
is ~LTM.parse('aaa', :rule('cap2')), 'aaa', 'Named captures do not terminate LTM';
is ~LTM.parse('aaa', :rule('ass1')), 'aaa', '<?{...}> does not terminate LTM';
is ~LTM.parse('aaa', :rule('ass2')), 'aaa', '<!{...}> does not terminate LTM';
is ~LTM.parse('aaa', :rule('block')), 'aa', 'However, code blocks do terminate LTM';

# vim: ft=perl6

0 comments on commit 08133b6

Please sign in to comment.