Debian Codegraph @

t/sl_lc.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 # Tests which require only grammar, input, and an output with no
18 # semantics -- usually just an AST
19
20 use 5.010001;
21 use strict;
22 use warnings;
23
24 use Test::More tests => 1;
25 use English qw( -no_match_vars );
26 use lib 'inc';
27 use Marpa::R2::Test;
28 use Marpa::R2;
29 use Data::Dumper;
30 use Getopt::Long ();
31
32 our $VERBOSE = 0;
33 die if not Getopt::Long::GetOptions( verbose => \$VERBOSE );
34
35 my $dsl = <<'=== END OF DSL ===';
36 :start ::= test
37 test ::= [\w] | [\W]
38 === END OF DSL ===
39
40 my $input = "1\x{0A}2\x{0D}3\x{0D}\x{0A}4\x{85}5\x{0A}\x{0D}\x{0A}7"
41 . ( "\x{0A}\x{0D}" x 4 ) # 5 lines -- 3 medial CRLF, plus 2 at ends
42 . ( "\x{0D}" x 3 ) # 3 lines
43 . "\x{85}" # 1 line
44 . ( "\x{0A}" x 3 ) # 3 lines
45 . ( "\x{0A}\x{0D}" x 4 ) # 5 lines -- 3 medial CRLF, plus 2 at ends
46 . '24';
47 my $g = Marpa::R2::Scanless::G->new({source => \$dsl});
48 my $r = Marpa::R2::Scanless::R->new({grammar => $g});
49
50 # We do not need to actually read the input
51 $r->read(\$input, 0, 0);
52
53 my @actual = ();
54 for my $i (0 .. length $input) {
55 my ($line, $column) = $r->line_column($i);
56 if ($VERBOSE) {
57 my $text = substr $input, $i, 20;
58 $text =~ s/\n/\\n/g;
59 $text =~ s/\r/\\r/g;
60 say join " ", $line, $column, $text;
61 }
62 push @actual, join q{ }, $line, $column;
63 }
64 my $actual = join "\n", @actual, q{};
65
66 my @expected = ();
67 for my $line (<DATA>)
68 {
69 chomp $line;
70 $line =~ s/\A(\d+ \s+ \d+) \s .*\z/$1/xms;
71 push @expected, $line;
72 }
73 my $expected = join "\n", @expected, q{};
74 Marpa::R2::Test::is($actual, $expected, "Line and column test");
75
76 __DATA__
77 1 1 1\n2\r3\r\n4�5\n\r\n7\n\r\n\r\n\r
78 1 2 \n2\r3\r\n4�5\n\r\n7\n\r\n\r\n\r\n
79 2 1 2\r3\r\n4�5\n\r\n7\n\r\n\r\n\r\n\r
80 2 2 \r3\r\n4�5\n\r\n7\n\r\n\r\n\r\n\r\r
81 3 1 3\r\n4�5\n\r\n7\n\r\n\r\n\r\n\r\r\r
82 3 2 \r\n4�5\n\r\n7\n\r\n\r\n\r\n\r\r\r\r
83 3 3 \n4�5\n\r\n7\n\r\n\r\n\r\n\r\r\r\r�
84 4 1 4�5\n\r\n7\n\r\n\r\n\r\n\r\r\r\r�\n
85 4 2 �5\n\r\n7\n\r\n\r\n\r\n\r\r\r\r�\n\n
86 5 1 5\n\r\n7\n\r\n\r\n\r\n\r\r\r\r�\n\n\n
87 5 2 \n\r\n7\n\r\n\r\n\r\n\r\r\r\r�\n\n\n\n
88 6 1 \r\n7\n\r\n\r\n\r\n\r\r\r\r�\n\n\n\n\r
89 6 2 \n7\n\r\n\r\n\r\n\r\r\r\r�\n\n\n\n\r\n
90 7 1 7\n\r\n\r\n\r\n\r\r\r\r�\n\n\n\n\r\n\r
91 7 2 \n\r\n\r\n\r\n\r\r\r\r�\n\n\n\n\r\n\r\n
92 8 1 \r\n\r\n\r\n\r\r\r\r�\n\n\n\n\r\n\r\n\r
93 8 2 \n\r\n\r\n\r\r\r\r�\n\n\n\n\r\n\r\n\r\n
94 9 1 \r\n\r\n\r\r\r\r�\n\n\n\n\r\n\r\n\r\n\r
95 9 2 \n\r\n\r\r\r\r�\n\n\n\n\r\n\r\n\r\n\r2
96 10 1 \r\n\r\r\r\r�\n\n\n\n\r\n\r\n\r\n\r24
97 10 2 \n\r\r\r\r�\n\n\n\n\r\n\r\n\r\n\r24
98 11 1 \r\r\r\r�\n\n\n\n\r\n\r\n\r\n\r24
99 12 1 \r\r\r�\n\n\n\n\r\n\r\n\r\n\r24
100 13 1 \r\r�\n\n\n\n\r\n\r\n\r\n\r24
101 14 1 \r�\n\n\n\n\r\n\r\n\r\n\r24
102 15 1 �\n\n\n\n\r\n\r\n\r\n\r24
103 16 1 \n\n\n\n\r\n\r\n\r\n\r24
104 17 1 \n\n\n\r\n\r\n\r\n\r24
105 18 1 \n\n\r\n\r\n\r\n\r24
106 19 1 \n\r\n\r\n\r\n\r24
107 20 1 \r\n\r\n\r\n\r24
108 20 2 \n\r\n\r\n\r24
109 21 1 \r\n\r\n\r24
110 21 2 \n\r\n\r24
111 22 1 \r\n\r24
112 22 2 \n\r24
113 23 1 \r24
114 24 1 24
115 24 2 4
116 24 3