1 USING: html.templates html.templates.chloe
2 tools.test io.streams.string kernel sequences ascii boxes
3 namespaces xml html.components html.forms
4 splitting unicode.categories furnace accessors ;
5 IN: html.templates.chloe.tests
10 with-string-writer [ "\r\n\t" member? not ] filter
11 "?>" split1 nip ; inline
13 : test-template ( name -- template )
14 "resource:basis/html/templates/chloe/test/"
19 "test1" test-template call-template
23 [ "Blah blah" "Hello world" ] [
27 "test2" test-template call-template
33 [ "<html><head><title>Hello world</title></head><body>Blah blah</body></html>" ] [
36 "test2" test-template call-template
37 ] "test3" test-template with-boilerplate
45 "test4" test-template call-template
53 "test5" test-template call-template
57 [ ] [ begin-form ] unit-test
59 [ ] [ "A label" "label" set-value ] unit-test
63 M: link-test link-title drop "<Link Title>" ;
65 M: link-test link-href drop "http://www.apple.com/foo&bar" ;
67 [ ] [ link-test "link" set-value ] unit-test
69 [ ] [ "int x = 5;" "code" set-value ] unit-test
71 [ ] [ "c" "mode" set-value ] unit-test
73 [ ] [ { 1 2 3 } "inspector" set-value ] unit-test
75 [ ] [ "<p>a paragraph</p>" "html" set-value ] unit-test
77 [ ] [ "sheeple" "field" set-value ] unit-test
79 [ ] [ "a password" "password" set-value ] unit-test
81 [ ] [ "a\nb\nc" "textarea" set-value ] unit-test
83 [ ] [ "new york" "choice" set-value ] unit-test
85 [ ] [ { "new york" "detroit" "minneapolis" } "choices" set-value ] unit-test
89 "test8" test-template call-template
93 [ ] [ { 1 2 3 } "numbers" set-value ] unit-test
95 [ "<ul><li>1</li><li>2</li><li>3</li></ul>" ] [
97 "test7" test-template call-template
98 ] run-template [ blank? not ] filter
101 TUPLE: person first-name last-name ;
105 T{ person f "RBaxter" "Unknown" }
106 T{ person f "Doug" "Coleman" }
110 [ "<table><tr><td>RBaxter</td><td>Unknown</td></tr><tr><td>Doug</td><td>Coleman</td></tr></table>" ] [
112 "test8" test-template call-template
113 ] run-template [ blank? not ] filter
118 H{ { "first-name" "RBaxter" } { "last-name" "Unknown" } }
119 H{ { "first-name" "Doug" } { "last-name" "Coleman" } }
123 [ "<table><tr><td>RBaxter</td><td>Unknown</td></tr><tr><td>Doug</td><td>Coleman</td></tr></table>" ] [
125 "test8" test-template call-template
126 ] run-template [ blank? not ] filter
129 [ ] [ 1 "id" set-value ] unit-test
131 [ "<a name=\"1\">Hello</a>" ] [
133 "test9" test-template call-template
137 [ ] [ H{ { "a" H{ { "b" "c" } } } } values set ] unit-test
139 [ "<form method='post' action='foo'><input type='hidden' name='__n' value='a'/></form>" ] [
141 "test10" test-template call-template
145 [ ] [ begin-form ] unit-test
148 <form> H{ { "first-name" "RBaxter" } { "last-name" "Unknown" } } >>values "person" set-value
151 [ "<table><tr><td>RBaxter</td><td>Unknown</td></tr></table>" ] [
153 "test11" test-template call-template
154 ] run-template [ blank? not ] filter
159 { "a" "b" } "choices" set-value
163 [ "<input type='checkbox' name='a'>a</input><input type='checkbox' name='b' checked='true'>b</input>" ] [
165 "test12" test-template call-template