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
|
package main;
use strict;
use warnings;
use Test::More tests => 15;
use XML::Hash::XS 'xml2hash';
$XML::Hash::XS::keep_root = 0;
{
is
xml2hash("<!DOCTYPE root><root>OK</root>"),
"OK",
'simple',
;
}
{
is
xml2hash("<!DOCTYPE\n\r\t root \n\r\t><root>OK</root>"),
"OK",
'with extra spaces',
;
}
{
is
xml2hash("<!-- comment --><!DOCTYPE root><!-- comment --><root>OK</root>"),
"OK",
'with comments',
;
}
{
is
xml2hash("<!DOCTYPE root SYSTEM \"dtd\"><root>OK</root>"),
"OK",
'with external system DTD',
;
}
{
is
xml2hash("<!DOCTYPE root SYSTEM 'dtd'><root>OK</root>"),
"OK",
'with external system DTD',
;
}
{
is
xml2hash('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"' .
' "http://www.w3.org/TR/REC-html40/loose.dtd"><root>OK</root>'),
"OK",
'with external public DTD',
;
}
{
is
xml2hash(<<'XML'),
<!DOCTYPE root [
<!ELEMENT document
(title*,subjectID,subjectname,prerequisite?,
classes,assessment,syllabus,textbooks*)>
<!ELEMENT prerequisite (subjectID,subjectname)>
<!ELEMENT textbooks (author,booktitle)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT subjectID (#PCDATA)>
<!ELEMENT subjectname (#PCDATA)>
<!ELEMENT classes (#PCDATA)>
<!ELEMENT assessment (#PCDATA)>
<!ATTLIST assessment assessment_type (exam | assignment) #IMPLIED>
<!ELEMENT syllabus (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT booktitle (#PCDATA)>
]>
<root>OK</root>
XML
"OK",
'with internal subset',
;
}
{
eval { xml2hash("<!DOCTYPE><root>123</root>") };
ok($@, 'missing root element type');
}
{
eval { xml2hash("<!DOCTYPE root><!DOCTYPE root><root>123</root>") };
ok($@, 'duplicate doctype');
}
{
eval { xml2hash("<root><!DOCTYPE root></root>") };
ok($@, 'misplaced doctype');
}
{
eval { xml2hash("<!DOCTYPE root SYSTEM><root>123</root>") };
ok($@, 'wrong external system DTD');
}
{
eval { xml2hash('<!DOCTYPE root PUBLIC><root>123</root>') };
ok($@, 'wrong external public DTD');
}
{
eval { xml2hash('<!DOCTYPE root PUBLIC "name"><root>123</root>') };
ok($@, 'wrong external public DTD2');
}
{
eval { xml2hash('<!DOCTYPE root [><root>123</root>') };
ok($@, 'wrong internal subset');
}
{
eval { xml2hash('<!DOCTYPE root []]><root>123</root>') };
ok($@, 'wrong internal subset');
}
|