Debian lenny version packages
[pkg-perl] / deb-src / libhtml-tree-perl / libhtml-tree-perl-3.23 / t / escape.t
1 #!/usr/bin/perl
2
3 # Tests that the following translations take place, and none other:
4 #
5 #  & => & (aka &)
6 #  < => &#60; (aka &lt;)
7 #  > => &#62; (aka &gt;)
8 #  ' => &#39; (aka &apos;)
9 #  " => &#34; (aka &quot;)
10 #
11 # Further tests that already-escaped things are not further escaped.
12 #
13 # Escapes are defined in the XML spec:
14 #    http://www.w3.org/TR/2006/REC-xml11-20060816/#dt-escape
15
16
17 BEGIN {
18         %translations = (
19                 'x > 3'   => 'x &#62; 3',
20                 'x < 3'   => 'x &#60; 3',
21                 '< 3 >'   => '&#60; 3 &#62;',
22                 "he's"    => "he&#39;s",
23                 "he’s"    => "he’s", # MS "smart" quotes don't get escaped (single)
24                 '"his"'   => '&#34;his&#34;',
25                 '‘his’'   => '‘his’', # MS "smart" quotes don't get escaped (single)
26                 '“his”'   => '“his”', # MS "smart" quotes don't get escaped (double)
27                 '1&2'     => '1&#38;2',
28                 '1&#38;2' => '1&#38;2',
29                 '1&amp;2' => '1&amp;2',
30                 '1&amp 2' => '1&#38;amp 2',
31                 '1&#38 2' => '1&#38;#38 2',
32                 'abc'     => 'abc',
33                 'número'  => 'número',
34                 '&dArr;'  => '&dArr;',
35                 '&OElig;' => '&OElig;',
36                 '&sup2;'  => '&sup2;',
37                 '&no_go;' => '&#38;no_go;',
38
39                 'This &#x17f;oftware has &#383;ome bugs' => 'This &#x17f;oftware has &#383;ome bugs', # RT 18568
40         );
41
42         $tests = keys(%translations) + 1;
43 }
44
45 use Test::More tests => $tests;
46
47 BEGIN {
48
49         use_ok('HTML::Element');
50 }
51
52 foreach my $orig (keys %translations) {
53         $new = $orig;
54         HTML::Element::_xml_escape($new);
55         is($new,$translations{$orig},"Properly escaped: $orig");
56 }
57