This repository has been archived by the owner on Feb 3, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[nqp]: Add some simple protoregex tests.
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#! nqp | ||
|
||
# test protoregexes in grammars | ||
|
||
plan(6); | ||
|
||
grammar ABC { | ||
|
||
token TOP { <symbols> .* } | ||
|
||
proto token symbols { <...> } | ||
|
||
token symbols:sym<abc> { <sym> } | ||
token symbols:sym<a> { <sym> } | ||
token symbols:sym<bang> { $<sym>=['!'] } | ||
token symbols:sym<===> { <sym> } | ||
} | ||
|
||
|
||
my $/ := ABC.parse('abcdef'); | ||
ok( ?$/ , 'successfully matched grammar' ); | ||
ok( $/ eq 'abcdef', 'successful string match' ); | ||
ok( $<symbols> eq 'abc', 'successful protoregex match'); | ||
ok( $<symbols><sym> eq 'abc', 'correct proto candidate match' ); | ||
|
||
$/ := ABC.parse('adef'); | ||
ok( ?$/ , 'successfully matched grammar' ); | ||
|
||
$/ := ABC.parse('xxx'); | ||
ok( !$/ , 'successfully failed protoregex match' ); | ||
|
||
|