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 html.templates.chloe.compiler ;
6 IN: html.templates.chloe.tests
9 with-string-writer [ "\r\n\t" member? not ] filter
10 "?>" split1 nip ; inline
12 : test-template ( name -- template )
13 "resource:basis/html/templates/chloe/test/"
18 "test1" test-template call-template
22 [ "Blah blah" "Hello world" ] [
26 "test2" test-template call-template
32 [ "<html><head><title>Hello world</title></head><body>Blah blah</body></html>" ] [
35 "test2" test-template call-template
36 ] "test3" test-template with-boilerplate
44 "test4" test-template call-template
52 "test5" test-template call-template
56 [ ] [ begin-form ] unit-test
58 [ ] [ "A label" "label" set-value ] unit-test
62 M: link-test link-title drop "<Link Title>" ;
64 M: link-test link-href drop "http://www.apple.com/foo&bar" ;
66 [ ] [ link-test "link" set-value ] unit-test
68 [ ] [ "int x = 5;" "code" set-value ] unit-test
70 [ ] [ "c" "mode" set-value ] unit-test
72 [ ] [ { 1 2 3 } "inspector" set-value ] unit-test
74 [ ] [ "<p>a paragraph</p>" "html" set-value ] unit-test
76 [ ] [ "sheeple" "field" set-value ] unit-test
78 [ ] [ "a password" "password" set-value ] unit-test
80 [ ] [ "a\nb\nc" "textarea" set-value ] unit-test
82 [ ] [ "new york" "choice" set-value ] unit-test
84 [ ] [ { "new york" "detroit" "minneapolis" } "choices" set-value ] unit-test
88 "test8" test-template call-template
92 [ ] [ { 1 2 3 } "numbers" set-value ] unit-test
94 [ "<ul><li>1</li><li>2</li><li>3</li></ul>" ] [
96 "test7" test-template call-template
97 ] run-template [ blank? not ] filter
100 TUPLE: person first-name last-name ;
104 T{ person f "RBaxter" "Unknown" }
105 T{ person f "Doug" "Coleman" }
109 [ "<table><tr><td>RBaxter</td><td>Unknown</td></tr><tr><td>Doug</td><td>Coleman</td></tr></table>" ] [
111 "test8" test-template call-template
112 ] run-template [ blank? not ] filter
117 H{ { "first-name" "RBaxter" } { "last-name" "Unknown" } }
118 H{ { "first-name" "Doug" } { "last-name" "Coleman" } }
122 [ "<table><tr><td>RBaxter</td><td>Unknown</td></tr><tr><td>Doug</td><td>Coleman</td></tr></table>" ] [
124 "test8" test-template call-template
125 ] run-template [ blank? not ] filter
128 [ ] [ 1 "id" set-value ] unit-test
130 [ "<a name=\"1\">Hello</a>" ] [
132 "test9" test-template call-template
136 [ ] [ H{ { "a" H{ { "b" "c" } } } } values set ] unit-test
138 [ "<form method='post' action='foo'><div style='display: none;'><input type='hidden' name='__n' value='a'/></div></form>" ] [
140 "test10" test-template call-template
144 [ ] [ begin-form ] unit-test
147 <form> H{ { "first-name" "RBaxter" } { "last-name" "Unknown" } } >>values "person" set-value
150 [ "<table><tr><td>RBaxter</td><td>Unknown</td></tr></table>" ] [
152 "test11" test-template call-template
153 ] run-template [ blank? not ] filter
158 { "a" "b" } "choices" set-value
162 [ "<input type=\"checkbox\" name=\"a\">a</input><input type=\"checkbox\" checked=\"true\" name=\"b\">b</input>" ] [
164 "test12" test-template call-template
170 "test13" test-template call-template
172 ] [ error>> T{ unknown-chloe-tag f "this-tag-does-not-exist" } = ] must-fail-with