Debian Codegraph @

t/sl_amon.t

raw
1 #!/usr/bin/perl
2 # Copyright 2022 Jeffrey Kegler
3 # This file is part of Marpa::R2. Marpa::R2 is free software: you can
4 # redistribute it and/or modify it under the terms of the GNU Lesser
5 # General Public License as published by the Free Software Foundation,
6 # either version 3 of the License, or (at your option) any later version.
7 #
8 # Marpa::R2 is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser
14 # General Public License along with Marpa::R2. If not, see
15 # http://www.gnu.org/licenses/.
16
17 # Bug found by amon: duplicate events when mixing external
18 # and internal scanning.
19
20 use 5.010001;
21 use strict;
22 use warnings;
23 use English qw( -no_match_vars );
24 use Test::More tests => 2;
25
26 use lib 'inc';
27 use Marpa::R2::Test;
28
29 ## no critic (ErrorHandling::RequireCarping);
30
31 use Marpa::R2;
32
33 my $g = Marpa::R2::Scanless::G->new({
34 source => \q{
35 Top::= 'start' TOKEN OTHER_TOKEN
36 TOKEN ~ [^\s\S]
37 OTHER_TOKEN ~ [^\s\S]
38 event ev_token = predicted TOKEN
39 event ev_other_token = predicted OTHER_TOKEN
40 },
41 });
42 my $r = Marpa::R2::Scanless::R->new({ grammar => $g });
43
44 # This is the "control" -- a test before where the bug
45 # occurred, just to make sure the context is right.
46 $r->read(\"start_");
47 {
48 my @events = map { $_->[0] } @{ $r->events };
49 Test::More::is( (join q{ }, @events), q{ev_token}, 'before' );
50 }
51
52 # Now look where the bug occurred.
53 # The problem was that the "ev_token" from the previous
54 # check for events was not cleared.
55 $r->lexeme_read(TOKEN => 0, 1, "_");
56 {
57 my @events = map { $_->[0] } @{ $r->events };
58 # ev_token should NOT be reported here.
59 Test::More::is( (join q{ }, @events), q{ev_other_token}, 'after' );
60 }