1 USING: accessors assocs combinators continuations fry generalizations
2 io.pathnames kernel macros sequences stack-checker tools.test xml
3 xml.traversal xml.writer arrays xml.data ;
6 TUPLE: xml-test id uri sections description type ;
8 : >xml-test ( tag -- test )
10 [ "TYPE" attr >>type ]
13 [ "SECTIONS" attr >>sections ]
14 [ children>> xml>string >>description ]
17 : parse-tests ( xml -- tests )
18 "TEST" tags-named [ >xml-test ] map ;
20 : base "vocab:xml/tests/xmltest/" ;
22 MACRO: drop-output ( quot -- newquot )
23 dup infer out>> '[ @ _ ndrop ] ;
25 MACRO: drop-input ( quot -- newquot )
26 infer in>> '[ _ ndrop ] ;
28 : fails? ( quot -- ? )
29 [ '[ _ drop-output f ] ]
30 [ '[ drop _ drop-input t ] ] bi recover ; inline
32 : well-formed? ( uri -- answer )
33 [ file>xml ] fails? "not-wf" "valid" ? ;
35 : test-quots ( test -- result quot )
37 [ '[ _ uri>> base swap append-path well-formed? ] ] bi ;
39 : xml-tests ( -- tests )
40 base "xmltest.xml" append-path file>xml
41 parse-tests [ test-quots 2array ] map ;
43 : run-xml-tests ( -- )
44 xml-tests [ unit-test ] assoc-each ;
46 : works? ( result quot -- ? )
47 [ first ] [ call ] bi* = ;
49 : partition-xml-tests ( -- successes failures )
50 xml-tests [ first2 works? ] partition ;
52 : failing-valids ( -- tests )
53 partition-xml-tests nip [ second first ] map [ type>> "valid" = ] filter ;
55 [ ] [ partition-xml-tests 2drop ] unit-test