The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!perl
# Marpa::R3 is Copyright (C) 2016, Jeffrey Kegler.
#
# This module is free software; you can redistribute it and/or modify it
# under the same terms as Perl 5.10.1. For more details, see the full text
# of the licenses in the directory LICENSES.
#
# This program is distributed in the hope that it will be
# useful, but it is provided “as is” and without any express
# or implied warranties. For details, see the full text of
# of the licenses in the directory LICENSES.

# CENSUS: ASIS
# Note: SLIF TEST

# Tests which require only grammar, input, and an output with no
# semantics -- usually just an AST

use 5.010001;
use strict;
use warnings;

use Test::More tests => 1;
use English qw( -no_match_vars );
use lib 'inc';
use Marpa::R3::Test;
use Marpa::R3;
use Data::Dumper;
use Getopt::Long ();

our $VERBOSE = 0;
die if not Getopt::Long::GetOptions( verbose => \$VERBOSE );

my $dsl = <<'=== END OF DSL ===';
:start ::= test
test ::= [\w] | [\W]
=== END OF DSL ===

my $input = "1\x{0A}2\x{0D}3\x{0D}\x{0A}4\x{85}5\x{0A}\x{0D}\x{0A}7"
  . ( "\x{0A}\x{0D}" x 4 ) #  5 lines -- 3 medial CRLF, plus 2 at ends
  . ( "\x{0D}" x 3 )  # 3 lines
  . "\x{85}" # 1 line
  . ( "\x{0A}" x 3 ) # 3 lines
  . ( "\x{0A}\x{0D}" x 4 ) #  5 lines -- 3 medial CRLF, plus 2 at ends
  . '24';
my $g = Marpa::R3::Scanless::G->new({source => \$dsl});
my $r = Marpa::R3::Scanless::R->new({grammar => $g});

# We do not need to actually read the input
$r->read(\$input, 0, 0);

my @actual = ();
for my $i (0 .. length $input) {
   my ($line, $column) = $r->line_column($i);
   if ($VERBOSE) {
   my $text = substr $input, $i, 20;
    $text =~ s/\n/\\n/g;
    $text =~ s/\r/\\r/g;
    say join " ", $line, $column, $text;
   }
   push @actual, join q{ }, $line, $column;
}
my $actual = join "\n", @actual, q{};

my $line_data = <<'END_OF_LINE_DATA';
1 1 1\n2\r3\r\n4�5\n\r\n7\n\r\n\r\n\r
1 2 \n2\r3\r\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r\n\r\n\r\n\r24
18 1 \n\n\r\n\r\n\r\n\r24
19 1 \n\r\n\r\n\r\n\r24
20 1 \r\n\r\n\r\n\r24
20 2 \n\r\n\r\n\r24
21 1 \r\n\r\n\r24
21 2 \n\r\n\r24
22 1 \r\n\r24
22 2 \n\r24
23 1 \r24
24 1 24
24 2 4
24 3 
END_OF_LINE_DATA

my @expected = ();
for my $line (split $RS, $line_data)
{
   chomp $line;
  $line =~ s/\A(\d+ \s+ \d+) \s .*\z/$1/xms;
  push @expected, $line;
}
my $expected = join "\n", @expected, q{};
Marpa::R3::Test::is($actual, $expected, "Line and column test");

# vim: expandtab shiftwidth=4: