Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add a very basic test for our NFA matcher.
- Loading branch information
Showing
1 changed file
with
40 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,40 @@ | ||
| plan(7); | ||
|
|
||
| my knowhow NFAType is repr('NFA') { } | ||
|
|
||
| my $EDGE_FATE := 0; | ||
| my $EDGE_EPSILON := 1; | ||
| my $EDGE_CODEPOINT := 2; | ||
| my $EDGE_CODEPOINT_NEG := 3; | ||
| my $EDGE_CHARCLASS := 4; | ||
| my $EDGE_CHARCLASS_NEG := 5; | ||
| my $EDGE_CHARLIST := 6; | ||
| my $EDGE_CHARLIST_NEG := 7; | ||
| my $EDGE_SUBRULE := 8; | ||
| my $EDGE_CODEPOINT_I := 9; | ||
| my $EDGE_CODEPOINT_I_NEG := 10; | ||
| my $EDGE_GENERIC_VAR := 11; | ||
|
|
||
| my $empty := nqp::nfafromstatelist([[],[]],NFAType); | ||
| ok(nqp::istype($empty,NFAType),"nfafromstatelist creates an object of the right type"); | ||
| my $empty_fates := nqp::nfarunproto($empty,"foo",0); | ||
| ok(nqp::elems($empty_fates) == 0,"an empty nfa matches no fates"); | ||
|
|
||
| { | ||
| # the target state of a FATE transition is ignore so we can pass anything | ||
| my $simple := nqp::nfafromstatelist([[11],[$EDGE_CODEPOINT,102,2],[$EDGE_CODEPOINT,111,3],[$EDGE_CODEPOINT,111,4],[$EDGE_FATE,11,666]],NFAType); | ||
|
|
||
| my $matching := nqp::nfarunproto($simple,"foo",0); | ||
| ok(nqp::elems($matching) == 1,"we can match a simple string"); | ||
| ok($matching[0] == 11,"...and we get the right fate"); | ||
|
|
||
| my $not_matching := nqp::nfarunproto($simple,"barfoo",0); | ||
| ok(nqp::elems($not_matching) == 0,"we don't match what we shouldn't"); | ||
|
|
||
| my $matching_at_specified_pos := nqp::nfarunproto($simple,"barfoo",3); | ||
| ok(nqp::elems($matching_at_specified_pos) == 1,"we match at the right position"); | ||
| ok($matching_at_specified_pos[0] == 11,"...and we get the right fate"); | ||
| } | ||
|
|
||
|
|
||
|
|