perl6-docs
perl6-docs copied to clipboard
built-in subrule need update
<dot> <lt> <gt> <null> <sp>
is not built-in subrule
#!perl6
use Test;
my regex dot { '.' }
my regex lt { '<' }
my regex gt { '>' }
my regex null { <?> }
ok( '.' ~~ / <dot> /, '. match <dot>');
ok( '<' ~~ / <lt> /, '< match <lt>');
ok( '>' ~~ / <gt> /, '> match <gt>');
ok( '' ~~ / <null> /, 'blank str match <null>');
According to the text:
Perl 6 predeclares several useful named regex:
<alpha> a single alphabetic character <digit> a single numeric character <ident> an "identifier" <sp> a single space character <ws> an arbitrary amount of whitespace <dot> a period (same as '.') <lt> a less-than character (same as '<') <gt> a greater-than character (same as '>') <null> matches nothing (useful in alternations that may be empty)
Your tests don't prove that they aren't predeclared. For instance, examine the following code:
~/p6_programs$ perl6 -v
This is Rakudo version 2016.11 built on MoarVM version 2016.11
implementing Perl 6.c.
~/p6_programs$ cat 4.pl6
$_ = "One small step";
m/One<ws>small<ws>step/;
say $/;
my regex ws { "-" };
$_ = "One-small-step";
m/One<ws>small<ws>step/;
say $/;
~/p6_programs$ perl6 4.pl6
「One small step」
ws => 「 」
ws => 「 」
「One-small-step」
ws => 「-」
ws => 「-」
I redefined <ws>
, but as the output shows <ws>
was actually predeclared.
I think your tests would have to do something like the following:
use Test;
plan(4);
throws-like { "." ~~ /<dot>/ }, X::Method::NotFound, "Some method wasn't found in <dot> test";
throws-like { "<" ~~ /<lt>/ }, X::Method::NotFound, "Some method wasn't found in <lt> test";
throws-like { ">" ~~ /<gt>/ }, X::Method::NotFound, "Some method wasn't found in <gt> test";
throws-like { "" ~~ /<null>/}, X::Method::NotFound, "Some method wasn't found in <null> test";
~/p6_programs$ perl6 4.pl6
1..4
1..2
ok 1 - code dies
ok 2 - right exception type (X::Method::NotFound)
ok 1 - Some method wasn't found in <dot> test
1..2
ok 1 - code dies
ok 2 - right exception type (X::Method::NotFound)
ok 2 - Some method wasn't found in <lt> test
1..2
ok 1 - code dies
ok 2 - right exception type (X::Method::NotFound)
ok 3 - Some method wasn't found in <gt> test
1..2
ok 1 - code dies
ok 2 - right exception type (X::Method::NotFound)
ok 4 - Some method wasn't found in <null> test
Even those tests don't prove that <dot>
, etc. aren't available--because the exception could be coming from another method that is failing. I'm not sure how to test for the existence of a method.