Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add a very basic test for our NFA matcher.
  • Loading branch information
pmurias committed Jul 24, 2013
1 parent 06c4835 commit 9e2d04c
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions t/nqp/74-nfa.t
@@ -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");
}



0 comments on commit 9e2d04c

Please sign in to comment.