remove math.blas.syntax and merge parsing words into math.blas.vectors/matrices
[factor/jcg.git] / basis / html / templates / chloe / chloe-tests.factor
blob19b67f70188edff234d7bd7af4bbd085e0c0ce86
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
8 : run-template
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/"
14     prepend <chloe> ;
16 [ "Hello world" ] [
17     [
18         "test1" test-template call-template
19     ] run-template
20 ] unit-test
22 [ "Blah blah" "Hello world" ] [
23     [
24         <box> title set
25         [
26             "test2" test-template call-template
27         ] run-template
28         title get box>
29     ] with-scope
30 ] unit-test
32 [ "<html><head><title>Hello world</title></head><body>Blah blah</body></html>" ] [
33     [
34         [
35             "test2" test-template call-template
36         ] "test3" test-template with-boilerplate
37     ] run-template
38 ] unit-test
40 : test4-aux? t ;
42 [ "True" ] [
43     [
44         "test4" test-template call-template
45     ] run-template
46 ] unit-test
48 : test5-aux? f ;
50 [ "" ] [
51     [
52         "test5" test-template call-template
53     ] run-template
54 ] unit-test
56 [ ] [ begin-form ] unit-test
58 [ ] [ "A label" "label" set-value ] unit-test
60 SINGLETON: link-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
86 [ ] [
87     [
88         "test8" test-template call-template
89     ] run-template drop
90 ] unit-test
92 [ ] [ { 1 2 3 } "numbers" set-value ] unit-test
94 [ "<ul><li>1</li><li>2</li><li>3</li></ul>" ] [
95     [
96         "test7" test-template call-template
97     ] run-template [ blank? not ] filter
98 ] unit-test
100 TUPLE: person first-name last-name ;
102 [ ] [
103     {
104         T{ person f "RBaxter" "Unknown" }
105         T{ person f "Doug" "Coleman" }
106     } "people" set-value
107 ] unit-test
109 [ "<table><tr><td>RBaxter</td><td>Unknown</td></tr><tr><td>Doug</td><td>Coleman</td></tr></table>" ] [
110     [
111         "test8" test-template call-template
112     ] run-template [ blank? not ] filter
113 ] unit-test
115 [ ] [
116     {
117         H{ { "first-name" "RBaxter" } { "last-name" "Unknown" } }
118         H{ { "first-name" "Doug"    } { "last-name" "Coleman" } }
119     } "people" set-value
120 ] unit-test
122 [ "<table><tr><td>RBaxter</td><td>Unknown</td></tr><tr><td>Doug</td><td>Coleman</td></tr></table>" ] [
123     [
124         "test8" test-template call-template
125     ] run-template [ blank? not ] filter
126 ] unit-test
128 [ ] [ 1 "id" set-value ] unit-test
130 [ "<a name=\"1\">Hello</a>" ] [
131     [
132         "test9" test-template call-template
133     ] run-template
134 ] unit-test
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>" ] [
139     [
140         "test10" test-template call-template
141     ] run-template
142 ] unit-test
144 [ ] [ begin-form ] unit-test
146 [ ] [
147     <form> H{ { "first-name" "RBaxter" } { "last-name" "Unknown" } } >>values "person" set-value
148 ] unit-test
150 [ "<table><tr><td>RBaxter</td><td>Unknown</td></tr></table>" ] [
151     [
152         "test11" test-template call-template
153     ] run-template [ blank? not ] filter
154 ] unit-test
156 [ ] [
157     begin-form
158     { "a" "b" } "choices" set-value
159     "true" "b" set-value
160 ] unit-test
162 [ "<input type=\"checkbox\" name=\"a\">a</input><input type=\"checkbox\" checked=\"true\" name=\"b\">b</input>" ] [
163     [
164         "test12" test-template call-template
165     ] run-template
166 ] unit-test
169     [
170         "test13" test-template call-template
171     ] run-template
172 ] [ error>> T{ unknown-chloe-tag f "this-tag-does-not-exist" } = ] must-fail-with