use v6-alpha; use Test; =pod This file was derived from the perl5 CPAN module Perl6::Rules, version 0.3 (12 Apr 2004), file t/der_grammar.t. It has (hopefully) been, and should continue to be, updated to be valid perl6. =cut plan 33; if !eval('("a" ~~ /a/)') { skip_rest "skipped tests - rules support appears to be missing"; } else { grammar Other { rule abc { a () c } rule bee { b } rule def { d f } rule eh { e } } grammar Another is Other { } grammar Yet::Another is Another { rule bee { B } rule def { D F } } # Test derivation and Liskov substitutability... ok('abc' ~~ m/^ () $/, '', :todo); is($/, "abc", 'abc $/', :todo); is($0, "abc", 'abc $0', :todo); ok('abc' ~~ m/ () /, '', :todo); is($/, "b", 'bee $/', :todo); is($0, "b", 'bee $0', :todo); ok('b' ~~ m/ () /, '', :todo); ok('def' ~~ m/^ () $/, '()', :todo); is($/, "def", 'def $/', :todo); is($0, "def", 'def $0', :todo); ok('def' ~~ m/^ $/, '', :todo); is($/, "def", '?def $/', :todo); ok($0 ne "def", '?def $0'); is($/, "def", '?def $/', :todo); is(eval('$/'), "e", '?def $/', :todo); # Test rederivation and polymorphism... ok(eval(q{'abc' ~~ m/^ () $/ }), '', :todo); is($/, "abc", 'abc $/', :todo); is($0, "abc", 'abc $0', :todo); ok(eval(q{!( 'abc' ~~ m/ () / ) }), 'abc '); ok(eval(q{'aBc' ~~ m/ () / }), 'aBc ', :todo); is($/, "B", 'Yet::Another::bee $/', :todo); is($0, "B", 'Yet::Another::bee $0', :todo); ok(eval(q{!( 'def' ~~ m/^ () $/ ) }), 'def ()'); ok(eval(q{'DeF' ~~ m/^ () $/ }), 'DeF ()', :todo); is($/, "DeF", 'DeF $/', :todo); is($0, "DeF", 'DeF $0', :todo); ok('DeF' ~~ m/^ $/, '', :todo); is($/, "DeF", '?Yet::Another.def $/', :todo); ok($0 ne "DeF", '?Yet::Another.def $0'); is($/, "DeF", '?def $/', :todo); is(eval('$/'), "e", '?def $/', :todo); # Non-existent rules... ok(!eval(q{ 'abc' ~~ m/ () / }), ''); is($!, 'Error', :todo); }