Skip to content

Commit d626eb7

Browse files
committed
update parse and subparse tests to match spec
1 parent 4b5c5c9 commit d626eb7

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

S05-grammar/parse_and_parsefile.t

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
11
use v6;
22
use Test;
33

4-
plan 12;
4+
plan 14;
55

66
# tests .parse and .parsefile methods on a grammar
77

8-
grammar Foo {
9-
token TOP { \d+ };
10-
};
11-
grammar Bar {
12-
token untop { \d+ }
13-
}
8+
grammar Foo { token TOP { \d+ } }
9+
grammar Bar { token untop { \d+ } }
10+
grammar Baz { token TOP { \d+ \n } }
1411

1512
nok(~Foo.parse("abc123xyz"), ".parse method invokes TOP rule, no match");
1613
is(~Foo.parse("123"), "123", ".parse method invokes TOP rule, match");
14+
nok(Foo.parse("123xyz"), ".parse method requires match to end");
15+
is(~Foo.subparse("123xyz"), "123", ".subparse method doesn't require match to end");
1716
dies_ok({ Bar.parse("abc123xyz") }, "dies if no TOP rule");
1817

1918
my $fh = open("parse_and_parsefile_test", :w);
2019
$fh.say("abc\n123\nxyz");
2120
$fh.close();
2221
#?niecza skip 'Unable to resolve method parsefile in class Foo'
23-
nok(~Foo.parsefile("parse_and_parsefile_test"), ".parsefile method invokes TOP rule, no match");
22+
nok(Foo.parsefile("parse_and_parsefile_test"), ".parsefile method invokes TOP rule, no match");
2423
unlink("parse_and_parsefile_test");
2524

2625
$fh = open("parse_and_parsefile_test", :w);
2726
$fh.say("123");
2827
$fh.close();
2928
#?niecza skip 'Unable to resolve method parsefile in class Foo'
30-
is(~Foo.parsefile("parse_and_parsefile_test"), "123", ".parsefile method invokes TOP rule, match");
29+
is(~Baz.parsefile("parse_and_parsefile_test"), "123\n", ".parsefile method invokes TOP rule, match");
3130
dies_ok({ Bar.parsefile("parse_and_parsefile_test") }, "dies if no TOP rule");
3231
dies_ok({ Foo.parsefile("non_existent_file") }, "dies if file not found");
3332

@@ -36,7 +35,7 @@ unlink("parse_and_parsefile_test");
3635
grammar A::B {
3736
token TOP { \d+ }
3837
}
39-
nok(~A::B.parse("zzz42zzz"), ".parse works with namespaced grammars, no match");
38+
nok(A::B.parse("zzz42zzz"), ".parse works with namespaced grammars, no match");
4039
is(~A::B.parse("42"), "42", ".parse works with namespaced grammars, match");
4140

4241
# TODO: Check for a good error message, not just the absence of a bad one.
@@ -63,4 +62,4 @@ eval_dies_ok '::No::Such::Grammar.parse()', '.parse on missing grammar dies';
6362

6463
done;
6564

66-
# vim: ft=perl6
65+
# vim: ft=perl6 expandtab sw=4

0 commit comments

Comments
 (0)