rewrite home page redirect
[dh-make-perl] / dev / arm / libhtml-parser-perl / libhtml-parser-perl-3.56 / t / entities.t
1 use HTML::Entities qw(decode_entities encode_entities encode_entities_numeric);
2
3 use Test::More tests => 13;
4
5 $a = "Våre norske tegn bør &#230res";
6
7 decode_entities($a);
8
9 is($a, "Våre norske tegn bør æres");
10
11 encode_entities($a);
12
13 is($a, "Våre norske tegn bør æres");
14
15 decode_entities($a);
16 encode_entities_numeric($a);
17
18 is($a, "Våre norske tegn bør æres");
19
20 $a = "<&>\"'";
21 is(encode_entities($a), "&lt;&amp;&gt;&quot;&#39;");
22 is(encode_entities_numeric($a), "&#x3C;&#x26;&#x3E;&#x22;&#x27;");
23
24 $a = "abcdef";
25 is(encode_entities($a, 'a-c'), "&#97;&#98;&#99;def");
26
27
28 # See how well it does against rfc1866...
29 $ent = $plain = "";
30 while (<DATA>) {
31     next unless /^\s*<!ENTITY\s+(\w+)\s*CDATA\s*\"&\#(\d+)/;
32     $ent .= "&$1;";
33     $plain .= chr($2);
34 }
35
36 $a = $ent;
37 decode_entities($a);
38 is($a, $plain);
39
40 # Try decoding when the ";" are left out
41 $a = $ent,
42 $a =~ s/;//g;
43 decode_entities($a);
44 is($a, $plain);
45
46
47 $a = $plain;
48 encode_entities($a);
49 is($a, $ent);
50
51
52 # From: Bill Simpson-Young <bill.simpson-young@cmis.csiro.au>
53 # Subject: HTML entities problem with 5.11
54 # To: libwww-perl@ics.uci.edu
55 # Date: Fri, 05 Sep 1997 16:56:55 +1000
56 # Message-Id: <199709050657.QAA10089@snowy.nsw.cmis.CSIRO.AU>
57 #
58 # Hi. I've got a problem that has surfaced with the changes to 
59 # HTML::Entities.pm for 5.11 (it doesn't happen with 5.08).  It's happening 
60 # in the process of encoding then decoding special entities.  Eg, what goes 
61 # in as "abc&def&ghi" comes out as "abc&def;&ghi;".
62
63 is(decode_entities("abc&def&ghi&abc;&def;"), "abc&def&ghi&abc;&def;");
64
65 # Decoding of &apos;
66 is(decode_entities("&apos;"), "'");
67 is(encode_entities("'", "'"), "&#39;");
68
69 is(decode_entities("Attention Home&#959&#969n&#1257rs...1&#1109t T&#1110&#1084e E&#957&#1257&#1075"),
70   "Attention Home\x{3BF}\x{3C9}n\x{4E9}rs...1\x{455}t T\x{456}\x{43C}e E\x{3BD}\x{4E9}\x{433}");
71
72 __END__
73 # Quoted from rfc1866.txt
74
75 14. Proposed Entities
76
77    The HTML DTD references the "Added Latin 1" entity set, which only
78    supplies named entities for a subset of the non-ASCII characters in
79    [ISO-8859-1], namely the accented characters. The following entities
80    should be supported so that all ISO 8859-1 characters may only be
81    referenced symbolically. The names for these entities are taken from
82    the appendixes of [SGML].
83
84     <!ENTITY nbsp   CDATA "&#160;" -- no-break space -->
85     <!ENTITY iexcl  CDATA "&#161;" -- inverted exclamation mark -->
86     <!ENTITY cent   CDATA "&#162;" -- cent sign -->
87     <!ENTITY pound  CDATA "&#163;" -- pound sterling sign -->
88     <!ENTITY curren CDATA "&#164;" -- general currency sign -->
89     <!ENTITY yen    CDATA "&#165;" -- yen sign -->
90     <!ENTITY brvbar CDATA "&#166;" -- broken (vertical) bar -->
91     <!ENTITY sect   CDATA "&#167;" -- section sign -->
92     <!ENTITY uml    CDATA "&#168;" -- umlaut (dieresis) -->
93     <!ENTITY copy   CDATA "&#169;" -- copyright sign -->
94     <!ENTITY ordf   CDATA "&#170;" -- ordinal indicator, feminine -->
95     <!ENTITY laquo  CDATA "&#171;" -- angle quotation mark, left -->
96     <!ENTITY not    CDATA "&#172;" -- not sign -->
97     <!ENTITY shy    CDATA "&#173;" -- soft hyphen -->
98     <!ENTITY reg    CDATA "&#174;" -- registered sign -->
99     <!ENTITY macr   CDATA "&#175;" -- macron -->
100     <!ENTITY deg    CDATA "&#176;" -- degree sign -->
101     <!ENTITY plusmn CDATA "&#177;" -- plus-or-minus sign -->
102     <!ENTITY sup2   CDATA "&#178;" -- superscript two -->
103     <!ENTITY sup3   CDATA "&#179;" -- superscript three -->
104     <!ENTITY acute  CDATA "&#180;" -- acute accent -->
105     <!ENTITY micro  CDATA "&#181;" -- micro sign -->
106     <!ENTITY para   CDATA "&#182;" -- pilcrow (paragraph sign) -->
107     <!ENTITY middot CDATA "&#183;" -- middle dot -->
108     <!ENTITY cedil  CDATA "&#184;" -- cedilla -->
109     <!ENTITY sup1   CDATA "&#185;" -- superscript one -->
110     <!ENTITY ordm   CDATA "&#186;" -- ordinal indicator, masculine -->
111     <!ENTITY raquo  CDATA "&#187;" -- angle quotation mark, right -->
112     <!ENTITY frac14 CDATA "&#188;" -- fraction one-quarter -->
113     <!ENTITY frac12 CDATA "&#189;" -- fraction one-half -->
114     <!ENTITY frac34 CDATA "&#190;" -- fraction three-quarters -->
115     <!ENTITY iquest CDATA "&#191;" -- inverted question mark -->
116     <!ENTITY Agrave CDATA "&#192;" -- capital A, grave accent -->
117     <!ENTITY Aacute CDATA "&#193;" -- capital A, acute accent -->
118     <!ENTITY Acirc  CDATA "&#194;" -- capital A, circumflex accent -->
119
120
121
122 Berners-Lee & Connolly      Standards Track                    [Page 75]
123 \f
124 RFC 1866            Hypertext Markup Language - 2.0        November 1995
125
126
127     <!ENTITY Atilde CDATA "&#195;" -- capital A, tilde -->
128     <!ENTITY Auml   CDATA "&#196;" -- capital A, dieresis or umlaut mark -->
129     <!ENTITY Aring  CDATA "&#197;" -- capital A, ring -->
130     <!ENTITY AElig  CDATA "&#198;" -- capital AE diphthong (ligature) -->
131     <!ENTITY Ccedil CDATA "&#199;" -- capital C, cedilla -->
132     <!ENTITY Egrave CDATA "&#200;" -- capital E, grave accent -->
133     <!ENTITY Eacute CDATA "&#201;" -- capital E, acute accent -->
134     <!ENTITY Ecirc  CDATA "&#202;" -- capital E, circumflex accent -->
135     <!ENTITY Euml   CDATA "&#203;" -- capital E, dieresis or umlaut mark -->
136     <!ENTITY Igrave CDATA "&#204;" -- capital I, grave accent -->
137     <!ENTITY Iacute CDATA "&#205;" -- capital I, acute accent -->
138     <!ENTITY Icirc  CDATA "&#206;" -- capital I, circumflex accent -->
139     <!ENTITY Iuml   CDATA "&#207;" -- capital I, dieresis or umlaut mark -->
140     <!ENTITY ETH    CDATA "&#208;" -- capital Eth, Icelandic -->
141     <!ENTITY Ntilde CDATA "&#209;" -- capital N, tilde -->
142     <!ENTITY Ograve CDATA "&#210;" -- capital O, grave accent -->
143     <!ENTITY Oacute CDATA "&#211;" -- capital O, acute accent -->
144     <!ENTITY Ocirc  CDATA "&#212;" -- capital O, circumflex accent -->
145     <!ENTITY Otilde CDATA "&#213;" -- capital O, tilde -->
146     <!ENTITY Ouml   CDATA "&#214;" -- capital O, dieresis or umlaut mark -->
147     <!ENTITY times  CDATA "&#215;" -- multiply sign -->
148     <!ENTITY Oslash CDATA "&#216;" -- capital O, slash -->
149     <!ENTITY Ugrave CDATA "&#217;" -- capital U, grave accent -->
150     <!ENTITY Uacute CDATA "&#218;" -- capital U, acute accent -->
151     <!ENTITY Ucirc  CDATA "&#219;" -- capital U, circumflex accent -->
152     <!ENTITY Uuml   CDATA "&#220;" -- capital U, dieresis or umlaut mark -->
153     <!ENTITY Yacute CDATA "&#221;" -- capital Y, acute accent -->
154     <!ENTITY THORN  CDATA "&#222;" -- capital THORN, Icelandic -->
155     <!ENTITY szlig  CDATA "&#223;" -- small sharp s, German (sz ligature) -->
156     <!ENTITY agrave CDATA "&#224;" -- small a, grave accent -->
157     <!ENTITY aacute CDATA "&#225;" -- small a, acute accent -->
158     <!ENTITY acirc  CDATA "&#226;" -- small a, circumflex accent -->
159     <!ENTITY atilde CDATA "&#227;" -- small a, tilde -->
160     <!ENTITY auml   CDATA "&#228;" -- small a, dieresis or umlaut mark -->
161     <!ENTITY aring  CDATA "&#229;" -- small a, ring -->
162     <!ENTITY aelig  CDATA "&#230;" -- small ae diphthong (ligature) -->
163     <!ENTITY ccedil CDATA "&#231;" -- small c, cedilla -->
164     <!ENTITY egrave CDATA "&#232;" -- small e, grave accent -->
165     <!ENTITY eacute CDATA "&#233;" -- small e, acute accent -->
166     <!ENTITY ecirc  CDATA "&#234;" -- small e, circumflex accent -->
167     <!ENTITY euml   CDATA "&#235;" -- small e, dieresis or umlaut mark -->
168     <!ENTITY igrave CDATA "&#236;" -- small i, grave accent -->
169     <!ENTITY iacute CDATA "&#237;" -- small i, acute accent -->
170     <!ENTITY icirc  CDATA "&#238;" -- small i, circumflex accent -->
171     <!ENTITY iuml   CDATA "&#239;" -- small i, dieresis or umlaut mark -->
172     <!ENTITY eth    CDATA "&#240;" -- small eth, Icelandic -->
173     <!ENTITY ntilde CDATA "&#241;" -- small n, tilde -->
174     <!ENTITY ograve CDATA "&#242;" -- small o, grave accent -->
175
176
177
178 Berners-Lee & Connolly      Standards Track                    [Page 76]
179 \f
180 RFC 1866            Hypertext Markup Language - 2.0        November 1995
181
182
183     <!ENTITY oacute CDATA "&#243;" -- small o, acute accent -->
184     <!ENTITY ocirc  CDATA "&#244;" -- small o, circumflex accent -->
185     <!ENTITY otilde CDATA "&#245;" -- small o, tilde -->
186     <!ENTITY ouml   CDATA "&#246;" -- small o, dieresis or umlaut mark -->
187     <!ENTITY divide CDATA "&#247;" -- divide sign -->
188     <!ENTITY oslash CDATA "&#248;" -- small o, slash -->
189     <!ENTITY ugrave CDATA "&#249;" -- small u, grave accent -->
190     <!ENTITY uacute CDATA "&#250;" -- small u, acute accent -->
191     <!ENTITY ucirc  CDATA "&#251;" -- small u, circumflex accent -->
192     <!ENTITY uuml   CDATA "&#252;" -- small u, dieresis or umlaut mark -->
193     <!ENTITY yacute CDATA "&#253;" -- small y, acute accent -->
194     <!ENTITY thorn  CDATA "&#254;" -- small thorn, Icelandic -->
195     <!ENTITY yuml   CDATA "&#255;" -- small y, dieresis or umlaut mark -->