Skip to content

Commit

Permalink
[t/spec] more grammar inheritance tests, and fudge for rakudo
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.pugscode.org/pugs@32079 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information
moritz committed Aug 21, 2010
1 parent 2562fbd commit 1d35860
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion S05-grammar/inheritance.t
@@ -1,26 +1,38 @@
use v6;
use Test;

plan 11;
plan *;

# L<S05/Grammars/"Like classes, grammars can inherit">

# tests namespace, inheritance and override

grammar Grammar::Foo {
token TOP { <foo> };
token foo { 'foo' };
};

#?rakudo skip '<a::b>'
is(~('foo' ~~ /^<Grammar::Foo::foo>$/), 'foo', 'got right match (foo)');
is ~Grammar::Foo.parse('foo'), 'foo', 'got the right match through .parse';

grammar Grammar::Bar is Grammar::Foo {
token TOP { <any> };
token bar { 'bar' };
token any { <foo> | <bar> };
};

isa_ok Grammar::Foo, Grammar, 'grammar isa Grammar';
isa_ok Grammar::Bar, Grammar, 'inherited grammar still isa Grammar';
isa_ok Grammar::Bar, Grammar::Foo, 'child isa parent';

#?rakudo skip '<a::b>'
is(~('bar' ~~ /^<Grammar::Bar::bar>$/), 'bar', 'got right match (bar)');
#?rakudo skip 'directly calling inherited grammar rule (RT 65474)'
is(~('foo' ~~ /^<Grammar::Bar::foo>$/), 'foo', 'got right match (foo)');
#?rakudo skip 'RT 77350'
ok Grammar::Bar.parse('foo'), 'can parse foo through .parsed and inhertied subrule';
#?rakudo 2 skip '<a::b>'
is(~('foo' ~~ /^<Grammar::Bar::any>$/), 'foo', 'got right match (any)');
is(~('bar' ~~ /^<Grammar::Bar::any>$/), 'bar', 'got right match (any)');

Expand All @@ -29,13 +41,24 @@ grammar Grammar::Baz is Grammar::Bar {
token any { <foo> | <bar> | <baz> };
};

#?rakudo skip '<a::b>'
is(~('baz' ~~ /^<Grammar::Baz::baz>$/), 'baz', 'got right match');
#?rakudo 2 skip 'calling inherited grammar rule'
is(~('foo' ~~ /^<Grammar::Baz::foo>$/), 'foo', 'got right match');
#?rakudo 4 skip '<a::b>'
is(~('bar' ~~ /^<Grammar::Baz::bar>$/), 'bar', 'got right match');
is(~('foo' ~~ /^<Grammar::Baz::any>$/), 'foo', 'got right match');
is(~('bar' ~~ /^<Grammar::Baz::any>$/), 'bar', 'got right match');
is(~('baz' ~~ /^<Grammar::Baz::any>$/), 'baz', 'got right match');

{
class A { };
grammar B is A { };
isa_ok B, Grammar, 'A grammar isa Grammar, even if inherting from a class';

}


done_testing;

# vim: ft=perl6

0 comments on commit 1d35860

Please sign in to comment.