Merge branch 'master' of git://factorcode.org/git/factor
[factor/jcg.git] / basis / html / components / components-tests.factor
blob09bb5860ade889e67892042d65756b9ad8fc978d
1 IN: html.components.tests
2 USING: tools.test kernel io.streams.string
3 io.streams.null accessors inspector html.streams
4 html.elements html.components html.forms namespaces ;
6 [ ] [ begin-form ] unit-test
8 [ ] [ 3 "hi" set-value ] unit-test
10 [ 3 ] [ "hi" value ] unit-test
12 TUPLE: color red green blue ;
14 [ ] [ 1 2 3 color boa from-object ] unit-test
16 [ 1 ] [ "red" value ] unit-test
18 [ ] [ "jimmy" "red" set-value ] unit-test
20 [ "jimmy" ] [
21     [
22         "red" label render
23     ] with-string-writer
24 ] unit-test
26 [ ] [ "<jimmy>" "red" set-value ] unit-test
28 [ "&lt;jimmy&gt;" ] [
29     [
30         "red" label render
31     ] with-string-writer
32 ] unit-test
34 [ "<input value=\"&lt;jimmy>\" name=\"red\" type=\"hidden\"/>" ] [
35     [
36         "red" hidden render
37     ] with-string-writer
38 ] unit-test
40 [ ] [ "'jimmy'" "red" set-value ] unit-test
42 [ "<input value=\"&apos;jimmy&apos;\" name=\"red\" size=\"5\" type=\"text\"/>" ] [
43     [
44         "red" <field> 5 >>size render
45     ] with-string-writer
46 ] unit-test
48 [ "<input value=\"\" name=\"red\" size=\"5\" type=\"password\"/>" ] [
49     [
50         "red" <password> 5 >>size render
51     ] with-string-writer
52 ] unit-test
54 [ ] [
55     [
56         "green" <textarea> render
57     ] with-null-writer
58 ] unit-test
60 [ ] [
61     [
62         "green" <textarea> 25 >>rows 30 >>cols render
63     ] with-null-writer
64 ] unit-test
66 [ ] [ begin-form ] unit-test
68 [ ] [ "new york" "city1" set-value ] unit-test
70 [ ] [ { "new york" "los angeles" "chicago" } "cities" set-value ] unit-test
72 [ ] [
73     [
74         "city1"
75         <choice>
76             "cities" >>choices
77         render
78     ] with-null-writer
79 ] unit-test
81 [ ] [ { "los angeles" "new york" } "city2" set-value ] unit-test
83 [ ] [
84     [
85         "city2"
86         <choice>
87             "cities" >>choices
88             t >>multiple
89         render
90     ] with-null-writer
91 ] unit-test
93 [ ] [
94     [
95         "city2"
96         <choice>
97             "cities" >>choices
98             t >>multiple
99             5 >>size
100         render
101     ] with-null-writer
102 ] unit-test
104 [ ] [ begin-form ] unit-test
106 [ ] [ t "delivery" set-value ] unit-test
108 [ "<input type=\"checkbox\" checked=\"true\" name=\"delivery\">Delivery</input>" ] [
109     [
110         "delivery"
111         <checkbox>
112             "Delivery" >>label
113         render
114     ] with-string-writer
115 ] unit-test
117 [ ] [ f "delivery" set-value ] unit-test
119 [ "<input type=\"checkbox\" name=\"delivery\">Delivery</input>" ] [
120     [
121         "delivery"
122         <checkbox>
123             "Delivery" >>label
124         render
125     ] with-string-writer
126 ] unit-test
128 SINGLETON: link-test
130 M: link-test link-title drop "<Link Title>" ;
132 M: link-test link-href drop "http://www.apple.com/foo&bar" ;
134 [ ] [ link-test "link" set-value ] unit-test
136 [ "<a href=\"http://www.apple.com/foo&amp;bar\">&lt;Link Title&gt;</a>" ] [
137     [ "link" link new render ] with-string-writer
138 ] unit-test
140 [ ] [
141     "<html>arbitrary <b>markup</b> for the win!</html>" "html" set-value
142 ] unit-test
144 [ "<html>arbitrary <b>markup</b> for the win!</html>" ] [
145     [ "html" html render ] with-string-writer
146 ] unit-test
148 [ ] [ "int x = 4;" "code" set-value ] unit-test
150 [ ] [ "java" "mode" set-value ] unit-test
152 [ "<span class=\"KEYWORD3\">int</span> x <span class=\"OPERATOR\">=</span> <span class=\"DIGIT\">4</span>;" ] [
153     [ "code" <code> "mode" >>mode render ] with-string-writer
154 ] unit-test
156 [ ] [ "-foo\n-bar" "farkup" set-value ] unit-test
158 [ "<ul><li>foo</li>\n<li>bar</li></ul>" ] [
159     [ "farkup" T{ farkup } render ] with-string-writer
160 ] unit-test
162 [ ] [ { 1 2 3 } "object" set-value ] unit-test
164 [ t ] [
165     [ "object" inspector render ] with-string-writer
166     USING: splitting sequences ;
167     "\"" split "'" join ! replace " with ' for now
168     [ "object" value [ describe ] with-html-writer ] with-string-writer
169     =
170 ] unit-test
172 [ ] [ begin-form ] unit-test
174 [ ] [
175     "factor" [
176         "concatenative" "model" set-value
177     ] nest-form
178 ] unit-test
181     H{
182         {
183             "factor"
184             T{ form f V{ } H{ { "model" "concatenative" } } }
185         }
186     }
187 ] [ values ] unit-test