]> gitweb.factorcode.org Git - factor.git/blob - basis/xml/writer/writer-tests.factor
Fix conflict
[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 io.encodings.utf8 io.files accessors io.directories ;
6 IN: xml.writer.tests
7
8 \ write-xml must-infer
9 \ xml>string must-infer
10 \ pprint-xml must-infer
11 ! Add a test for pprint-xml with sensitive-tags
12
13 [ "foo" ] [ T{ name { main "foo" } } name>string ] unit-test
14 [ "foo" ] [ T{ name { space "" } { main "foo" } } name>string ] unit-test
15 [ "ns:foo" ] [ T{ name { space "ns" } { main "foo" } } name>string ] unit-test
16
17 : reprints-as ( to from -- )
18      [ ] [ string>xml xml>string ] bi-curry* unit-test ;
19
20 : pprint-reprints-as ( to from -- )
21      [ ] [ string>xml pprint-xml>string ] bi-curry* unit-test ;
22
23 : reprints-same ( string -- ) dup reprints-as ;
24
25 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><x/>" reprints-same
26
27 {" <?xml version="1.0" encoding="UTF-8"?>
28 <!DOCTYPE foo [<!ENTITY foo "bar">]>
29 <x>bar</x> "}
30 {" <?xml version="1.0" encoding="UTF-8"?>
31 <!DOCTYPE foo [<!ENTITY foo 'bar'>]>
32 <x>&foo;</x> "} reprints-as
33
34 {" <?xml version="1.0" encoding="UTF-8"?>
35 <!DOCTYPE foo [
36   <!ENTITY foo "bar">
37   <!ELEMENT br EMPTY>
38   <!ATTLIST list type    (bullets|ordered|glossary)  "ordered">
39   <!NOTATION foo bar>
40   <?baz bing bang bong?>
41   <!--wtf-->
42 ]>
43 <x>
44   bar
45 </x>"}
46 {" <?xml version="1.0" encoding="UTF-8"?>
47 <!DOCTYPE foo [ <!ENTITY foo 'bar'> <!ELEMENT br EMPTY>
48 <!ATTLIST list
49           type    (bullets|ordered|glossary)  "ordered">
50 <!NOTATION      foo bar> <?baz bing bang bong?>
51                 <!--wtf-->
52 ]>
53 <x>&foo;</x>"} pprint-reprints-as
54
55 [ 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
56 [ "<?xml version=\"1.0\" encoding=\"UTF-8\"?><a b=\"c\"/>" ]
57     [ "<a b='c'/>" string>xml xml>string ] unit-test
58 [ "<?xml version=\"1.0\" encoding=\"UTF-8\"?><foo>bar baz</foo>" ]
59 [ "<foo>bar</foo>" string>xml [ " baz" append ] map xml>string ] unit-test
60 [ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<foo>\n  bar\n</foo>" ]
61 [ "<foo>         bar            </foo>" string>xml pprint-xml>string ] unit-test
62 [ "<foo'>" ] [ "<foo'>" <unescaped> xml>string ] unit-test
63
64 : test-file "resource:basis/xml/writer/test.xml" ;
65
66 [ ] [ "<?xml version='1.0' encoding='UTF-16BE'?><x/>" string>xml test-file utf8 [ write-xml ] with-file-writer ] unit-test
67 [ "x" ] [ test-file file>xml body>> name>> main>> ] unit-test
68 [ ] [ test-file delete-file ] unit-test