Release commit for 1.000006
[scpubgit/HTML-String.git] / t / simple.t
CommitLineData
e1b4b35c 1use strictures 1;
2use Test::More;
3use HTML::String;
4
5my $hi = 'Hi <bob>';
6
7my $one = html('<tag>').$hi.html('</tag>');
8
9is("$one", '<tag>Hi &lt;bob&gt;</tag>');
10
11my $two = do {
12 use HTML::String::Overload;
13
ed99cbb4 14 "<tag>${hi}</tag>";
e1b4b35c 15};
16
17is("$two", '<tag>Hi &lt;bob&gt;</tag>');
18
f27b509e 19my $three = html('<tag>');
20
21$three .= $hi;
22
23$three .= html('</tag>');
24
25is("$three", '<tag>Hi &lt;bob&gt;</tag>');
26
27my $four; {
f554c1ff 28 use HTML::String::Overload { ignore => { non_existant_package_name => 1 } };
f27b509e 29
30 #$four = "<tag>".$hi."</tag>\n";
31 $four = "<tag>$hi</tag>"."\n";
32};
33
34chomp($four);
35
36is("$four", '<tag>Hi &lt;bob&gt;</tag>');
37
b8aaa17d 38{
39 package MyPkg;
40
41 sub new { 'foo' }
42
43 sub load { 'bar' }
44}
45
46is(html('MyPkg')->new, 'foo');
47
48is(html('MyPkg')->load, 'bar');
49
fc076557 50# Test that all characters that should be escaped are escaped
51
52my $raw_characters = q{<>&"'};
53my $expected_output = q{<tag>&lt;&gt;&amp;&quot;&#39;</tag>};
54my $html = html('<tag>').$raw_characters.html('</tag>');
55is($html, $expected_output);
56
ac4c210b 57ok(HTML::String::Value->isa('HTML::String::Value'), 'isa on class ok');
58
59is($@, '', '$@ not set by check');
fc076557 60
cb4648fa 61is do {
62 use HTML::String::Overload;
63 '' . '0'
64}, '0', 'concatenating strings which are false in boolean context';
65
e1b4b35c 66done_testing;