1
1
use v6 ;
2
2
use Test ;
3
3
4
- plan 12 ;
4
+ plan 14 ;
5
5
6
6
# tests .parse and .parsefile methods on a grammar
7
7
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 } }
14
11
15
12
nok (~ Foo. parse(" abc123xyz" ), " .parse method invokes TOP rule, no match" );
16
13
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" );
17
16
dies_ok({ Bar. parse(" abc123xyz" ) }, " dies if no TOP rule" );
18
17
19
18
my $ fh = open (" parse_and_parsefile_test" , : w);
20
19
$ fh . say (" abc\n 123\n xyz" );
21
20
$ fh . close ();
22
21
# ?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" );
24
23
unlink (" parse_and_parsefile_test" );
25
24
26
25
$ fh = open (" parse_and_parsefile_test" , : w);
27
26
$ fh . say (" 123" );
28
27
$ fh . close ();
29
28
# ?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" );
31
30
dies_ok({ Bar. parsefile(" parse_and_parsefile_test" ) }, " dies if no TOP rule" );
32
31
dies_ok({ Foo. parsefile(" non_existent_file" ) }, " dies if file not found" );
33
32
@@ -36,7 +35,7 @@ unlink("parse_and_parsefile_test");
36
35
grammar A::B {
37
36
token TOP { \d + }
38
37
}
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" );
40
39
is (~ A::B. parse(" 42" ), " 42" , " .parse works with namespaced grammars, match" );
41
40
42
41
# 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';
63
62
64
63
done ;
65
64
66
- # vim: ft=perl6
65
+ # vim: ft=perl6 expandtab sw=4
0 commit comments