Skip to content

Commit

Permalink
LTM tests should use subparse
Browse files Browse the repository at this point in the history
  • Loading branch information
TimToady committed Mar 2, 2014
1 parent d626eb7 commit 9c0f7ec
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions S05-grammar/protoregex.t
Expand Up @@ -12,22 +12,22 @@ grammar Alts {
token alt:sym«=>» { <sym> }; # RT #113590
}

ok (my $match = Alts.parse('foo')), 'can parse with proto regexes (1)';
ok (my $match = Alts.subparse('foo')), 'can parse with proto regexes (1)';

is $match, 'foo', 'and matched the full string';
is $match<alt>, 'foo', 'got the right name of the capture';

is $/, 'foo', 'also works with $/';

ok Alts.parse('bar'), 'can parse with second alternative';
ok Alts.parse('argl'), 'can parse third second alternative';
ok Alts.subparse('bar'), 'can parse with second alternative';
ok Alts.subparse('argl'), 'can parse third second alternative';

ok !Alts.parse('baz'), 'does not match sym of third alternative';
ok !Alts.parse('aldkfj'), 'does not match completely unrelated string';
ok !Alts.parse(''), 'does not match empty string';
ok !Alts.subparse('baz'), 'does not match sym of third alternative';
ok !Alts.subparse('aldkfj'), 'does not match completely unrelated string';
ok !Alts.subparse(''), 'does not match empty string';

# RT #113590
ok Alts.parse('=>'), 'can parse symbol inside double-angles';
ok Alts.subparse('=>'), 'can parse symbol inside double-angles';


class SomeActions {
Expand All @@ -36,7 +36,7 @@ class SomeActions {
}
}

ok ($match = Alts.parse('argl', :actions(SomeActions.new))),
ok ($match = Alts.subparse('argl', :actions(SomeActions.new))),
'can parse with action methods';
is $match<alt>.ast, 'bazbaz', 'action method got called, make() worked';

Expand Down Expand Up @@ -104,21 +104,21 @@ grammar LTM {
token block:sym<b> { aa }
}

is ~LTM.parse('foobar', :rule('lit')), 'foobar', 'LTM picks longest literal';
is ~LTM.parse('1.2', :rule('cclass1')), '1.2', 'LTM picks longest with char classes';
is ~LTM.parse('1.2', :rule('cclass2')), '1.2', '...and it not just luck with ordering';
is ~LTM.parse('11', :rule('cclass3')), '11', 'LTM works with things like \d';
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.subparse('foobar', :rule('lit')), 'foobar', 'LTM picks longest literal';
is ~LTM.subparse('1.2', :rule('cclass1')), '1.2', 'LTM picks longest with char classes';
is ~LTM.subparse('1.2', :rule('cclass2')), '1.2', '...and it not just luck with ordering';
is ~LTM.subparse('11', :rule('cclass3')), '11', 'LTM works with things like \d';
is ~LTM.subparse('..', :rule('cclass4')), '..', '...and negated ones like \W';
is ~LTM.subparse('ab', :rule('quant1')), 'ab', 'LTM and ? quantifier';
is ~LTM.subparse('abbb', :rule('quant2')), 'abbb', 'LTM, ? and + quantifiers';
is ~LTM.subparse('aaaa', :rule('quant3')), 'aaaa', 'LTM and * quantifier';
is ~LTM.subparse('aaa', :rule('declok')), 'aaa', ':my declarations do not terminate LTM';
is ~LTM.subparse('aaa', :rule('cap1')), 'aaa', 'Positional captures do not terminate LTM';
is ~LTM.subparse('aaa', :rule('cap2')), 'aaa', 'Named captures do not terminate LTM';
is ~LTM.subparse('aaa', :rule('ass1')), 'aaa', '<?{...}> does not terminate LTM';
is ~LTM.subparse('aaa', :rule('ass2')), 'aaa', '<!{...}> does not terminate LTM';
#?niecza todo '#89'
is ~LTM.parse('aaa', :rule('block')), 'aa', 'However, code blocks do terminate LTM';
is ~LTM.subparse('aaa', :rule('block')), 'aa', 'However, code blocks do terminate LTM';

# RT120146
#?niecza skip "Action method assertion:sym<...> not yet implemented"
Expand All @@ -130,16 +130,16 @@ is ~LTM.parse('aaa', :rule('block')), 'aa', 'However, code blocks do termi
token ident {'-'?<nmstrt><nmreg>*}
token num {[\+|\-]?\d+}

proto token term { <...> }
proto token term {*}
token term:sym<ident> {<ident>}
token term:sym<num> {<num>}
}

is ~G.parse("-42", :rule<num>), '-42', 'num parse';
is ~G.parse("-my_id", :rule<ident>), '-my_id', 'id parse';
is ~G.parse("my_id", :rule<term>), 'my_id', 'term parse';
is ~G.subparse("-42", :rule<num>), '-42', 'num parse';
is ~G.subparse("-my_id", :rule<ident>), '-my_id', 'id parse';
is ~G.subparse("my_id", :rule<term>), 'my_id', 'term parse';
#?rakudo todo 'RT120146'
is ~G.parse("-my_id", :rule<term>), '-my_id', 'term parse, leading "-"';
is ~G.subparse("-my_id", :rule<term>), '-my_id', 'term parse, leading "-"';
}

# vim: ft=perl6

0 comments on commit 9c0f7ec

Please sign in to comment.