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