]> gitweb.factorcode.org Git - factor.git/blob - extra/modern/html/html-tests.factor
3af527c44547e997e9b2d8cc14521213d394301f
[factor.git] / extra / modern / html / html-tests.factor
1 ! Copyright (C) 2021 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: io.encodings.utf8 io.files kernel make math modern.html
4 multiline sequences tools.test ;
5 IN: modern.html.tests
6
7 [
8     [[ <html>]] string>html
9 ] [ unmatched-open-tags-error? ] must-fail-with
10
11 [
12     [[ <html><body></html>]] string>html
13 ] [ unmatched-open-tags-error? ] must-fail-with
14
15 [
16     [[ <html><body><html/>]] string>html
17 ] [ unmatched-open-tags-error? ] must-fail-with
18
19 [
20     [[ </html>]] string>html
21 ] [ unmatched-closing-tag-error? ] must-fail-with
22
23 [
24     [[ <html></html123>]] string>html
25 ] [ unmatched-closing-tag-error? ] must-fail-with
26
27 { [[ <html><head>omg</head><body><asdf a b c="d"><a/></asdf></body></html>]] } [
28     [[ <html><head>omg</head><body><asdf a b c="d" > <a/></asdf></body></html>]] string>html html>string
29 ] unit-test
30
31 [
32     [[ <html><head>omg<body></body></html>]] string>html html>string
33 ] [ unmatched-open-tags-error? ] must-fail-with
34
35 { [[ <!-- omg omg -->]] }
36 [ [[ <!-- omg omg -->]] string>html html>string ] unit-test
37
38 { "<div><div><a/><b/><c/></div></div>" }
39 [ "<div> <div>  <a/> <b/> <c/> </div> </div>" string>html html>string ] unit-test
40
41 { "<?xml version='1.0'?>" }
42 [ [[ <?xml version='1.0'?> ]] string>html html>string ] unit-test
43
44 { "<?xml version='1.0'?>" }
45 [ [[ <?xml version='1.0' ?> ]] string>html html>string ] unit-test
46
47 {
48     V{
49         T{ doctype
50             { open "<!DOCTYPE" }
51             { close ">" }
52             { values
53                 V{
54                     "plist"
55                     "PUBLIC"
56                     T{ dquote
57                         { payload "-//Apple//DTD PLIST 1.0//EN" }
58                     }
59                     T{ dquote
60                         { payload
61                             "http://www.apple.com/DTDs/PropertyList-1.0.dtd"
62                         }
63                     }
64                 }
65             }
66         }
67     }
68 } [
69     [[ <!DOCTYPE plist PUBLIC
70     "-//Apple//DTD PLIST 1.0//EN"
71     "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
72     ]]
73     string>html
74 ] unit-test
75
76 {
77     V{ T{ comment { open "<!--" } { payload " comment " } { close "-->" } } }
78 } [ [[ <!-- comment --> ]] string>html ] unit-test
79
80 ! From wikipedia factor article
81 ! https://en.wikipedia.org/w/index.php?title=Factor_(programming_language)&offset=&limit=500&action=history"
82 {
83     V{
84         T{ doctype
85             { open "<!DOCTYPE" }
86             { close ">" }
87             { values V{ "html" } }
88         }
89         T{ open-tag
90             { open "<" }
91             { name "html" }
92             { props
93                 V{
94                     {
95                         "class"
96                         T{ dquote { payload "client-nojs" } }
97                     }
98                     { "lang" T{ dquote { payload "en" } } }
99                     { "dir" T{ dquote { payload "ltr" } } }
100                 }
101             }
102             { close ">" }
103             { children
104                 V{
105                     T{ open-tag
106                         { open "<" }
107                         { name "head" }
108                         { props V{ } }
109                         { close ">" }
110                         { children
111                             V{
112                                 T{ open-tag
113                                     { open "<" }
114                                     { name "title" }
115                                     { props V{ } }
116                                     { close ">" }
117                                     { children V{ "omg" } }
118                                     { close-tag
119                                         T{ close-tag
120                                             { name "title" }
121                                         }
122                                     }
123                                 }
124                             }
125                         }
126                         { close-tag T{ close-tag { name "head" } } }
127                     }
128                     T{ open-tag
129                         { open "<" }
130                         { name "body" }
131                         { props V{ } }
132                         { close ">" }
133                         { children
134                             V{
135                                 T{ open-tag
136                                     { open "<" }
137                                     { name "div" }
138                                     { props
139                                         V{
140                                             {
141                                                 "id"
142                                                 T{ squote
143                                                     { payload
144                                                         "ooui-php-6"
145                                                     }
146                                                 }
147                                             }
148                                             {
149                                                 "data-ooui"
150                                                 T{ squote
151                                                     { payload
152                                                         "{\"_\":\"mw.htmlform.FieldLayout\",\"fieldWidget\":{\"tag\":\"tagfilter\"},\"align\":\"top\",\"helpInline\":true,\"$overlay\":true,\"label\":{\"html\":\"&lt;a href=\\\"\\/wiki\\/Special:Tags\\\" title=\\\"Special:Tags\\\"&gt;Tag&lt;\\/a&gt; filter:\"},\"classes\":[\"mw-htmlform-field-HTMLTagFilter\",\"mw-htmlform-autoinfuse\"]}"
153                                                     }
154                                                 }
155                                             }
156                                         }
157                                     }
158                                     { close ">" }
159                                     { children V{ } }
160                                     { close-tag
161                                         T{ close-tag
162                                             { name "div" }
163                                         }
164                                     }
165                                 }
166                             }
167                         }
168                         { close-tag T{ close-tag { name "body" } } }
169                     }
170                 }
171             }
172             { close-tag T{ close-tag { name "html" } } }
173         }
174     }
175 } [
176     [[
177     <!DOCTYPE html>
178     <html class="client-nojs" lang="en" dir="ltr">
179
180     <head> <title>omg</title></head>
181     <body>
182     <div id='ooui-php-6'
183     data-ooui='{"_":"mw.htmlform.FieldLayout","fieldWidget":{"tag":"tagfilter"},"align":"top","helpInline":true,"$overlay":true,"label":{"html":"&lt;a href=\"\/wiki\/Special:Tags\" title=\"Special:Tags\"&gt;Tag&lt;\/a&gt; filter:"},"classes":["mw-htmlform-field-HTMLTagFilter","mw-htmlform-autoinfuse"]}'
184     >
185     </div>
186     </body>
187     </html>
188     ]] string>html
189 ] unit-test
190
191
192 ! Handle tabs
193 {
194 V{
195     T{ open-tag
196         { open "<" }
197         { name "label" }
198         { props
199             V{
200                 {
201                     "id"
202                     T{ dquote { payload "p-personal-label" } }
203                 }
204                 {
205                     "class"
206                     T{ dquote
207                         { payload "vector-menu-heading " }
208                     }
209                 }
210             }
211         }
212         { close ">" }
213         { children
214             V{
215                 T{ open-tag
216                     { open "<" }
217                     { name "span" }
218                     { props
219                         V{
220                             {
221                                 "class"
222                                 T{ dquote
223                                     { payload
224                                         "vector-menu-heading-label"
225                                     }
226                                 }
227                             }
228                         }
229                     }
230                     { close ">" }
231                     { children V{ "Personal tools" } }
232                     { close-tag T{ close-tag { name "span" } } }
233                 }
234             }
235         }
236         { close-tag T{ close-tag { name "label" } } }
237     }
238 }
239 } [
240 [[
241         <label
242                 id="p-personal-label"
243                 
244                 class="vector-menu-heading "
245         >
246                 <span class="vector-menu-heading-label">Personal tools</span>
247         </label>
248 ]] string>html
249 ] unit-test
250
251 ! Ensure we can parse <%factor "hi" print %> embedded code
252 { t } [
253     "resource:extra/websites/factorcode/index.fhtml" utf8 file-contents
254     string>html [ [ dup embedded-language? [ , ] [ drop ] if ] walk-html ] { } make length 0 >
255 ] unit-test