Debian Codegraph @

html/t/config.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 use strict;
19 use warnings;
20 use Carp;
21 use Data::Dumper;
22 use English qw( -no_match_vars );
23 use Fatal qw(open close);
24 use Test::More;
25 use lib 'config';
26 use lib 'html/lib';
27 use Marpa::R2::Test;
28
29 BEGIN {
30 use lib 'html/tool/lib';
31 my $eval_result = eval { require Marpa::R2::HTML::Test::Util; 1 };
32 if ( !$eval_result ) {
33 Test::More::plan tests => 1;
34 Test::More::fail(
35 "Could not load Marpa::R2::HTML::Test::Util; $EVAL_ERROR");
36 exit 0;
37 } ## end if ( !$eval_result )
38 } ## end BEGIN
39
40 BEGIN { Marpa::R2::HTML::Test::Util::load_or_skip_all('HTML::Parser'); }
41
42 BEGIN { Test::More::plan tests => 2; }
43
44 use Marpa::R2::HTML;
45 use Marpa::R2::HTML::Config::Default;
46
47 my $current_file = do {
48 my $filename = $INC{'Marpa/R2/HTML/Config/Default.pm'};
49 open my $fh, q{<}, $filename;
50 join q{}, <$fh>;
51 };
52
53 my $short_round_trip_file = do {
54 my $short_round_trip_ref =
55 Marpa::R2::HTML::html( \"hi", \{ dump_config => 1 } );
56 die "No parse" if not ref $short_round_trip_ref;
57 ${$short_round_trip_ref};
58 };
59
60 my $long_round_trip_file = do {
61 open my $source_fh, q{<}, 'g/config/default.txt';
62 my $source_file = join q{}, <$source_fh>;
63 close $source_fh;
64 my $long_round_trip_ref =
65 Marpa::R2::HTML::html( \"hi", \{ compile => \$source_file, dump_config => 1 } );
66 die "No parse" if not ref $long_round_trip_ref;
67 ${$long_round_trip_ref};
68 };
69
70 my $datestamp_re = qr/ ^ \s* [#] \s+ The \s+ date \s+ of \s+ generation \s+ was [^\n]* /xms;
71 $current_file =~ s/$datestamp_re/[ DATESTAMP ]/xms;
72 $short_round_trip_file =~ s/$datestamp_re/[ DATESTAMP ]/xms;
73 $long_round_trip_file =~ s/$datestamp_re/[ DATESTAMP ]/xms;
74
75 Marpa::R2::Test::is( $short_round_trip_file, $current_file, 'Default config, short round trip' );
76 Marpa::R2::Test::is( $long_round_trip_file, $current_file, 'Default config, long round trip' );