1 ! Copyright (C) 2005, 2009 Daniel Ehrenberg
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: xml.data xml.writer tools.test fry xml kernel multiline
4 xml.writer.private io.streams.string xml.utilities sequences ;
8 \ xml>string must-infer
9 \ pprint-xml must-infer
10 ! Add a test for pprint-xml with sensitive-tags
12 [ "foo" ] [ T{ name { main "foo" } } name>string ] unit-test
13 [ "foo" ] [ T{ name { space "" } { main "foo" } } name>string ] unit-test
14 [ "ns:foo" ] [ T{ name { space "ns" } { main "foo" } } name>string ] unit-test
16 : reprints-as ( to from -- )
17 [ '[ _ ] ] [ '[ _ string>xml xml>string ] ] bi* unit-test ;
19 : pprint-reprints-as ( to from -- )
20 [ '[ _ ] ] [ '[ _ string>xml pprint-xml>string ] ] bi* unit-test ;
22 : reprints-same ( string -- ) dup reprints-as ;
24 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><x/>" reprints-same
26 {" <?xml version="1.0" encoding="UTF-8"?>
27 <!DOCTYPE foo [<!ENTITY foo "bar">]>
29 {" <?xml version="1.0" encoding="UTF-8"?>
30 <!DOCTYPE foo [<!ENTITY foo 'bar'>]>
31 <x>&foo;</x> "} reprints-as
33 {" <?xml version="1.0" encoding="UTF-8"?>
37 <!ATTLIST list type (bullets|ordered|glossary) "ordered">
39 <?baz bing bang bong?>
45 {" <?xml version="1.0" encoding="UTF-8"?>
46 <!DOCTYPE foo [ <!ENTITY foo 'bar'> <!ELEMENT br EMPTY>
48 type (bullets|ordered|glossary) "ordered">
49 <!NOTATION foo bar> <?baz bing bang bong?>
52 <x>&foo;</x>"} pprint-reprints-as
54 [ t ] [ "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\" >" dup string>xml-chunk xml>string = ] unit-test
55 [ "<?xml version=\"1.0\" encoding=\"UTF-8\"?><a b=\"c\"/>" ]
56 [ "<a b='c'/>" string>xml xml>string ] unit-test
57 [ "<?xml version=\"1.0\" encoding=\"UTF-8\"?><foo>bar baz</foo>" ]
58 [ "<foo>bar</foo>" string>xml [ " baz" append ] map xml>string ] unit-test
59 [ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<foo>\n bar\n</foo>" ]
60 [ "<foo> bar </foo>" string>xml pprint-xml>string ] unit-test
61 [ "<foo'>" ] [ "<foo'>" <unescaped> xml>string ] unit-test