Skip to content
Newer
Older
100644 81 lines (63 sloc) 3.15 KB
ede2bad [t/spec] add tests for grammars and inheritance, patch courtesy by pe…
moritz authored
1 use v6;
2 use Test;
3
74bedac @jdv Tests for RT #77350.
jdv authored
4 plan 32;
ede2bad [t/spec] add tests for grammars and inheritance, patch courtesy by pe…
moritz authored
5
288e046 [t] and [t/spec]
moritz authored
6 # L<S05/Grammars/"Like classes, grammars can inherit">
7
ede2bad [t/spec] add tests for grammars and inheritance, patch courtesy by pe…
moritz authored
8 # tests namespace, inheritance and override
9
10 grammar Grammar::Foo {
1d35860 [t/spec] more grammar inheritance tests, and fudge for rakudo
moritz authored
11 token TOP { <foo> };
ede2bad [t/spec] add tests for grammars and inheritance, patch courtesy by pe…
moritz authored
12 token foo { 'foo' };
74bedac @jdv Tests for RT #77350.
jdv authored
13 token so { 'so' };
ede2bad [t/spec] add tests for grammars and inheritance, patch courtesy by pe…
moritz authored
14 };
15
74bedac @jdv Tests for RT #77350.
jdv authored
16 #?rakudo todo 'RT #77350'
17 is( try { Grammar::Foo.parse( 'so', :rule<so> ) }, 'so',
18 "don't let a Mu based action method fail the parse" );
19
4363cc3 @colomon Fudge for niecza.
colomon authored
20 #?niecza skip 'Cannot dispatch to a method on Foo because it is not inherited or done by Cursor'
1af085a [t/spec]
moritz authored
21 is(~('foo' ~~ /^<Grammar::Foo::foo>$/), 'foo', 'got right match (foo)');
134127c @colomon Add tests so that we're actually testing inheritance on the current v…
colomon authored
22 ok Grammar::Foo.parse('foo'), 'got the right match through .parse TOP';
23 ok Grammar::Foo.parse('foo', :rule<foo>), 'got the right match through .parse foo';
ede2bad [t/spec] add tests for grammars and inheritance, patch courtesy by pe…
moritz authored
24
25 grammar Grammar::Bar is Grammar::Foo {
1d35860 [t/spec] more grammar inheritance tests, and fudge for rakudo
moritz authored
26 token TOP { <any> };
ede2bad [t/spec] add tests for grammars and inheritance, patch courtesy by pe…
moritz authored
27 token bar { 'bar' };
28 token any { <foo> | <bar> };
29 };
30
bb0a8fa @lizmat Use isa-ok instead of isa_ok
lizmat authored
31 isa-ok Grammar::Foo, Grammar, 'grammar isa Grammar';
32 isa-ok Grammar::Bar, Grammar, 'inherited grammar still isa Grammar';
33 isa-ok Grammar::Bar, Grammar::Foo, 'child isa parent';
1d35860 [t/spec] more grammar inheritance tests, and fudge for rakudo
moritz authored
34
134127c @colomon Add tests so that we're actually testing inheritance on the current v…
colomon authored
35 #?niecza 4 skip 'Cannot dispatch to a method on Bar because it is not inherited or done by Cursor'
1af085a [t/spec]
moritz authored
36 is(~('bar' ~~ /^<Grammar::Bar::bar>$/), 'bar', 'got right match (bar)');
37 is(~('foo' ~~ /^<Grammar::Bar::foo>$/), 'foo', 'got right match (foo)');
38 is(~('foo' ~~ /^<Grammar::Bar::any>$/), 'foo', 'got right match (any)');
39 is(~('bar' ~~ /^<Grammar::Bar::any>$/), 'bar', 'got right match (any)');
ede2bad [t/spec] add tests for grammars and inheritance, patch courtesy by pe…
moritz authored
40
7759c2d @Util Fix typos.
Util authored
41 ok Grammar::Bar.parse('foo'), 'can parse foo through .parsed and inherited subrule';
134127c @colomon Add tests so that we're actually testing inheritance on the current v…
colomon authored
42 ok Grammar::Bar.parse('bar', :rule<bar>), 'got right match (bar)';
fe0dfd6 @moritz refudge file for rakudo
moritz authored
43 ok Grammar::Bar.parse('foo', :rule<foo>), 'got right match (foo)';
134127c @colomon Add tests so that we're actually testing inheritance on the current v…
colomon authored
44 ok Grammar::Bar.parse('bar', :rule<any>), 'got right match (any)';
45 ok Grammar::Bar.parse('foo', :rule<any>), 'got right match (any)';
46 nok Grammar::Bar.parse('boo', :rule<any>), 'No match for bad input (any)';
47
ede2bad [t/spec] add tests for grammars and inheritance, patch courtesy by pe…
moritz authored
48 grammar Grammar::Baz is Grammar::Bar {
49 token baz { 'baz' };
50 token any { <foo> | <bar> | <baz> };
51 };
52
4363cc3 @colomon Fudge for niecza.
colomon authored
53 #?niecza 6 skip 'Cannot dispatch to a method on Baz because it is not inherited or done by Cursor'
cd1cc24 [t/spec] fix anchors in grammars + inheritance test, peters++
moritz authored
54 is(~('baz' ~~ /^<Grammar::Baz::baz>$/), 'baz', 'got right match');
55 is(~('foo' ~~ /^<Grammar::Baz::foo>$/), 'foo', 'got right match');
56 is(~('bar' ~~ /^<Grammar::Baz::bar>$/), 'bar', 'got right match');
57 is(~('foo' ~~ /^<Grammar::Baz::any>$/), 'foo', 'got right match');
58 is(~('bar' ~~ /^<Grammar::Baz::any>$/), 'bar', 'got right match');
59 is(~('baz' ~~ /^<Grammar::Baz::any>$/), 'baz', 'got right match');
ede2bad [t/spec] add tests for grammars and inheritance, patch courtesy by pe…
moritz authored
60
134127c @colomon Add tests so that we're actually testing inheritance on the current v…
colomon authored
61 ok Grammar::Baz.parse('baz', :rule<baz>), 'got right match (baz)';
62 ok Grammar::Baz.parse('foo', :rule<foo>), 'got right match (foo)';
63 ok Grammar::Baz.parse('bar', :rule<bar>), 'got right match (bar)';
64 ok Grammar::Baz.parse('baz', :rule<any>), 'got right match (any)';
65 ok Grammar::Baz.parse('foo', :rule<any>), 'got right match (any)';
66 ok Grammar::Baz.parse('bar', :rule<any>), 'got right match (any)';
67 nok Grammar::Baz.parse('boo', :rule<any>), 'No match for bad input (any)';
68
1d35860 [t/spec] more grammar inheritance tests, and fudge for rakudo
moritz authored
69 {
70 class A { };
71 grammar B is A { };
e20ead4 @moritz fudge a grammar test
moritz authored
72 #?rakudo todo 'automatic Grammar superclass'
4363cc3 @colomon Fudge for niecza.
colomon authored
73 #?niecza todo 'automatic Grammar superclass'
bb0a8fa @lizmat Use isa-ok instead of isa_ok
lizmat authored
74 isa-ok B, Grammar, 'A grammar isa Grammar, even if inherting from a class';
1d35860 [t/spec] more grammar inheritance tests, and fudge for rakudo
moritz authored
75
76 }
77
bebc699 @moritz switch from Type() to (Type) (work in progress)
moritz authored
78 is(Grammar.WHAT.gist,"(Grammar)", "Grammar.WHAT.gist = Grammar()");
1d35860 [t/spec] more grammar inheritance tests, and fudge for rakudo
moritz authored
79
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
80 # vim: ft=perl6
Something went wrong with that request. Please try again.