Debian Codegraph @

t/15-x2h_doctype.t

raw
1 package main;
2 use strict;
3 use warnings;
4
5 use Test::More tests => 15;
6
7 use XML::Hash::XS 'xml2hash';
8 $XML::Hash::XS::keep_root = 0;
9
10 {
11 is
12 xml2hash("<!DOCTYPE root><root>OK</root>"),
13 "OK",
14 'simple',
15 ;
16 }
17
18 {
19 is
20 xml2hash("<!DOCTYPE\n\r\t root \n\r\t><root>OK</root>"),
21 "OK",
22 'with extra spaces',
23 ;
24 }
25
26 {
27 is
28 xml2hash("<!-- comment --><!DOCTYPE root><!-- comment --><root>OK</root>"),
29 "OK",
30 'with comments',
31 ;
32 }
33
34 {
35 is
36 xml2hash("<!DOCTYPE root SYSTEM \"dtd\"><root>OK</root>"),
37 "OK",
38 'with external system DTD',
39 ;
40 }
41
42 {
43 is
44 xml2hash("<!DOCTYPE root SYSTEM 'dtd'><root>OK</root>"),
45 "OK",
46 'with external system DTD',
47 ;
48 }
49
50 {
51 is
52 xml2hash('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"' .
53 ' "http://www.w3.org/TR/REC-html40/loose.dtd"><root>OK</root>'),
54 "OK",
55 'with external public DTD',
56 ;
57 }
58
59 {
60 is
61 xml2hash(<<'XML'),
62 <!DOCTYPE root [
63 <!ELEMENT document
64 (title*,subjectID,subjectname,prerequisite?,
65 classes,assessment,syllabus,textbooks*)>
66 <!ELEMENT prerequisite (subjectID,subjectname)>
67 <!ELEMENT textbooks (author,booktitle)>
68 <!ELEMENT title (#PCDATA)>
69 <!ELEMENT subjectID (#PCDATA)>
70 <!ELEMENT subjectname (#PCDATA)>
71 <!ELEMENT classes (#PCDATA)>
72 <!ELEMENT assessment (#PCDATA)>
73 <!ATTLIST assessment assessment_type (exam | assignment) #IMPLIED>
74 <!ELEMENT syllabus (#PCDATA)>
75 <!ELEMENT author (#PCDATA)>
76 <!ELEMENT booktitle (#PCDATA)>
77 ]>
78 <root>OK</root>
79 XML
80 "OK",
81 'with internal subset',
82 ;
83 }
84
85 {
86 eval { xml2hash("<!DOCTYPE><root>123</root>") };
87 ok($@, 'missing root element type');
88 }
89
90 {
91 eval { xml2hash("<!DOCTYPE root><!DOCTYPE root><root>123</root>") };
92 ok($@, 'duplicate doctype');
93 }
94
95 {
96 eval { xml2hash("<root><!DOCTYPE root></root>") };
97 ok($@, 'misplaced doctype');
98 }
99
100 {
101 eval { xml2hash("<!DOCTYPE root SYSTEM><root>123</root>") };
102 ok($@, 'wrong external system DTD');
103 }
104
105 {
106 eval { xml2hash('<!DOCTYPE root PUBLIC><root>123</root>') };
107 ok($@, 'wrong external public DTD');
108 }
109
110 {
111 eval { xml2hash('<!DOCTYPE root PUBLIC "name"><root>123</root>') };
112 ok($@, 'wrong external public DTD2');
113 }
114
115 {
116 eval { xml2hash('<!DOCTYPE root [><root>123</root>') };
117 ok($@, 'wrong internal subset');
118 }
119
120 {
121 eval { xml2hash('<!DOCTYPE root []]><root>123</root>') };
122 ok($@, 'wrong internal subset');
123 }