! Copyright (C) 2005, 2009 Daniel Ehrenberg
! See http://factorcode.org/license.txt for BSD license.
USING: xml.data xml.writer tools.test fry xml xml.syntax kernel multiline
xml.writer.private io.streams.string xml.traversal sequences
io.encodings.utf8 io.files io.files.temp accessors io.directories math
math.parser ;
IN: xml.writer.tests
! Add a test for pprint-xml with sensitive-tags
[ "foo" ] [ T{ name { main "foo" } } name>string ] unit-test
[ "foo" ] [ T{ name { space "" } { main "foo" } } name>string ] unit-test
[ "ns:foo" ] [ T{ name { space "ns" } { main "foo" } } name>string ] unit-test
: reprints-as ( to from -- )
[ ] [ string>xml xml>string ] bi-curry* unit-test ;
: pprint-reprints-as ( to from -- )
[ ] [ string>xml pprint-xml>string ] bi-curry* unit-test ;
: reprints-same ( string -- ) dup reprints-as ;
"" reprints-same
"""
]>
bar"""
"""
]>
&foo;""" reprints-as
"""
]>
bar
"""
"""
]>
&foo;""" pprint-reprints-as
[ t ] [ "" dup string>xml-chunk xml>string = ] unit-test
[ "" ]
[ "" string>xml xml>string ] unit-test
[ "bar baz" ]
[ "bar" string>xml [ " baz" append ] map xml>string ] unit-test
[ "\n\n bar\n" ]
[ " bar " string>xml pprint-xml>string ] unit-test
[ "" ] [ "" xml>string ] unit-test
: test-file ( -- path )
"test.xml" temp-file ;
[ ] [
"" string>xml test-file utf8 [ write-xml ] with-file-writer
] unit-test
[ "x" ] [ test-file file>xml body>> name>> main>> ] unit-test
[ ] [ test-file delete-file ] unit-test
[ ] [
{ 1 2 3 4 } [
[ number>string ] [ sq number>string ] bi
[XML <-> | <-> |
XML]
] map [XML Timings
XML]
pprint-xml
] unit-test