Browse files

update parse and subparse tests to match spec

  • Loading branch information...
1 parent 4b5c5c9 commit d626eb7548bbd52010baa341855bac969cf47831 @TimToady TimToady committed Mar 2, 2014
Showing with 10 additions and 11 deletions.
  1. +10 −11 S05-grammar/parse_and_parsefile.t
View
21 S05-grammar/parse_and_parsefile.t
@@ -1,33 +1,32 @@
use v6;
use Test;
-plan 12;
+plan 14;
# tests .parse and .parsefile methods on a grammar
-grammar Foo {
- token TOP { \d+ };
-};
-grammar Bar {
- token untop { \d+ }
-}
+grammar Foo { token TOP { \d+ } }
+grammar Bar { token untop { \d+ } }
+grammar Baz { token TOP { \d+ \n } }
nok(~Foo.parse("abc123xyz"), ".parse method invokes TOP rule, no match");
is(~Foo.parse("123"), "123", ".parse method invokes TOP rule, match");
+nok(Foo.parse("123xyz"), ".parse method requires match to end");
+is(~Foo.subparse("123xyz"), "123", ".subparse method doesn't require match to end");
dies_ok({ Bar.parse("abc123xyz") }, "dies if no TOP rule");
my $fh = open("parse_and_parsefile_test", :w);
$fh.say("abc\n123\nxyz");
$fh.close();
#?niecza skip 'Unable to resolve method parsefile in class Foo'
-nok(~Foo.parsefile("parse_and_parsefile_test"), ".parsefile method invokes TOP rule, no match");
+nok(Foo.parsefile("parse_and_parsefile_test"), ".parsefile method invokes TOP rule, no match");
unlink("parse_and_parsefile_test");
$fh = open("parse_and_parsefile_test", :w);
$fh.say("123");
$fh.close();
#?niecza skip 'Unable to resolve method parsefile in class Foo'
-is(~Foo.parsefile("parse_and_parsefile_test"), "123", ".parsefile method invokes TOP rule, match");
+is(~Baz.parsefile("parse_and_parsefile_test"), "123\n", ".parsefile method invokes TOP rule, match");
dies_ok({ Bar.parsefile("parse_and_parsefile_test") }, "dies if no TOP rule");
dies_ok({ Foo.parsefile("non_existent_file") }, "dies if file not found");
@@ -36,7 +35,7 @@ unlink("parse_and_parsefile_test");
grammar A::B {
token TOP { \d+ }
}
-nok(~A::B.parse("zzz42zzz"), ".parse works with namespaced grammars, no match");
+nok(A::B.parse("zzz42zzz"), ".parse works with namespaced grammars, no match");
is(~A::B.parse("42"), "42", ".parse works with namespaced grammars, match");
# 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';
done;
-# vim: ft=perl6
+# vim: ft=perl6 expandtab sw=4

0 comments on commit d626eb7

Please sign in to comment.