| 
									
										
										
										
											2010-01-14 10:10:13 -05:00
										 |  |  | USING: accessors assocs combinators combinators.smart | 
					
						
							|  |  |  | continuations fry generalizations io.pathnames kernel macros | 
					
						
							|  |  |  | sequences stack-checker tools.test xml xml.traversal xml.writer | 
					
						
							|  |  |  | arrays xml.data ;
 | 
					
						
							| 
									
										
										
										
											2009-01-19 23:25:15 -05:00
										 |  |  | IN: xml.tests.suite | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-20 16:37:21 -05:00
										 |  |  | TUPLE: xml-test id uri sections description type ;
 | 
					
						
							| 
									
										
										
										
											2009-01-19 23:25:15 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-20 16:37:21 -05:00
										 |  |  | : >xml-test ( tag -- test )
 | 
					
						
							|  |  |  |     xml-test new swap { | 
					
						
							| 
									
										
										
										
											2009-01-28 15:33:33 -05:00
										 |  |  |         [ "TYPE" attr >>type ] | 
					
						
							|  |  |  |         [ "ID" attr >>id ] | 
					
						
							|  |  |  |         [ "URI" attr >>uri ] | 
					
						
							|  |  |  |         [ "SECTIONS" attr >>sections ] | 
					
						
							| 
									
										
										
										
											2009-01-29 14:33:04 -05:00
										 |  |  |         [ children>> xml>string >>description ] | 
					
						
							| 
									
										
										
										
											2009-01-19 23:25:15 -05:00
										 |  |  |     } cleave ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : parse-tests ( xml -- tests )
 | 
					
						
							| 
									
										
										
										
											2009-01-20 16:37:21 -05:00
										 |  |  |     "TEST" tags-named [ >xml-test ] map ;
 | 
					
						
							| 
									
										
										
										
											2009-01-19 23:25:15 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-22 19:37:28 -04:00
										 |  |  | CONSTANT: base "vocab:xml/tests/xmltest/" | 
					
						
							| 
									
										
										
										
											2009-01-19 23:25:15 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : fails? ( quot -- ? )
 | 
					
						
							| 
									
										
										
										
											2010-01-14 10:10:13 -05:00
										 |  |  |     [ drop-outputs f ] [ nip drop-inputs t ] bi-curry recover ; inline
 | 
					
						
							| 
									
										
										
										
											2009-01-19 23:25:15 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : well-formed? ( uri -- answer )
 | 
					
						
							|  |  |  |     [ file>xml ] fails? "not-wf" "valid" ? ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-20 16:37:21 -05:00
										 |  |  | : test-quots ( test -- result quot )
 | 
					
						
							| 
									
										
										
										
											2009-01-19 23:25:15 -05:00
										 |  |  |     [ type>> '[ _ ] ] | 
					
						
							| 
									
										
										
										
											2009-01-20 16:37:21 -05:00
										 |  |  |     [ '[ _ uri>> base swap append-path well-formed? ] ] bi ;
 | 
					
						
							| 
									
										
										
										
											2009-01-19 23:25:15 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-20 16:37:21 -05:00
										 |  |  | : xml-tests ( -- tests )
 | 
					
						
							| 
									
										
										
										
											2009-01-19 23:25:15 -05:00
										 |  |  |     base "xmltest.xml" append-path file>xml | 
					
						
							| 
									
										
										
										
											2009-01-20 16:37:21 -05:00
										 |  |  |     parse-tests [ test-quots 2array ] map ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : run-xml-tests ( -- )
 | 
					
						
							|  |  |  |     xml-tests [ unit-test ] assoc-each ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : works? ( result quot -- ? )
 | 
					
						
							| 
									
										
										
										
											2009-04-20 04:27:52 -04:00
										 |  |  |     [ first ] [ call( -- result ) ] bi* = ;
 | 
					
						
							| 
									
										
										
										
											2009-01-20 16:37:21 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : partition-xml-tests ( -- successes failures )
 | 
					
						
							|  |  |  |     xml-tests [ first2 works? ] partition ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : failing-valids ( -- tests )
 | 
					
						
							|  |  |  |     partition-xml-tests nip [ second first ] map [ type>> "valid" = ] filter ;
 | 
					
						
							| 
									
										
										
										
											2009-01-28 15:33:33 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | [ ] [ partition-xml-tests 2drop ] unit-test |