Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

built-in subrule need update #3

Open
songzan opened this issue Dec 22, 2014 · 1 comment
Open

built-in subrule need update #3

songzan opened this issue Dec 22, 2014 · 1 comment

Comments

@songzan
Copy link

songzan commented Dec 22, 2014

<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>');
@7stud
Copy link

7stud commented Jan 7, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants