File: basic.t

package info (click to toggle)
libhtml-simpleparse-perl 0.12-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 88 kB
  • sloc: perl: 223; makefile: 2
file content (130 lines) | stat: -rw-r--r-- 2,450 bytes parent folder | download | duplicates (5)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/perl -w

use Test;
BEGIN { plan tests => 23 }
use HTML::SimpleParse;
ok 1;

use Carp;
$SIG{__WARN__} = \&Carp::cluck;

{
	my %hash = HTML::SimpleParse->parse_args('A="xx" B=3');
	ok $hash{A}, "xx";
	ok $hash{B}, 3;
}

{
	my %hash = HTML::SimpleParse->parse_args('A="xx" B');
	ok $hash{A}, "xx";
	ok exists $hash{B};
}

{
	my %hash = HTML::SimpleParse->parse_args('A="xx" B c="hi" ');
	ok $hash{A}, "xx";
	ok exists $hash{B};
	ok $hash{C}, "hi";
}

{
	my $text = 'type=checkbox checked name=flavor value="chocolate or strawberry"';
	my %hash = HTML::SimpleParse->parse_args( $text );
	ok $hash{TYPE}, "checkbox";
	ok exists $hash{CHECKED};
	ok $hash{VALUE}, "chocolate or strawberry";
}

{
	my %hash=HTML::SimpleParse->parse_args(' A="xx" B');
	ok $hash{A}, 'xx';
	ok exists $hash{B};
}

{
	my $text = <<EOF;
	<html><head>
	<title>Hiya, tester</title>
	</head>
	
	<body>
	<center><h1>Hiya, tester</h1></center>
	<!-- here is a comment -->
	<!DOCTYPE here is a markup>
	<!--# here is an ssi -->
	</body>
	</html>
EOF
	my $p = new HTML::SimpleParse( $text );
	
	ok $p->get_output(), $text;
}

{
	my %hash = HTML::SimpleParse->parse_args('a="b=c"');
	ok $hash{A}, "b=c";
}

{
	my %hash = HTML::SimpleParse->parse_args('val="a \"value\""');
	ok $hash{VAL}, 'a "value"';
}

{
  my %hash = HTML::SimpleParse->parse_args('val = "a \"value\""');
  ok $hash{VAL}, 'a "value"';
}

{
  # Avoid 'uninitialized value' warning
  my $ok=1;
  local $^W=1;
  local $SIG{__WARN__} = sub {$ok=0};
  HTML::SimpleParse->new();
  ok $ok;
}

{
  my %hash = HTML::SimpleParse->parse_args("val='a value'");
  ok $hash{VAL}, 'a value';
}

{
  local $HTML::SimpleParse::FIX_CASE = 0;
  my %hash = HTML::SimpleParse->parse_args("val='a value'");
  ok $hash{val}, 'a value';
}

{
  local $HTML::SimpleParse::FIX_CASE = 0;
  my %hash = HTML::SimpleParse->parse_args("Val='a value'");
  ok $hash{Val}, 'a value';
}

{
  my $p = new HTML::SimpleParse('', fix_case => 0);
  my %hash = $p->parse_args("Val='a value'");
  ok $hash{Val}, 'a value';
}

{
  my $text = <<EOF;
    <html><head>
    <title>Hiya, tester</title>
    </head>
	
    <body>
    <center><h1>Hiya, tester</h1></center>
    <!-- here is a comment -->
    <!DOCTYPE here is a markup>
    <!--# here is an ssi -->
    </body>
    </html>
EOF
  my $p = new HTML::SimpleParse($text);
  my $ok = 1;
  foreach ($p->tree) {
    $ok = 0 unless substr($text, $_->{offset}) =~ /^<?\Q$_->{content}/;
  }
  ok $ok;
}