Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 37 lines (32 sloc) 0.816 kB
cafd728 @moritz [lexer] rework lexer_test.pl into a proper Test::More test
authored
1 use strict;
2 use warnings;
3 use lib 'lib';
c16fb9f @moritz Renamed Mowyw to App::Mowyw
authored
4 use App::Mowyw::Lexer qw(lex);
cafd728 @moritz [lexer] rework lexer_test.pl into a proper Test::More test
authored
5 use Test::More tests => 13;
6
7 my @tokens = (
3430736 @moritz [lexer] fix pos() bug when callbacks changed the token length; retab
authored
8 ['Int', qr/(?:-|\+)?\d+/, sub { 2 * $_[0]}],
cafd728 @moritz [lexer] rework lexer_test.pl into a proper Test::More test
authored
9 ['Op', qr/\+|\*|-|\//],
10 ['Brace_Open', qr/\(/],
11 ['Brace_Close', qr/\)/],
12 ['Whitespace', qr/\s+/, sub { return undef; }],
13 );
3430736 @moritz [lexer] fix pos() bug when callbacks changed the token length; retab
authored
14
15 my $text = "12 + foo\n (3 * (60 + -1))BAR";
cafd728 @moritz [lexer] rework lexer_test.pl into a proper Test::More test
authored
16
17 my @expected = split /\n/, <<EXPECTED;
3430736 @moritz [lexer] fix pos() bug when callbacks changed the token length; retab
authored
18 Int: 24 (0; 1)
cafd728 @moritz [lexer] rework lexer_test.pl into a proper Test::More test
authored
19 Op: + (3; 1)
20 UNMATCHED: foo (4; 1)
21 Brace_Open: ( (10; 2)
3430736 @moritz [lexer] fix pos() bug when callbacks changed the token length; retab
authored
22 Int: 6 (11; 2)
cafd728 @moritz [lexer] rework lexer_test.pl into a proper Test::More test
authored
23 Op: * (13; 2)
24 Brace_Open: ( (15; 2)
3430736 @moritz [lexer] fix pos() bug when callbacks changed the token length; retab
authored
25 Int: 120 (16; 2)
26 Op: + (19; 2)
27 Int: -2 (21; 2)
cafd728 @moritz [lexer] rework lexer_test.pl into a proper Test::More test
authored
28 Brace_Close: ) (23; 2)
3430736 @moritz [lexer] fix pos() bug when callbacks changed the token length; retab
authored
29 Brace_Close: ) (24; 2)
30 UNMATCHED: BAR (25; 2)
cafd728 @moritz [lexer] rework lexer_test.pl into a proper Test::More test
authored
31 EXPECTED
32
33 for (lex($text, \@tokens)) {
34 my ($name, $matched, $pos, $line) = @$_;
35 is "$name: $matched ($pos; $line)", shift(@expected);
36 }
Something went wrong with that request. Please try again.