1169d92004-05-02Martin Nilsson START_MARKER
408f9e2002-08-02Martin Nilsson  // DOM // Tree
0d39292005-12-18Martin Nilsson define(test_tree_eq,[[ test_eq(Parser.XML.Tree.parse_input $1 ,$2) test_eq(Parser.XML.Tree.simple_parse_input $1 ,$2)
9e14ec2006-07-21Henrik Grubbström (Grubba)  test_eq(Parser.XML.Tree.RootNode $1 ,$2) test_eq(Parser.XML.Tree.SimpleRootNode $1 ,$2)
0d39292005-12-18Martin Nilsson ]])
ccf77a2003-12-23Henrik Grubbström (Grubba) test_eval_error([[ Parser.XML.Tree.parse_input("<foo>", 0, 0, 0, 1); ]])
0d39292005-12-18Martin Nilsson test_tree_eq([[ ("<a>foo &gt; hej &x.y; hopp &lt; bar</a>")->render_xml() ]],
24443a2002-10-25Martin Nilsson [[ "<a>foo &gt; hej &amp;x.y; hopp &lt; bar</a>" ]])
0d39292005-12-18Martin Nilsson test_tree_eq([[ ("<a>foo &gt; hej &x.y; hopp &lt; bar</a>")->render_xml(1); ]],
24443a2002-10-25Martin Nilsson [[ "<a>foo &gt; hej &x.y; hopp &lt; bar</a>" ]])
0d39292005-12-18Martin Nilsson test_tree_eq([[ ("<a>hej &x.y; hopp</a>")->render_xml(); ]],
24443a2002-10-25Martin Nilsson [[ "<a>hej &amp;x.y; hopp</a>" ]])
0d39292005-12-18Martin Nilsson test_tree_eq([[ ("<a>hej &x.y; hopp</a>")->render_xml(1); ]],
24443a2002-10-25Martin Nilsson [[ "<a>hej &x.y; hopp</a>" ]]) test_eq([[ (string)Parser.XML.Tree.parse_input("<a><b> <c/> </b></a>") ]], [[ "<a><b> <c/> </b></a>" ]])
0d39292005-12-18Martin Nilsson test_tree_eq([[ ("<p>a<![CDATA[b]""]>c</p>")[0][0]->get_text() ]],
f989a02005-10-31Martin Nilsson [[ "abc" ]])
0d39292005-12-18Martin Nilsson test_tree_eq([[ ("<?xml version=\"1.0\"?><!DOCTYPE greeting SYSTEM \"hello.dtd\"><!-- comment -- --><x/>")->render_xml() ]], [[ "<?xml version='1.0' encoding='utf-8'?><!DOCTYPE greeting SYSTEM \"hello.dtd\"><!-- comment -- --><x/>" ]])
5f66272018-05-13Martin Nilsson test_tree_eq([[ ("<x><a foo='x\"'/><b bar=\"x'y\"/></x>")->render_xml() ]], [[ "<x><a foo='x\"'/><b bar=\"x'y\"/></x>" ]])
0d39292005-12-18Martin Nilsson 
9e14ec2006-07-21Henrik Grubbström (Grubba) // Check that any xml and/or doctype header survives the parsing. // Check also that the headers are rendered properly.
a1b3752006-07-21Henrik Grubbström (Grubba) test_tree_eq([[ ("<?xml version='1.0' encoding='iso-8859-1'?><!DOCTYPE foo [ <!ELEMENT foo (foo)*> ]><foo><foo/><foo/></foo>")->render_xml() ]],
1c03b52006-07-21Henrik Grubbström (Grubba)  [[ "<?xml version='1.0' encoding='iso-8859-1'?><!DOCTYPE foo [ <!ELEMENT foo (foo)*> ]><foo><foo/><foo/></foo>" ]])
a1b3752006-07-21Henrik Grubbström (Grubba) test_tree_eq([[ ("<?xml version='1.0' encoding='utf-8'?><!DOCTYPE foo PUBLIC \"-//EN\" \"foo.dtd\" ><foo><foo/><foo/></foo>")->render_xml() ]],
9e14ec2006-07-21Henrik Grubbström (Grubba)  [[ "<?xml version='1.0' encoding='utf-8'?><!DOCTYPE foo PUBLIC \"-//EN\" \"foo.dtd\"><foo><foo/><foo/></foo>" ]])
eb39e82016-12-06Martin Nilsson dnl You could argue that the decoding should cause an error as 0x2122 dnl is outside of iso-8859-1, but we could just manipulate the text dnl node instead. test_eq([[ Parser.XML.Tree.parse_input("<?xml version='1.0' encoding='iso-8859-1'?><a>\x2122</a>")->render_xml() ]], "<?xml version='1.0' encoding='iso-8859-1'?><a>&#2122;</a>" ) test_eq([[ Parser.XML.Tree.parse_input("<?xml version='1.0' encoding='iso-8859-1'?><a>\x2122</a>")->render_xml(0,0,"utf-8") ]], "<?xml version='1.0' encoding='utf-8'?><a>\342\204\242</a>" )
ff5cd72016-12-08Martin Nilsson test_eq([[ Parser.XML.Tree.parse_input("\xef\xbb\xbf<i></i>")->render_xml() ]], "<i/>")
0d39292005-12-18Martin Nilsson test_any([[ class A {
9e14ec2006-07-21Henrik Grubbström (Grubba)  inherit Parser.XML.Tree.RootNode;
a1b3752006-07-21Henrik Grubbström (Grubba)  public array(Parser.XML.Tree.AbstractSimpleNode) mChildren = ({});
0d39292005-12-18Martin Nilsson }; return sizeof(A("<!-- --><!-- --><x/>")->mChildren); ]], 3)
c0be712012-09-03Henrik Grubbström (Grubba) // Tests of namespace handling in normal-mode. test_any([[ // InfoKOM 731715 object root = Parser.XML.Tree.simple_parse_input("<root/>"); object sub = Parser.XML.Tree.SimpleNode(Parser.XML.Tree.XML_ELEMENT, "sub", ([ "foo" : "bar" ]), ""); root->get_elements("root")[0]->add_child(sub); return root->render_xml(); ]], "<root><sub foo='bar'/></root>") test_any([[ // InfoKOM 731484 return Parser.XML.Tree.simple_parse_input( "<feed xmlns='http://www.w3.org/2005/Atom'\n" " xmlns:example='http://www.example.com/example'>\n" " <entry>\n" " <category example:test='yes' label='Test' example:test='yes' term='test' />\n" " </entry>\n" "</feed>")->render_xml(); ]], "<feed xmlns='http://www.w3.org/2005/Atom'" " xmlns:example='http://www.example.com/example'>\n" " <entry>\n" " <category example:test='yes' label='Test' term='test'/>\n" " </entry>\n" "</feed>")
24443a2002-10-25Martin Nilsson 
611b582012-10-17Henrik Grubbström (Grubba) test_do([[ add_constant("xmlblob", #"<?xml version='1.0' encoding='utf-8'?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:A='http://example.com/dtd'> <generator>Grubba</generator> <id>urn:uuid:4baeaeb4-7125-463a-9b68-a7005a7548bb</id> <title>Namespace Test</title> <updated>2012-09-28T16:02:16+02:00</updated> <entry> <title>Namespace Test</title> <id>urn:uuid:e73d603c-c287-47c8-b17c-c9e35981d64a</id> <link href='urn:uuid:e73d603c-c287-47c8-b17c-c9e35981d64a' rel='self'/> <updated>2012-09-28T16:02:16+02:00</updated> <author> <name>Grubba</name> </author> <A:user user-name='grubba'>Grubba</A:user> <category A:example='yes' A:priority='300' scheme='http://example.com/dtd' term='example'/> <A:a> <A:b date='2010-10-01'> <A:c yes='no'/> </A:b> </A:a> <content type='xhtml'> <div xmlns='http://www.w3.org/1999/xhtml'> <div A:id='1' class='text' id='e73ab900-f76d-41f7-8576-6be10519e31b' name='text'> <h1 class='headline'>Namespace Test</h1> <p class='normal'>This is a test of whether namespaces work in Parser.XML.Tree.</p> </div> <div class='image' id='68788699-d986-418a-8ca2-2a058ab86625' name='image'> <img class='image' src='/some/path/to/an/image.jpg'/> </div> </div> </content> </entry> </feed>"); ]]) test_eq([[Parser.XML.Tree.simple_parse_input(xmlblob)->render_xml()]], xmlblob) test_eq([[Parser.XML.Tree.simple_parse_input(xmlblob, UNDEFINED, Parser.XML.Tree.PARSE_ENABLE_NAMESPACES)->render_xml()]], xmlblob)
9d52482015-11-12Henrik Grubbström (Grubba) // Test of implicit xml: namespace. test_do([[add_constant("xmlblob", "<?xml version='1.0' encoding='utf-8'?><foo xml:lang='bar' xmlns='gazonk:'/>");]])
5ba5c62015-11-13Henrik Grubbström (Grubba) test_eq([[Parser.XML.Tree.simple_parse_input(xmlblob)->render_xml()]], xmlblob) test_eq([[Parser.XML.Tree.simple_parse_input(xmlblob, UNDEFINED, Parser.XML.Tree.PARSE_ENABLE_NAMESPACES)->render_xml()]], xmlblob) // Test InfoKOM 803815. test_do([[add_constant("xmlblob", #"<?xml version='1.0' encoding='UTF-8'?><foo xmlns='http://bar.com/test' xmlns:bar='http://foo.com/bar/'> <hej bar:gazonk='hopp' xml:lang='sv-SE'> <tag>test</tag> </hej> </foo>");]]) test_eq([[Parser.XML.Tree.simple_parse_input(xmlblob)->render_xml()]], xmlblob)
9d52482015-11-12Henrik Grubbström (Grubba) test_eq([[Parser.XML.Tree.simple_parse_input(xmlblob, UNDEFINED, Parser.XML.Tree.PARSE_ENABLE_NAMESPACES)->render_xml()]], xmlblob) // Test of explicit xml: namespace. test_do([[add_constant("xmlblob", "<?xml version='1.0' encoding='utf-8'?><foo xml:lang='bar' xmlns='gazonk:' xmlns:xml='http://www.w3.org/XML/1998/namespace'/>");]])
5ba5c62015-11-13Henrik Grubbström (Grubba) test_eq([[Parser.XML.Tree.simple_parse_input(xmlblob)->render_xml()]], xmlblob)
9d52482015-11-12Henrik Grubbström (Grubba) test_eq([[Parser.XML.Tree.simple_parse_input(xmlblob, UNDEFINED, Parser.XML.Tree.PARSE_ENABLE_NAMESPACES)->render_xml()]], xmlblob) // Test detection of invalid namespaces. test_do([[add_constant("xmlblob", "<?xml version='1.0' encoding='utf-8'?><foo xml:lang='bar' xmlns='gazonk:' xmlns:xml='http://www.w3.org/XML/1998/invalid'/>");]])
5ba5c62015-11-13Henrik Grubbström (Grubba) test_eq([[Parser.XML.Tree.simple_parse_input(xmlblob)->render_xml()]], xmlblob)
9d52482015-11-12Henrik Grubbström (Grubba) test_eval_error([[Parser.XML.Tree.simple_parse_input(xmlblob, UNDEFINED, Parser.XML.Tree.PARSE_ENABLE_NAMESPACES);]]) test_do([[add_constant("xmlblob", "<?xml version='1.0' encoding='utf-8'?><foo xml:lang='bar' xmlns='gazonk:' xmlns:invalid='http://www.w3.org/XML/1998/namespace'/>");]])
5ba5c62015-11-13Henrik Grubbström (Grubba) test_eq([[Parser.XML.Tree.simple_parse_input(xmlblob)->render_xml()]], xmlblob)
9d52482015-11-12Henrik Grubbström (Grubba) test_eval_error([[Parser.XML.Tree.simple_parse_input(xmlblob, UNDEFINED, Parser.XML.Tree.PARSE_ENABLE_NAMESPACES);]]) test_do([[add_constant("xmlblob", "<?xml version='1.0' encoding='utf-8'?><foo xml:lang='bar' xmlns='gazonk:' xmlns:xmlns='http://www.w3.org/2000/xmlns/'/>");]])
5ba5c62015-11-13Henrik Grubbström (Grubba) test_eq([[Parser.XML.Tree.simple_parse_input(xmlblob)->render_xml()]], xmlblob)
9d52482015-11-12Henrik Grubbström (Grubba) test_eval_error([[Parser.XML.Tree.simple_parse_input(xmlblob, UNDEFINED, Parser.XML.Tree.PARSE_ENABLE_NAMESPACES);]]) test_do([[add_constant("xmlblob", "<?xml version='1.0' encoding='utf-8'?><foo xml:lang='bar' xmlns='gazonk:' xmlns:xmlns='http://www.w3.org/2000/invalid/'/>");]])
5ba5c62015-11-13Henrik Grubbström (Grubba) test_eq([[Parser.XML.Tree.simple_parse_input(xmlblob)->render_xml()]], xmlblob)
9d52482015-11-12Henrik Grubbström (Grubba) test_eval_error([[Parser.XML.Tree.simple_parse_input(xmlblob, UNDEFINED, Parser.XML.Tree.PARSE_ENABLE_NAMESPACES);]]) test_do([[add_constant("xmlblob", "<?xml version='1.0' encoding='utf-8'?><foo xml:lang='bar' xmlns='gazonk:' xmlns:invalid='http://www.w3.org/2000/xmlns/'/>");]])
5ba5c62015-11-13Henrik Grubbström (Grubba) test_eq([[Parser.XML.Tree.simple_parse_input(xmlblob)->render_xml()]], xmlblob)
9d52482015-11-12Henrik Grubbström (Grubba) test_eval_error([[Parser.XML.Tree.simple_parse_input(xmlblob, UNDEFINED, Parser.XML.Tree.PARSE_ENABLE_NAMESPACES);]])
611b582012-10-17Henrik Grubbström (Grubba) test_do([[add_constant("xmlblob");]])
30a4262016-12-20Martin Nilsson test_any([[ object o=Parser.XML.Tree.parse_input("<x><a/><b/><c/></x>"); o[0][1]->replace_node( ({ Parser.XML.Tree.ElementNode("q",([])), Parser.XML.Tree.ElementNode("r",([])) }) ); return (string)o; ]], "<x><a/><q/><r/><c/></x>")
408f9e2002-08-02Martin Nilsson // NSTree // XML NS section 2 test_any_equal([[ object x=Parser.XML.NSTree.parse_input(#" <x> <!-- No namespace here. --> </x>"); x=x[0]; array r = ({}); r += ({ x->get_any_name() }); r += ({ x->get_default_ns() }); r += ({ x->get_ns() }); r += ({ x->get_defined_nss()->edi }); return r; ]], ({ "x", 0, 0, 0 }) ) test_any_equal([[ object x=Parser.XML.NSTree.parse_input(#" <x xmlns:edi='http://ecommerce.org/schema'> <!-- the 'edi' prefix is bound to http://ecommerce.org/schema for the 'x' element and contents --> </x>"); x=x[0]; array r = ({}); r += ({ x->get_any_name() }); r += ({ x->get_default_ns() }); r += ({ x->get_ns() }); r += ({ x->get_defined_nss()->edi }); r += ({ x[0]->get_default_ns() }); r += ({ x[0]->get_ns() }); r += ({ x[0]->get_defined_nss()->edi }); return r; ]], ({ "x", 0, 0, "http://ecommerce.org/schema", 0, 0, "http://ecommerce.org/schema" }) ) // XML NS section 4 test_any_equal([[ object x=Parser.XML.NSTree.parse_input(#" <x xmlns:edi='http://ecommerce.org/schema'> <!-- the 'price' element's namespace is http://ecommerce.org/schema --> <edi:price units='Euro'>32.18</edi:price> </x>"); x=x[0]; array r = ({}); r += ({ x[3]->get_any_name() }); r += ({ x[3]->get_ns() }); r += ({ x[3]->get_attributes()->units }); r += ({ x[3][0]->get_ns() }); return r; ]], ({ "price", "http://ecommerce.org/schema", "Euro", 0 }) ); test_any_equal([[ object x=Parser.XML.NSTree.parse_input(#" <x xmlns:edi='http://ecommerce.org/schema'> <!-- the 'taxClass' attribute's namespace is http://ecommerce.org/schema --> <lineItem edi:taxClass=\"exempt\">Baby food</lineItem> </x>"); x=x[0]; array r = ({}); r += ({ x[3]->get_ns() }); r += ({ x[3]->get_attributes() }); r += ({ x[3]->get_ns_attributes() }); return r; ]], ({ 0, ([]), ([ "http://ecommerce.org/schema": ([ "taxClass":"exempt" ]) ]) }) ) // XML NS section 5.1 test_any_equal([[
642b802005-12-18Martin Nilsson object x=Parser.XML.NSTree.parse_input(#"<?xml version=\"1.0\"?>
408f9e2002-08-02Martin Nilsson <!-- all elements here are explicitly in the HTML namespace --> <html:html xmlns:html='http://www.w3.org/TR/REC-html40'> <html:head><html:title>Frobnostication</html:title></html:head>
3524712015-05-26Martin Nilsson  <html:body><html:p>Moved to
408f9e2002-08-02Martin Nilsson  <html:a href='http://frob.com'>here.</html:a></html:p></html:body> </html:html>"); x=x[2]; array r = ({}); r += ({ x->get_ns() }); r += ({ x->get_default_ns() }); r += ({ x[0]->get_ns() }); r += ({ x[0]->get_default_ns() }); r += ({ x[3][0][1]->get_attributes()->href }); return r; ]], ({ "http://www.w3.org/TR/REC-html40", 0, 0, 0, "http://frob.com" }) ) test_any_equal([[
642b802005-12-18Martin Nilsson object x=Parser.XML.NSTree.parse_input(#"<?xml version=\"1.0\"?>
408f9e2002-08-02Martin Nilsson <!-- both namespace prefixes are available throughout --> <bk:book xmlns:bk='urn:loc.gov:books' xmlns:isbn='urn:ISBN:0-395-36341-6'> <bk:title>Cheaper by the Dozen</bk:title> <isbn:number>1568491379</isbn:number> </bk:book>"); x=x[2]; array r = ({}); r += ({ x->get_ns() }); r += ({ x->get_defined_nss() }); r += ({ x[1]->get_ns() }); r += ({ x[3]->get_ns() }); return r; ]], ({ "urn:loc.gov:books", ([ "bk":"urn:loc.gov:books", "isbn":"urn:ISBN:0-395-36341-6" ]), "urn:loc.gov:books", "urn:ISBN:0-395-36341-6" }) ) // XML NS section 5.2 test_any_equal([[
642b802005-12-18Martin Nilsson object x=Parser.XML.NSTree.parse_input(#"<?xml version=\"1.0\"?>
408f9e2002-08-02Martin Nilsson <!-- initially, the default namespace is \"books\" --> <book xmlns='urn:loc.gov:books' xmlns:isbn='urn:ISBN:0-395-36341-6'> <title>Cheaper by the Dozen</title> <isbn:number>1568491379</isbn:number> <notes> <!-- make HTML the default namespace for some commentary --> <p xmlns='urn:w3-org-ns:HTML'> This is a <i>funny</i> book! </p> </notes> </book>"); x=x[2]; array r = ({}); r += ({ x->get_ns() }); r += ({ x->get_default_ns() }); r += ({ x->get_defined_nss() }); r += ({ x[1]->get_ns() }); r += ({ x[3]->get_ns() }); x=x[5]; r += ({ x[3]->get_ns() }); r += ({ x[3][1]->get_ns() }); r += ({ x[3][1]->get_default_ns() }); return r; ]], ({ "urn:loc.gov:books", "urn:loc.gov:books", ([ "isbn":"urn:ISBN:0-395-36341-6" ]), "urn:loc.gov:books", "urn:ISBN:0-395-36341-6", "urn:w3-org-ns:HTML", "urn:w3-org-ns:HTML", "urn:w3-org-ns:HTML" }) ) // We don't test the case with empty namespace, since it // it is unclear how we should behave. // XML Section 5.3 test_any_equal([[ object x=Parser.XML.NSTree.parse_input(#" <!-- http://www.w3.org is bound to n1 and is the default -->
3524712015-05-26Martin Nilsson <x xmlns:n1=\"http://www.w3.org\"
408f9e2002-08-02Martin Nilsson  xmlns=\"http://www.w3.org\" > <good a=\"1\" n1:a=\"2\" /> </x>"); x=x[1][1]; array r = ({}); r += ({ x->get_ns() }); r += ({ x->get_ns_attributes()[x->get_ns()] }); r += ({ x->get_attributes() }); return r; ]], ({ "http://www.w3.org", (["a":"2"]), (["a":"1"]) }) )
a6b02d2002-08-20Martin Nilsson // End of XML NS spec tests test_do([[ array args = ({ "xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'", "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'", "xmlns:xsd='http://www.w3.org/2001/XMLSchema'",
3524712015-05-26Martin Nilsson  "xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'",
a6b02d2002-08-20Martin Nilsson  "soap:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'" }); for(int i; i<120; i++) Parser.XML.NSTree.parse_input("<soap:Envelope "+Array.permute(args,i)*" "+"/>"); ]])
642b802005-12-18Martin Nilsson 
408f9e2002-08-02Martin Nilsson // Simple
642b802005-12-18Martin Nilsson test_do([[Parser.XML.Simple()->parse("<!DOCTYPE root [\n<!NOTATION JPGformat>\n]>\n", lambda(mixed ...args){} )]]) test_do([[Parser.XML.Simple()->parse_dtd("%hej;\n", lambda(mixed ... args){}, 1, 2, 3)]]) test_any([[ string error; object o = Parser.XML.Simple(); o->compat_allow_errors (0); o->parse("<a></a><foo/>", lambda (string type, string name, mapping attrs, string data) { if (type == "error") error = data; }); return error; ]], "There can not be more than one element on the top level.") test_any([[ string error; object o = Parser.XML.Simple(); o->compat_allow_errors ("7.2"); o->parse("<a></a><foo/>", lambda (string type, string name, mapping attrs, string data) { if (type == "error") error = data; }); return error; ]], 0) test_any([[ string error; object o = Parser.XML.Simple(); o->compat_allow_errors (0); o->parse ("<?xml version='1.0'?> <?herk?> <!-- herk --> " "<!DOCTYPE foo SYSTEM 'blurk.dtd'> <?herk?> <!-- herk --> " "<foo/> <?herk?> <!-- herk --> ", lambda (string type, string name, mapping attrs, string data) { if (type == "error") error = data; }); return error; ]], 0) test_any([[ string error; object o = Parser.XML.Simple(); o->compat_allow_errors (0); o->parse ("<?xml version='1.0'?> <?herk?> <!-- herk --> " "<foo/> <?herk?> <!-- herk --> ", lambda (string type, string name, mapping attrs, string data) { if (type == "error") error = data; }); return error; ]], 0) test_any([[ string error; object o = Parser.XML.Simple(); o->compat_allow_errors (0); o->parse (" <?herk?> <!-- herk --> " "<!DOCTYPE foo SYSTEM 'blurk.dtd'> <?herk?> <!-- herk --> " "<foo/> <?herk?> <!-- herk --> ", lambda (string type, string name, mapping attrs, string data) { if (type == "error") error = data; }); return error; ]], 0) test_any([[ string error; object o = Parser.XML.Simple(); o->compat_allow_errors (0); o->parse (" <?herk?> <!-- herk --> " "<foo/> <?herk?> <!-- herk --> ", lambda (string type, string name, mapping attrs, string data) { if (type == "error") error = data; }); return error; ]], 0) test_any([[ string error; int got_header; object o = Parser.XML.Simple(); o->compat_allow_errors (0); o->parse ("<?xml ?> <?herk?> <!-- herk --> " "<!DOCTYPE foo SYSTEM 'blurk.dtd'> <?herk?> <!-- herk --> " "<foo/> <?herk?> <!-- herk --> ", lambda (string type, string name, mapping attrs, string data) { if (type == "error") error = data; if (type == "<?xml") got_header = 1; }); return error || got_header; ]], "Required version attribute missing in XML header.") test_any([[ string error; int got_header; object o = Parser.XML.Simple(); o->compat_allow_errors ("7.6"); o->parse ("<?xml ?> <?herk?> <!-- herk --> " "<!DOCTYPE foo SYSTEM 'blurk.dtd'> <?herk?> <!-- herk --> " "<foo/> <?herk?> <!-- herk --> ", lambda (string type, string name, mapping attrs, string data) { if (type == "error") error = data; if (type == "<?xml") got_header = 1; }); return error || got_header; ]], 1)
1ef7712006-01-10Henrik Grubbström (Grubba) cond(0, [[ // The following tests are currently not valid. test_any([[ string error; int got_header; object o = Parser.XML.Simple(); o->compat_allow_errors (0); o->parse (" <?xml version='1.0'?> <?herk?> <!-- herk --> " "<!DOCTYPE foo SYSTEM 'blurk.dtd'> <?herk?> <!-- herk --> " "<foo/> <?herk?> <!-- herk --> ", lambda (string type, string name, mapping attrs, string data) { if (type == "error") error = data; if (type == "<?xml") got_header = 1; }); return error || got_header; ]], "XML header must be at the first byte in the document.") test_any([[ string error; int got_header; object o = Parser.XML.Simple(); o->compat_allow_errors ("7.6"); o->parse (" <?xml version='1.0'?> <?herk?> <!-- herk --> " "<!DOCTYPE foo SYSTEM 'blurk.dtd'> <?herk?> <!-- herk --> " "<foo/> <?herk?> <!-- herk --> ", lambda (string type, string name, mapping attrs, string data) { if (type == "error") error = data; if (type == "<?xml") got_header = 1; }); return error || got_header; ]], "XML header must be at the first byte in the document.") test_any([[ string error; int got_header; object o = Parser.XML.Simple(); o->compat_allow_errors (0); o->parse (" <?herk?> <!-- herk --> " "<!DOCTYPE foo SYSTEM 'blurk.dtd'> <?herk?> <!-- herk --> " "<?xml version='1.0'?> <?herk?> <!-- herk --> " "<foo/> <?herk?> <!-- herk --> ", lambda (string type, string name, mapping attrs, string data) { if (type == "error") error = data; if (type == "<?xml") got_header = 1; }); return error || got_header; ]], "XML header must be at the first byte in the document.") test_any([[ string error; int got_header; object o = Parser.XML.Simple(); o->compat_allow_errors ("7.6"); o->parse (" <?herk?> <!-- herk --> " "<!DOCTYPE foo SYSTEM 'blurk.dtd'> <?herk?> <!-- herk --> " "<?xml version='1.0'?> <?herk?> <!-- herk --> " "<foo/> <?herk?> <!-- herk --> ", lambda (string type, string name, mapping attrs, string data) { if (type == "error") error = data; if (type == "<?xml") got_header = 1; }); return error || got_header; ]], "XML header must be at the first byte in the document.") ]])
642b802005-12-18Martin Nilsson  test_any([[ string error; object o = Parser.XML.Simple(); o->compat_allow_errors (0); o->parse ("<?xml version='1.0'?> <?herk?> <!-- herk --> " "<!DOCTYPE foo SYSTEM 'blurk.dtd'> <?herk?> <!-- herk --> " "<!DOCTYPE foo SYSTEM 'blurk.dtd'> <?herk?> <!-- herk --> " "<foo/> <?herk?> <!-- herk --> ", lambda (string type, string name, mapping attrs, string data) { if (type == "error") error = data; }); return error; ]], "Multiple DOCTYPE declarations are not allowed.") test_any([[ string error; object o = Parser.XML.Simple(); o->compat_allow_errors ("7.6"); o->parse ("<?xml version='1.0'?> <?herk?> <!-- herk --> " "<!DOCTYPE foo SYSTEM 'blurk.dtd'> <?herk?> <!-- herk --> " "<!DOCTYPE foo SYSTEM 'blurk.dtd'> <?herk?> <!-- herk --> " "<foo/> <?herk?> <!-- herk --> ", lambda (string type, string name, mapping attrs, string data) { if (type == "error") error = data; }); return error; ]], 0) test_any([[ string error; object o = Parser.XML.Simple(); o->compat_allow_errors (0); o->parse ("<?xml version='1.0'?> <?herk?> <!-- herk --> " "<foo/> <?herk?> <!-- herk --> " "<!DOCTYPE foo SYSTEM 'blurk.dtd'> <?herk?> <!-- herk --> ", lambda (string type, string name, mapping attrs, string data) { if (type == "error") error = data; }); return error; ]], "DOCTYPE must occur before the root element.") test_any([[ string error; object o = Parser.XML.Simple(); o->compat_allow_errors ("7.2"); o->parse ("<?xml version='1.0'?> <?herk?> <!-- herk --> " "<foo/> <?herk?> <!-- herk --> " "<!DOCTYPE foo SYSTEM 'blurk.dtd'> <?herk?> <!-- herk --> ", lambda (string type, string name, mapping attrs, string data) { if (type == "error") error = data; }); return error; ]], 0) test_any([[ string error; object o = Parser.XML.Simple(); o->compat_allow_errors (0); o->parse ("<?xml version='1.0'?> <?herk?> <!-- herk --> " "<foo><!DOCTYPE foo SYSTEM 'blurk.dtd'></foo> <?herk?> <!-- herk --> ", lambda (string type, string name, mapping attrs, string data) { if (type == "error") error = data; }); return error; ]], "DOCTYPE must occur before the root element.") test_any([[ string error; object o = Parser.XML.Simple(); o->compat_allow_errors ("7.6"); o->parse ("<?xml version='1.0'?> <?herk?> <!-- herk --> " "<foo><!DOCTYPE foo SYSTEM 'blurk.dtd'></foo> <?herk?> <!-- herk --> ", lambda (string type, string name, mapping attrs, string data) { if (type == "error") error = data; }); return error; ]], 0) test_any([[ string error; object o = Parser.XML.Simple(); o->compat_allow_errors (0); o->parse ("<?xml version='1.0'?> <?herk?> <!-- herk --> " "<!DOCTYPE foo SYSTEM 'blurk.dtd'> <?herk?> <!-- herk --> ", lambda (string type, string name, mapping attrs, string data) { if (type == "error") error = data; }); return error; ]], "Root element missing.") test_any([[ string error; object o = Parser.XML.Simple(); o->compat_allow_errors ("7.6"); o->parse ("<?xml version='1.0'?> <?herk?> <!-- herk --> " "<!DOCTYPE foo SYSTEM 'blurk.dtd'> <?herk?> <!-- herk --> ", lambda (string type, string name, mapping attrs, string data) { if (type == "error") error = data; }); return error; ]], 0) test_any([[ string error; object o = Parser.XML.Simple(); o->compat_allow_errors (0); o->parse ("<?xml version='1.0'?> <?herk?> <!-- herk --> " "<foo>mupp</foo> <?herk?> <!-- herk --> " "<![CDATA[gnork]""]> <?herk?> <!-- herk --> ", lambda (string type, string name, mapping attrs, string data) { if (type == "error") error = data; }); return error; ]], "All data must be inside tags") test_any([[ string error; object o = Parser.XML.Simple(); o->compat_allow_errors ("7.6"); o->parse ("<?xml version='1.0'?> <?herk?> <!-- herk --> " "<foo>mupp</foo> <?herk?> <!-- herk --> " "<![CDATA[gnork]""]> <?herk?> <!-- herk --> ", lambda (string type, string name, mapping attrs, string data) { if (type == "error") error = data; }); return error; ]], "All data must be inside tags") test_any([[ string error; object o = Parser.XML.Simple(); o->compat_allow_errors ("7.2"); o->parse ("<?xml version='1.0'?> <?herk?> <!-- herk --> " "<foo>mupp</foo> <?herk?> <!-- herk --> " "<![CDATA[gnork]""]> <?herk?> <!-- herk --> ", lambda (string type, string name, mapping attrs, string data) { if (type == "error") error = data; }); return error; ]], 0) test_any([[ string error; object o = Parser.XML.Simple(); o->compat_allow_errors (0); o->parse ("<?xml version='1.0'?> <?herk?> <!-- herk --> " "<![CDATA[gnork]""]> <?herk?> <!-- herk --> " "<foo>mupp</foo> <?herk?> <!-- herk --> ", lambda (string type, string name, mapping attrs, string data) { if (type == "error") error = data; }); return error; ]], "All data must be inside tags") test_any([[ string error; object o = Parser.XML.Simple(); o->compat_allow_errors ("7.6"); o->parse ("<?xml version='1.0'?> <?herk?> <!-- herk --> " "<![CDATA[gnork]""]> <?herk?> <!-- herk --> " "<foo>mupp</foo> <?herk?> <!-- herk --> ", lambda (string type, string name, mapping attrs, string data) { if (type == "error") error = data; }); return error; ]], 0) test_any([[ string error; object o = Parser.XML.Simple(); o->compat_allow_errors ("7.2"); o->parse ("<?xml version='1.0'?> <?herk?> <!-- herk --> " "<![CDATA[gnork]""]> <?herk?> <!-- herk --> " "<foo>mupp</foo> <?herk?> <!-- herk --> ", lambda (string type, string name, mapping attrs, string data) { if (type == "error") error = data; }); return error; ]], 0) test_any([[ string error; object o = Parser.XML.Simple(); o->compat_allow_errors (0); o->parse ("<?xml version='1.0'?> <?herk?> <!-- herk --> " "<foo>mupp</foo> <?herk?> <!-- herk --> " "gnork <?herk?> <!-- herk --> ", lambda (string type, string name, mapping attrs, string data) { if (type == "error") error = data; }); return error; ]], "All data must be inside tags") test_any([[ string error; object o = Parser.XML.Simple(); o->compat_allow_errors ("7.6"); o->parse ("<?xml version='1.0'?> <?herk?> <!-- herk --> " "<foo>mupp</foo> <?herk?> <!-- herk --> " "gnork <?herk?> <!-- herk --> ", lambda (string type, string name, mapping attrs, string data) { if (type == "error") error = data; }); return error; ]], "All data must be inside tags") test_any([[ string error; object o = Parser.XML.Simple(); o->compat_allow_errors ("7.2"); o->parse ("<?xml version='1.0'?> <?herk?> <!-- herk --> " "<foo>mupp</foo> <?herk?> <!-- herk --> " "gnork <?herk?> <!-- herk --> ", lambda (string type, string name, mapping attrs, string data) { if (type == "error") error = data; }); return error; ]], "All data must be inside tags")
408f9e2002-08-02Martin Nilsson // Validating
1169d92004-05-02Martin Nilsson END_MARKER