summaryrefslogtreecommitdiff
path: root/t/case-sensitive.t
blob: 565b20b3e99a41b329310d238dbcd1073aac00ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use strict;
use Test::More tests => 8;

use HTML::Parser ();
my $p = HTML::Parser->new();
$p->case_sensitive(1);

my $text = "";
$p->handler(start =>
	    sub {
		 my($tag, $attr, $attrseq) = @_;
		 $text .= "S[$tag";
		 for my $k (sort keys %$attr) {
		     my $v =  $attr->{$k};
		     $text .= " $k=$v";
		 }
		 if (@$attrseq) { $text.=" Order:" ; }
		 for my $k (@$attrseq) {
		     $text .= " $k";
		 }
		 $text .= "]";
	     }, "tagname,attr,attrseq");
$p->handler(end =>
	    sub {
		 my ($tag) = @_;
		 $text .= "E[$tag]";
	     }, "tagname");

my $html = <<'EOT';
<tAg aRg="Value" arg="other value"></tAg>
EOT
my $cs = 'S[tAg aRg=Value arg=other value Order: aRg arg]E[tAg]';
my $ci = 'S[tag arg=Value Order: arg arg]E[tag]';

$p->parse($html)->eof;
is($text, $cs);

$text = "";
$p->case_sensitive(0);
$p->parse($html)->eof;
is($text, $ci);

$text = "";
$p->case_sensitive(1);
$p->xml_mode(1);
$p->parse($html)->eof;
is($text, $cs);

$text = "";
$p->case_sensitive(0);
$p->parse($html)->eof;
is($text, $cs);

$html = <<'EOT';
<tAg aRg="Value" arg="other value"></tAg>
<iGnOrE></ignore>
EOT
$p->ignore_tags('ignore');
$cs = 'S[tAg aRg=Value arg=other value Order: aRg arg]E[tAg]S[iGnOrE]';
$ci = 'S[tag arg=Value Order: arg arg]E[tag]';

$text = "";
$p->case_sensitive(0);
$p->xml_mode(0);
$p->parse($html)->eof;
is($text, $ci);
 
$text = "";
$p->case_sensitive(1);
$p->xml_mode(0);
$p->parse($html)->eof;
is($text, $cs);

$text = "";
$p->case_sensitive(0);
$p->xml_mode(1);
$p->parse($html)->eof;
is($text, $cs);
 
$text = "";
$p->case_sensitive(1);
$p->xml_mode(1);
$p->parse($html)->eof;
is($text, $cs);