]> gitweb.factorcode.org Git - factor.git/blob - basis/xml/writer/writer-tests.factor
Merge branch 'master' into experimental
[factor.git] / basis / xml / writer / writer-tests.factor
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 ;
5 IN: xml.writer.tests
6
7 \ write-xml must-infer
8 \ xml>string must-infer
9 \ pprint-xml must-infer
10 ! Add a test for pprint-xml with sensitive-tags
11
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
15
16 : reprints-as ( to from -- )
17      [ '[ _ ] ] [ '[ _ string>xml xml>string ] ] bi* unit-test ;
18
19 : pprint-reprints-as ( to from -- )
20      [ '[ _ ] ] [ '[ _ string>xml pprint-xml>string ] ] bi* unit-test ;
21
22 : reprints-same ( string -- ) dup reprints-as ;
23
24 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><x/>" reprints-same
25
26 {" <?xml version="1.0" encoding="UTF-8"?>
27 <!DOCTYPE foo [<!ENTITY foo "bar">]>
28 <x>bar</x> "}
29 {" <?xml version="1.0" encoding="UTF-8"?>
30 <!DOCTYPE foo [<!ENTITY foo 'bar'>]>
31 <x>&foo;</x> "} reprints-as
32
33 {" <?xml version="1.0" encoding="UTF-8"?>
34 <!DOCTYPE foo [
35   <!ENTITY foo "bar">
36   <!ELEMENT br EMPTY>
37   <!ATTLIST list type    (bullets|ordered|glossary)  "ordered">
38   <!NOTATION foo bar>
39   <?baz bing bang bong?>
40   <!--wtf-->
41 ]>
42 <x>
43   bar
44 </x>"}
45 {" <?xml version="1.0" encoding="UTF-8"?>
46 <!DOCTYPE foo [ <!ENTITY foo 'bar'> <!ELEMENT br EMPTY>
47 <!ATTLIST list
48           type    (bullets|ordered|glossary)  "ordered">
49 <!NOTATION      foo bar> <?baz bing bang bong?>
50                 <!--wtf-->
51 ]>
52 <x>&foo;</x>"} pprint-reprints-as
53
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