2009-01-21 19:16:51 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								! Copyright (C) 2005, 2009 Daniel Ehrenberg
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								! See http://factorcode.org/license.txt for BSD license.
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-20 04:28:03 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								USING: xml.data xml.writer tools.test fry xml xml.syntax kernel multiline
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-05 22:17:03 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								xml.writer.private io.streams.string xml.traversal sequences
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-20 04:28:03 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								io.encodings.utf8 io.files accessors io.directories math math.parser ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-09-08 03:52:42 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								IN: xml.writer.tests
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-21 19:16:51 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-29 14:33:04 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								! Add a test for pprint-xml with sensitive-tags
							 | 
						
					
						
							
								
									
										
										
										
											2008-09-08 03:52:42 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								[ "foo" ] [ T{ name { main "foo" } } name>string ] unit-test
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-21 19:16:51 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								[ "foo" ] [ T{ name { space "" } { main "foo" } } name>string ] unit-test
							 | 
						
					
						
							
								
									
										
										
										
											2008-09-08 03:52:42 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								[ "ns:foo" ] [ T{ name { space "ns" } { main "foo" } } name>string ] unit-test
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-21 19:16:51 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: reprints-as ( to from -- )
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-02 14:43:54 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								     [ ] [ string>xml xml>string ] bi-curry* unit-test ;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-21 19:16:51 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: pprint-reprints-as ( to from -- )
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-02 14:43:54 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								     [ ] [ string>xml pprint-xml>string ] bi-curry* unit-test ;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-21 19:16:51 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: reprints-same ( string -- ) dup reprints-as ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								"<?xml version=\"1.0\" encoding=\"UTF-8\"?><x/>" reprints-same
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-09-20 23:42:40 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								"""<?xml version="1.0" encoding="UTF-8"?>
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-21 19:16:51 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								<!DOCTYPE foo [<!ENTITY foo "bar">]>
							 | 
						
					
						
							
								
									
										
										
										
											2009-09-20 23:42:40 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								<x>bar</x>"""
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								"""<?xml version="1.0" encoding="UTF-8"?>
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-21 19:16:51 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								<!DOCTYPE foo [<!ENTITY foo 'bar'>]>
							 | 
						
					
						
							
								
									
										
										
										
											2009-09-20 23:42:40 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								<x>&foo;</x>""" reprints-as
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-21 19:16:51 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-09-20 23:42:40 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								"""<?xml version="1.0" encoding="UTF-8"?>
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-21 19:16:51 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								<!DOCTYPE foo [
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  <!ENTITY foo "bar">
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  <!ELEMENT br EMPTY>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  <!ATTLIST list type    (bullets|ordered|glossary)  "ordered">
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  <!NOTATION foo bar>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  <?baz bing bang bong?>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  <!--wtf-->
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								]>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								<x>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  bar
							 | 
						
					
						
							
								
									
										
										
										
											2009-09-20 23:42:40 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								</x>"""
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								"""<?xml version="1.0" encoding="UTF-8"?>
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-21 19:16:51 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								<!DOCTYPE foo [ <!ENTITY foo 'bar'> <!ELEMENT br EMPTY>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								<!ATTLIST list
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          type    (bullets|ordered|glossary)  "ordered">
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								<!NOTATION 	foo bar> <?baz bing bang bong?>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      		<!--wtf-->
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								]>
							 | 
						
					
						
							
								
									
										
										
										
											2009-09-20 23:42:40 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								<x>&foo;</x>""" pprint-reprints-as
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-21 19:16:51 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-29 14:33:04 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								[ 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
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-21 19:16:51 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								[ "<?xml version=\"1.0\" encoding=\"UTF-8\"?><a b=\"c\"/>" ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [ "<a b='c'/>" string>xml xml>string ] unit-test
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								[ "<?xml version=\"1.0\" encoding=\"UTF-8\"?><foo>bar baz</foo>" ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								[ "<foo>bar</foo>" string>xml [ " baz" append ] map xml>string ] unit-test
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								[ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<foo>\n  bar\n</foo>" ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								[ "<foo>         bar            </foo>" string>xml pprint-xml>string ] unit-test
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-29 14:33:04 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								[ "<foo'>" ] [ "<foo'>" <unescaped> xml>string ] unit-test
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-04 13:32:47 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-22 19:37:28 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								CONSTANT: test-file "resource:basis/xml/writer/test.xml"
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-04 13:32:47 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								[ ] [ "<?xml version='1.0' encoding='UTF-16BE'?><x/>" 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
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-20 04:28:03 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								[ ] [
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    { 1 2 3 4 } [
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        [ number>string ] [ sq number>string ] bi
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        [XML <tr><td><-></td><td><-></td></tr> XML]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ] map [XML <h2>Timings</h2> <table><-></table> XML]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    pprint-xml
							 | 
						
					
						
							
								
									
										
										
										
											2009-09-20 23:42:40 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								] unit-test
							 |