Debian Codegraph @

t/naif.t

raw
1 #!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 use 5.010001;
18
19 # Small NAIF tests
20
21 use strict;
22 use warnings;
23
24 use Test::More tests => 1;
25 use lib 'inc';
26 use Marpa::R2::Test;
27 use Marpa::R2;
28 use Data::Dumper;
29
30 my $grammar = Marpa::R2::Grammar->new( {
31 start => 'start',
32 actions => 'main',
33 default_action => 'My_Actions::dwim',
34 rules => [
35 [ start => [qw/x y/] ],
36 ],
37 } );
38
39 $grammar->precompute;
40 my $rec = Marpa::R2::Recognizer->new( { grammar => $grammar } );
41
42 $rec->alternative('x',\undef, 1);
43 $rec->earleme_complete;
44 $rec->alternative('y',\"some", 1);
45 $rec->earleme_complete;
46
47 my $value_ref = $rec->value();
48 die if not defined $value_ref;
49
50 Test::More::is_deeply(
51 ${$value_ref},
52 [ undef, 'some' ],
53 "Regression test of ref to undef as toke value"
54 );
55
56 sub My_Actions::dwim {
57 shift;
58 return $_[0] if scalar @_ == 1;
59 return [@_];
60 }
61
62 # vim: expandtab shiftwidth=4: