Skip to content

Commit

Permalink
Merge pull request #1 from pstuifzand/master
Browse files Browse the repository at this point in the history
Added testcases as actual test
  • Loading branch information
ruz committed Apr 10, 2012
2 parents c134e5a + 0260f56 commit 8311a72
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
3 changes: 2 additions & 1 deletion MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ inc/Module/Install/Metadata.pm
inc/Module/Install/ReadmeFromPod.pm
inc/Module/Install/Win32.pm
inc/Module/Install/WriteAll.pm
lib/Marpa/Simple/Lexer.pm
lib/MarpaX/Simple/Lexer.pm
t/test-cases.t
Makefile.PL
MANIFEST This list of files
META.yml
Expand Down
44 changes: 44 additions & 0 deletions t/test-cases.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use Test::More;
use Test::Exception;

use Marpa::XS;
use MarpaX::Simple::Lexer;
use IO::String;
use Data::Dumper;

sub X {
return 1;
}

my $grammar = Marpa::XS::Grammar->new( {
actions => 'main',
start => 'Parser',
rules => [
[ 'Parser' => [ 'X' ], 'X' ],
],
terminals => [qw/X/],
});

$grammar->precompute;

my @test_cases = (
[ {X => qr/X/}, "X" ],
[ {X => qr/XX/}, "XX" ],
);

for my $case (@test_cases) {
my $recognizer = Marpa::XS::Recognizer->new( { grammar => $grammar } );
my $lexer = MarpaX::Simple::Lexer->new(
recognizer => $recognizer,
tokens => $case->[0],
);

my $io = IO::String->new($case->[1]);
lives_ok {
$lexer->recognize($io);
};
is(${ $recognizer->value }, 1);
}

done_testing();

0 comments on commit 8311a72

Please sign in to comment.