| 
									
										
										
										
											2009-01-27 15:33:43 -05:00
										 |  |  | ! Copyright (C) 2005, 2009 Daniel Ehrenberg | 
					
						
							| 
									
										
										
										
											2007-12-23 14:57:39 -05:00
										 |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2008-03-01 17:00:45 -05:00
										 |  |  | IN: xml.tests | 
					
						
							| 
									
										
										
										
											2008-09-11 01:20:06 -04:00
										 |  |  | USING: kernel xml tools.test io namespaces make sequences | 
					
						
							| 
									
										
										
										
											2009-01-15 23:20:24 -05:00
										 |  |  | xml.errors xml.entities.html parser strings xml.data io.files | 
					
						
							| 
									
										
										
										
											2009-02-13 16:10:34 -05:00
										 |  |  | xml.traversal continuations assocs io.encodings.binary | 
					
						
							| 
									
										
										
										
											2008-12-02 20:59:16 -05:00
										 |  |  | sequences.deep accessors io.streams.string ;
 | 
					
						
							| 
									
										
										
										
											2007-12-23 14:57:39 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! This is insufficient | 
					
						
							| 
									
										
										
										
											2009-01-27 15:15:00 -05:00
										 |  |  | [ [ drop ] each-element ] must-infer | 
					
						
							| 
									
										
										
										
											2008-04-14 07:04:01 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-23 14:57:39 -05:00
										 |  |  | SYMBOL: xml-file | 
					
						
							| 
									
										
										
										
											2009-02-13 16:10:34 -05:00
										 |  |  | [ ] [ | 
					
						
							| 
									
										
										
										
											2009-02-15 20:53:21 -05:00
										 |  |  |     "vocab:xml/tests/test.xml" | 
					
						
							| 
									
										
										
										
											2009-02-13 16:10:34 -05:00
										 |  |  |     [ file>xml ] with-html-entities xml-file set
 | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | [ t ] [ | 
					
						
							| 
									
										
										
										
											2009-02-15 20:53:21 -05:00
										 |  |  |     "vocab:xml/tests/test.xml" binary file-contents | 
					
						
							| 
									
										
										
										
											2009-02-13 16:10:34 -05:00
										 |  |  |     [ bytes>xml ] with-html-entities xml-file get =
 | 
					
						
							|  |  |  | ] unit-test | 
					
						
							| 
									
										
										
										
											2008-08-28 18:23:33 -04:00
										 |  |  | [ "1.0" ] [ xml-file get prolog>> version>> ] unit-test | 
					
						
							|  |  |  | [ f ] [ xml-file get prolog>> standalone>> ] unit-test | 
					
						
							|  |  |  | [ "a" ] [ xml-file get space>> ] unit-test | 
					
						
							|  |  |  | [ "http://www.hello.com" ] [ xml-file get url>> ] unit-test | 
					
						
							| 
									
										
										
										
											2007-12-23 14:57:39 -05:00
										 |  |  | [ "that" ] [ | 
					
						
							| 
									
										
										
										
											2009-01-28 15:33:33 -05:00
										 |  |  |     xml-file get T{ name f "" "this" "http://d.de" } attr | 
					
						
							| 
									
										
										
										
											2007-12-23 14:57:39 -05:00
										 |  |  | ] unit-test | 
					
						
							| 
									
										
										
										
											2008-08-28 18:23:33 -04:00
										 |  |  | [ t ] [ xml-file get children>> second contained-tag? ] unit-test | 
					
						
							| 
									
										
										
										
											2009-01-26 17:11:30 -05:00
										 |  |  | [ "<a></b>" string>xml ] [ xml-error? ] must-fail-with | 
					
						
							| 
									
										
										
										
											2007-12-23 14:57:39 -05:00
										 |  |  | [ T{ comment f "This is where the fun begins!" } ] [ | 
					
						
							| 
									
										
										
										
											2008-09-01 22:36:34 -04:00
										 |  |  |     xml-file get before>> [ comment? ] find nip
 | 
					
						
							| 
									
										
										
										
											2007-12-23 14:57:39 -05:00
										 |  |  | ] unit-test | 
					
						
							|  |  |  | [ "xsl stylesheet=\"that-one.xsl\"" ] [ | 
					
						
							| 
									
										
										
										
											2008-08-28 18:23:33 -04:00
										 |  |  |     xml-file get after>> [ instruction? ] find nip text>> | 
					
						
							| 
									
										
										
										
											2007-12-23 14:57:39 -05:00
										 |  |  | ] unit-test | 
					
						
							| 
									
										
										
										
											2008-08-28 18:23:33 -04:00
										 |  |  | [ V{ "fa&g" } ] [ xml-file get "x" get-id children>> ] unit-test | 
					
						
							| 
									
										
										
										
											2009-01-28 15:33:33 -05:00
										 |  |  | [ "that" ] [ xml-file get "this" attr ] unit-test | 
					
						
							| 
									
										
										
										
											2007-12-23 14:57:39 -05:00
										 |  |  | [ "abcd" ] [ | 
					
						
							|  |  |  |     "<main>a<sub>bc</sub>d<nothing/></main>" string>xml | 
					
						
							|  |  |  |     [ [ dup string? [ % ] [ drop ] if ] deep-each ] "" make | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | [ "abcd" ] [ | 
					
						
							|  |  |  |     "<main>a<sub>bc</sub>d<nothing/></main>" string>xml | 
					
						
							| 
									
										
										
										
											2008-04-26 00:17:08 -04:00
										 |  |  |     [ string? ] deep-filter concat
 | 
					
						
							| 
									
										
										
										
											2007-12-23 14:57:39 -05:00
										 |  |  | ] unit-test | 
					
						
							|  |  |  | [ "foo" ] [ | 
					
						
							|  |  |  |     "<a><b id='c'>foo</b><d id='e'/></a>" string>xml | 
					
						
							|  |  |  |     "c" get-id children>string | 
					
						
							|  |  |  | ] unit-test | 
					
						
							| 
									
										
										
										
											2009-01-28 15:33:33 -05:00
										 |  |  | [ "foo" ] [ | 
					
						
							|  |  |  |     "<x y='foo'/>" string>xml | 
					
						
							|  |  |  |     dup dup "y" attr "z" set-attr | 
					
						
							|  |  |  |     T{ name { space "blah" } { main "z" } } attr | 
					
						
							|  |  |  | ] unit-test | 
					
						
							| 
									
										
										
										
											2007-10-12 16:28:23 -04:00
										 |  |  | [ "foo" ] [ "<boo><![CDATA[foo]]></boo>" string>xml children>string ] unit-test | 
					
						
							| 
									
										
										
										
											2008-12-02 20:59:16 -05:00
										 |  |  | [ "<!-- B+, B, or B--->" string>xml ] must-fail | 
					
						
							|  |  |  | [ ] [ "<?xml version='1.0'?><!-- declarations for <head> & <body> --><foo/>" string>xml drop ] unit-test | 
					
						
							| 
									
										
										
										
											2009-01-29 17:57:13 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : first-thing ( seq -- elt )
 | 
					
						
							|  |  |  |     [ "" = not ] filter first ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ T{ element-decl f "br" "EMPTY" } ] [ "<!ELEMENT br EMPTY>" string>dtd directives>> first-thing ] unit-test | 
					
						
							|  |  |  | [ T{ element-decl f "p" "(#PCDATA|emph)*" } ] [ "<!ELEMENT p (#PCDATA|emph)*>" string>dtd directives>> first-thing ] unit-test | 
					
						
							|  |  |  | [ T{ element-decl f "%name.para;" "%content.para;" } ] [ "<!ELEMENT %name.para; %content.para;>" string>dtd directives>> first-thing ] unit-test | 
					
						
							|  |  |  | [ T{ element-decl f "container" "ANY" } ] [ "<!ELEMENT container ANY>" string>dtd directives>> first-thing ] unit-test | 
					
						
							|  |  |  | [ T{ doctype-decl f "foo" } ] [ "<!DOCTYPE foo>" string>xml-chunk first-thing ] unit-test | 
					
						
							|  |  |  | [ T{ doctype-decl f "foo" } ] [ "<!DOCTYPE foo >" string>xml-chunk first-thing ] unit-test | 
					
						
							|  |  |  | [ T{ doctype-decl f "foo" T{ system-id f "blah.dtd" } } ] [ "<!DOCTYPE foo SYSTEM 'blah.dtd'>" string>xml-chunk first-thing ] unit-test | 
					
						
							|  |  |  | [ T{ doctype-decl f "foo" T{ system-id f "blah.dtd" } } ] [ "<!DOCTYPE foo   SYSTEM \"blah.dtd\"   >" string>xml-chunk first-thing ] unit-test | 
					
						
							| 
									
										
										
										
											2009-01-19 23:25:15 -05:00
										 |  |  | [ 958 ] [ [ "ξ" string>xml-chunk ] with-html-entities first first ] unit-test | 
					
						
							| 
									
										
										
										
											2009-01-28 15:33:33 -05:00
										 |  |  | [ "x" "<" ] [ "<x value='<'/>" string>xml [ name>> main>> ] [ "value" attr ] bi ] unit-test | 
					
						
							| 
									
										
										
										
											2009-01-22 17:31:22 -05:00
										 |  |  | [ "foo" ] [ "<!DOCTYPE foo [<!ENTITY bar 'foo'>]><x>&bar;</x>" string>xml children>string ] unit-test | 
					
						
							| 
									
										
										
										
											2009-01-28 15:33:33 -05:00
										 |  |  | [ T{ xml-chunk f V{ "hello" } } ] [ "hello" string>xml-chunk ] unit-test | 
					
						
							| 
									
										
										
										
											2009-02-04 13:32:47 -05:00
										 |  |  | [ "1.1" ] [ "<?xml version='1.1'?><x/>" string>xml prolog>> version>> ] unit-test | 
					
						
							| 
									
										
										
										
											2009-03-16 19:28:15 -04:00
										 |  |  | [ "ß" ] [ "<x>ß</x>" <string-reader> read-xml children>string ] unit-test | 
					
						
							| 
									
										
										
										
											2009-07-22 19:48:38 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! <pull-xml> tests | 
					
						
							|  |  |  | ! this tests just checks that pull-event doesn't raise an exception | 
					
						
							|  |  |  | [ ] [ "vocab:xml/tests/test.xml" binary [ <pull-xml> pull-event drop ] with-file-reader ] unit-test |