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 furnace accessors
5 html.templates.chloe.compiler ;
6 IN: html.templates.chloe.tests
8 ! So that changes to code are reflected
9 { } [ reset-cache ] unit-test
11 : run-template ( quot -- string )
12 with-string-writer [ "\r\n\t" member? ] reject
13 [ CHAR: \s = ] trim ; inline
15 : test-template ( name -- template )
16 "vocab:html/templates/chloe/test/"
21 "test1" test-template call-template
25 { "Blah blah" "Hello world" } [
29 "test2" test-template call-template
35 { "<!DOCTYPE html><html><head><title>Hello world</title></head><body>Blah blah</body></html>" } [
38 "test2" test-template call-template
39 ] "test3" test-template with-boilerplate
43 : test4-aux? ( -- ? ) t ;
47 "test4" test-template call-template
51 : test5-aux? ( -- ? ) f ;
55 "test5" test-template call-template
59 { } [ begin-form ] unit-test
61 { } [ "A label" "label" set-value ] unit-test
65 M: link-test link-title drop "<Link Title>" ;
67 M: link-test link-href drop "http://www.apple.com/foo&bar" ;
69 { } [ link-test "link" set-value ] unit-test
71 { } [ "int x = 5;" "code" set-value ] unit-test
73 { } [ "c" "mode" set-value ] unit-test
75 { } [ { 1 2 3 } "inspector" set-value ] unit-test
77 { } [ "<p>a paragraph</p>" "html" set-value ] unit-test
79 { } [ "sheeple" "field" set-value ] unit-test
81 { } [ "a password" "password" set-value ] unit-test
83 { } [ "a\nb\nc" "textarea" set-value ] unit-test
85 { } [ "new york" "choice" set-value ] unit-test
87 { } [ { "new york" "detroit" "minneapolis" } "choices" set-value ] unit-test
91 "test8" test-template call-template
95 { } [ { 1 2 3 } "numbers" set-value ] unit-test
97 { "<ul><li>1</li><li>2</li><li>3</li></ul>" } [
99 "test7" test-template call-template
100 ] run-template [ ascii:blank? ] reject
103 TUPLE: person first-name last-name ;
107 T{ person f "RBaxter" "Unknown" }
108 T{ person f "Doug" "Coleman" }
112 { "<table><tr><td>RBaxter</td><td>Unknown</td></tr><tr><td>Doug</td><td>Coleman</td></tr></table>" } [
114 "test8" test-template call-template
115 ] run-template [ ascii:blank? ] reject
120 H{ { "first-name" "RBaxter" } { "last-name" "Unknown" } }
121 H{ { "first-name" "Doug" } { "last-name" "Coleman" } }
125 { "<table><tr><td>RBaxter</td><td>Unknown</td></tr><tr><td>Doug</td><td>Coleman</td></tr></table>" } [
127 "test8" test-template call-template
128 ] run-template [ ascii:blank? ] reject
131 { } [ 1 "id" set-value ] unit-test
133 { "<a name=\"1\">Hello</a>" } [
135 "test9" test-template call-template
139 { } [ H{ { "a" H{ { "b" "c" } } } } values set ] unit-test
141 { "<form method=\"post\" action=\"foo\"><div style=\"display: none;\"><input type=\"hidden\" value=\"a\" name=\"__n\"/></div></form>" } [
143 "test10" test-template call-template
147 { } [ begin-form ] unit-test
150 <form> H{ { "first-name" "RBaxter" } { "last-name" "Unknown" } } >>values "person" set-value
153 { "<table><tr><td>RBaxter</td><td>Unknown</td></tr></table>" } [
155 "test11" test-template call-template
156 ] run-template [ ascii:blank? ] reject
161 { "a" "b" } "choices" set-value
165 { "<input type=\"checkbox\" name=\"a\">a</input><input type=\"checkbox\" checked=\"true\" name=\"b\">b</input>" } [
167 "test12" test-template call-template
173 "test13" test-template call-template
175 ] [ error>> T{ unknown-chloe-tag f "this-tag-does-not-exist" } = ] must-fail-with
177 { "Hello <world> &escaping test;" "Hello <world> &escaping test;" } [
182 "&escaping test;" "a-value" set-value
183 "test14" test-template call-template
193 "test15" test-template call-template
196 ] [ error>> tag-not-allowed-here? ] must-fail-with
198 { "This is <style type=\"text/css\"> * { font-family: monospace; } </style>" } [
200 [ "test16" test-template call-template ] run-template
204 { "<script type=\"text/javascript\">/* <![CDATA[*/function testAlerts() { window.alert(\"Hello, world!\");}/*]]> */</script>" } [
206 [ "test17" test-template call-template ] run-template
210 { "<meta name=\"author\" content=\"John Doe\"/><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"/>" } [
212 [ "test18" test-template call-template ] run-template