Revert "lists: Add list literal doc example."
[factor.git] / basis / xml / tests / templating.factor
blob7f7d8d28918e73ecefb1d4745d95fb0c72d378fa
1 USING: kernel xml sequences assocs tools.test io arrays namespaces fry
2 accessors xml.data xml.traversal xml.writer generic sequences.deep multiline ;
3 IN: xml.tests
5 CONSTANT: sub-tag
6     T{ name f f "sub" "http://littledan.onigirihouse.com/namespaces/replace" }
8 SYMBOL: ref-table
10 GENERIC: (r-ref) ( xml -- )
11 M: tag (r-ref)
12     dup sub-tag attr [
13         ref-table get at
14         >>children drop
15     ] [ drop ] if* ;
16 M: object (r-ref) drop ;
18 : template ( xml -- )
19     [ (r-ref) ] deep-each ;
21 ! Example
23 STRING: sample-doc
24 <html xmlns:f='http://littledan.onigirihouse.com/namespaces/replace'>
25 <body>
26 <span f:sub='foo'/>
27 <div f:sub='bar'/>
28 <p f:sub='baz'>paragraph</p>
29 </body></html>
32 STRING: expected-result
33 <?xml version="1.0" encoding="UTF-8"?>
34 <html xmlns:f="http://littledan.onigirihouse.com/namespaces/replace">
35   <body>
36     <span f:sub="foo">
37       foo
38     </span>
39     <div f:sub="bar">
40       blah
41       <a/>
42     </div>
43     <p f:sub="baz"/>
44   </body>
45 </html>
48 : test-refs ( -- string )
49     [
50         H{
51             { "foo" { "foo" } }
52             { "bar" { "blah" T{ tag f T{ name f "" "a" "" } T{ attrs } f } } }
53             { "baz" f }
54         } ref-table set
55         sample-doc string>xml dup template pprint-xml>string
56     ] with-scope ;
58 expected-result '[ _ ] [ test-refs ] unit-test