| 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 |
# Regression test of problem with SvIOK() in Perl XS API |
| 18 |
|
| 19 |
use 5.010001; |
| 20 |
use strict; |
| 21 |
use warnings; |
| 22 |
|
| 23 |
use Test::More tests => 2; |
| 24 |
use English qw( -no_match_vars ); |
| 25 |
use lib 'inc'; |
| 26 |
use Marpa::R2::Test; |
| 27 |
use Marpa::R2; |
| 28 |
|
| 29 |
my $rules = <<'END_OF_GRAMMAR'; |
| 30 |
:default ::= action => [name, values] |
| 31 |
S ::= A A |
| 32 |
A ::= 'a' |
| 33 |
END_OF_GRAMMAR |
| 34 |
|
| 35 |
my $grammar = Marpa::R2::Scanless::G->new( { source => \$rules } ); |
| 36 |
|
| 37 |
my @actual_events; |
| 38 |
my $input = 'axxxa'; |
| 39 |
my $length = length $input; |
| 40 |
|
| 41 |
sub testIt { |
| 42 |
my ($recce) = @_; |
| 43 |
my $value_ref = $recce->value(); |
| 44 |
if ( not defined $value_ref ) { |
| 45 |
die "No parse\n"; |
| 46 |
} |
| 47 |
|
| 48 |
local $Data::Dumper::Deepcopy = 1; |
| 49 |
local $Data::Dumper::Terse = 1; |
| 50 |
my $actual_value = Data::Dumper::Dumper($value_ref); |
| 51 |
my $expected = |
| 52 |
Data::Dumper::Dumper( \[ 'S', [ 'A', 'a' ], [ 'A', 'a' ] ] ); |
| 53 |
|
| 54 |
Test::More::is( $actual_value, $expected, qq{Value for "$input"} ); |
| 55 |
|
| 56 |
} |
| 57 |
|
| 58 |
# Test::More::diag( "Marpa::R2 file: ", $INC{'Marpa/R2.pm'} ); |
| 59 |
# Test::More::diag( "Marpa::R2 version: ", $Marpa::R2::VERSION ); |
| 60 |
# Test::More::diag( "Perl version $^V" ); |
| 61 |
|
| 62 |
# Need to repeat code here because I am trying to preserve |
| 63 |
# the internal flags in $resumePos, and I do not want to |
| 64 |
# pass it out of a function. |
| 65 |
|
| 66 |
# === Bare $resume_pos |
| 67 |
|
| 68 |
TEST: { |
| 69 |
my $recce = Marpa::R2::Scanless::R->new( { grammar => $grammar } ); |
| 70 |
my $pos = $recce->read( \$input, 0, 1 ); |
| 71 |
pos $input = 1; |
| 72 |
$input =~ /\Gx+/; |
| 73 |
my $resumePos = $LAST_MATCH_END[0]; |
| 74 |
my $ok = eval { $recce->resume( $resumePos ); 1 }; |
| 75 |
if (not $ok) { |
| 76 |
diag($EVAL_ERROR); |
| 77 |
Test::More::fail('Bare integer test: no parse'); |
| 78 |
last TEST; |
| 79 |
} |
| 80 |
testIt($recce); |
| 81 |
} |
| 82 |
|
| 83 |
# === int($resume_pos) |
| 84 |
|
| 85 |
TEST: { |
| 86 |
my $recce = Marpa::R2::Scanless::R->new( { grammar => $grammar } ); |
| 87 |
my $pos = $recce->read( \$input, 0, 1 ); |
| 88 |
pos $input = 1; |
| 89 |
$input =~ /\Gx+/; |
| 90 |
my $resumePos = $LAST_MATCH_END[0]; |
| 91 |
# Test::More::diag("$^V resume pos: $resumePos"); |
| 92 |
my $ok = eval { $recce->resume( int($resumePos) ); 1 }; |
| 93 |
if (not $ok) { |
| 94 |
diag($EVAL_ERROR); |
| 95 |
Test::More::fail('int() output test: no parse'); |
| 96 |
last TEST; |
| 97 |
} |
| 98 |
testIt($recce); |
| 99 |
} |
| 100 |
|
| 101 |
# vim: expandtab shiftwidth=4: |