Add ARM files
[dh-make-perl] / dev / arm / libhtml-parser-perl / libhtml-parser-perl-3.56 / t / marked-sect.t
1 #!/usr/bin/perl -w
2
3 use strict;
4 my $tag;
5 my $text;
6
7 use HTML::Parser ();
8 my $p = HTML::Parser->new(start_h => [sub { $tag = shift  }, "tagname"],
9                           text_h  => [sub { $text .= shift }, "dtext"],
10                          );
11
12
13 use Test::More tests => 14;
14
15 SKIP: {
16 eval {
17     $p->marked_sections(1);
18 };
19 skip $@, 14 if $@;
20
21 $p->parse("<![[foo]]>");
22 is($text, "foo");
23
24 $p->parse("<![TEMP INCLUDE[bar]]>");
25 is($text, "foobar");
26
27 $p->parse("<![ INCLUDE -- IGNORE -- [foo<![IGNORE[bar]]>]]>\n<br>");
28 is($text, "foobarfoo\n");
29
30 $text = "";
31 $p->parse("<![  CDATA   [&lt;foo");
32 $p->parse("<![IGNORE[bar]]>,bar&gt;]]><br>");
33 is($text, "&lt;foo<![IGNORE[bar,bar>]]>");
34
35 $text = "";
36 $p->parse("<![ RCDATA [&aring;<a>]]><![CDATA[&aring;<a>]]>&aring;<a><br>");
37 is($text, "å<a>&aring;<a>å");
38 is($tag, "br");
39
40 $text = "";
41 $p->parse("<![INCLUDE RCDATA CDATA IGNORE [foo&aring;<a>]]><br>");
42 is($text,  "");
43
44 $text = "";
45 $p->parse("<![INCLUDE RCDATA CDATA [foo&aring;<a>]]><br>");
46 is($text, "foo&aring;<a>");
47
48 $text = "";
49 $p->parse("<![INCLUDE RCDATA [foo&aring;<a>]]><br>");
50 is($text, "fooå<a>");
51
52 $text = "";
53 $p->parse("<![INCLUDE [foo&aring;<a>]]><br>");
54 is($text, "fooå");
55
56 $text = "";
57 $p->parse("<![[foo&aring;<a>]]><br>");
58 is($text, "fooå");
59
60 # offsets/line/column numbers
61 $p = HTML::Parser->new(default_h => [\&x, "line,column,offset,event,text"],
62                        marked_sections => 1,
63                       );
64 $p->parse(<<'EOT')->eof;
65 <title>Test</title>
66 <![CDATA
67   [foo&aring;<a>
68 ]]>
69 <![[
70 INCLUDE
71 STUFF
72 ]]>
73   <h1>Test</h1>
74 EOT
75
76 my @x;
77 sub x {
78     my($line, $col, $offset, $event, $text) = @_;
79     $text =~ s/\n/\\n/g;
80     $text =~ s/ /./g;
81     push(@x, "$line.$col:$offset $event \"$text\"\n");
82 }
83
84 #diag @x;
85 is(join("", @x), <<'EOT');
86 1.0:0 start_document ""
87 1.0:0 start "<title>"
88 1.7:7 text "Test"
89 1.11:11 end "</title>"
90 1.19:19 text "\n"
91 3.3:32 text "foo&aring;<a>\n"
92 4.3:49 text "\n"
93 5.4:54 text "\nINCLUDE\nSTUFF\n"
94 8.3:72 text "\n.."
95 9.2:75 start "<h1>"
96 9.6:79 text "Test"
97 9.10:83 end "</h1>"
98 9.15:88 text "\n"
99 10.0:89 end_document ""
100 EOT
101
102 my $doc = "<Tag><![CDATA[This is cdata]]></Tag>";
103 my $result = "";
104 $p = HTML::Parser->new(
105     marked_sections => 1,
106     handlers => {
107         default => [ sub { $result .= join("",@_); }, "skipped_text,text" ]
108     }
109 )->parse($doc)->eof;
110 is($doc, $result);
111
112 $text = "";
113 $p = HTML::Parser->new(
114     text_h => [sub { $text .= shift }, "dtext"],
115     marked_sections => 1,
116 );
117
118 $p->parse("<![CDATA[foo [1]]]>");
119 is($text, "foo [1]", "CDATA text ending in square bracket");
120
121 } # SKIP