Debian Codegraph @

html/t/missing.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
21 # Documented methods and argspecs which had no
22 # tests as of Sep 2012
23
24 use English qw( -no_match_vars );
25 use List::Util;
26 use Test::More;
27
28 BEGIN {
29 use lib 'html/tool/lib';
30 my $eval_result = eval { require Marpa::R2::HTML::Test::Util; 1 };
31 if ( !$eval_result ) {
32 Test::More::plan tests => 1;
33 Test::More::fail(
34 "Could not load Marpa::R2::HTML::Test::Util; $EVAL_ERROR");
35 exit 0;
36 } ## end if ( !$eval_result )
37 } ## end BEGIN
38
39 BEGIN { Marpa::R2::HTML::Test::Util::load_or_skip_all('HTML::Parser'); }
40
41 BEGIN { Test::More::plan tests => 1; }
42
43 use Marpa::R2::HTML;
44 use lib 'tool/lib';
45 use Marpa::R2::Test;
46
47 my $html = <<'END_OF_HTML';
48 <h1 title="h1_title">Header with title attribute</h2>
49 <p title="p_title">Graf with title attribute
50 <span title="span_title">Div with title attribute</span>
51 stuff
52 </p>
53 <!-- A comment -->
54 <div title="div_title">Div with title attribute</div>
55 END_OF_HTML
56
57 sub handler {
58 my $offset = Marpa::R2::HTML::offset() // q{-};
59 my $title = Marpa::R2::HTML::title() // q{-};
60 my $element = Marpa::R2::HTML::tagname();
61 my $description =
62 qq{element "$element", titled "$title", at offset $offset};
63 return join "\n", @{ Marpa::R2::HTML::values() }, $description;
64 } ## end sub handler
65
66 my $result_ref = Marpa::R2::HTML::html( \$html, { q{*} => \&handler } );
67 my $result = ref $result_ref ? ${$result_ref} : 'Parse failed';
68 $result .= "\n";
69
70 my $expected_result = <<'END_OF_TEXT';
71 element "head", titled "-", at offset -
72 element "h1", titled "h1_title", at offset 0
73 element "span", titled "span_title", at offset 99
74 element "p", titled "p_title", at offset 54
75 element "div", titled "div_title", at offset 186
76 element "body", titled "-", at offset 0
77 element "html", titled "-", at offset 0
78 END_OF_TEXT
79
80 Marpa::R2::Test::is( $result, $expected_result, qq{"missing" features test} );