]> gitweb.factorcode.org Git - factor.git/blob - extra/html/parser/parser-tests.factor
html.parser: Strip trailing slashes / in html tags. Add unit test. Fixes #1233.
[factor.git] / extra / html / parser / parser-tests.factor
1 USING: html.parser kernel tools.test ;
2 IN: html.parser.tests
3
4 [
5     V{ T{ tag f "html" H{ } f f } }
6 ] [ "<html>" parse-html ] unit-test
7
8 [
9     V{ T{ tag f "html" H{ } f t } }
10 ] [ "</html>" parse-html ] unit-test
11
12 [
13     V{ T{ tag f "a" H{ { "href" "http://factorcode.org/" } } f f } }
14 ] [ "<a href=\"http://factorcode.org/\">" parse-html ] unit-test
15
16 [
17     V{ T{ tag f "a" H{ { "href" "http://factorcode.org/" } } f f } }
18 ] [ "<a   href  =  \"http://factorcode.org/\"   >" parse-html ] unit-test
19
20 [
21 V{
22     T{
23         tag
24         f
25         "a"
26         H{ { "baz" "\"quux\"" } { "foo" "bar's" } }
27         f
28         f
29     }
30 }
31 ] [ "<a   foo=\"bar's\" baz='\"quux\"'  >" parse-html ] unit-test
32
33 [
34 V{
35     T{ tag f "a"
36         H{
37             { "a" "pirsqd" }
38             { "foo" "bar" }
39             { "href" "http://factorcode.org/" }
40             { "baz" "quux" }
41         } f f }
42 }
43 ] [ "<a   href  =    \"http://factorcode.org/\"    foo   =  bar baz='quux'a=pirsqd  >" parse-html ] unit-test
44
45 [
46 V{
47     T{ tag f "a"
48         H{
49             { "a" "pirsqd" }
50             { "foo" "bar" }
51             { "href" "http://factorcode.org/" }
52             { "baz" "quux" }
53             { "nofollow" "nofollow" }
54         } f f }
55 }
56 ] [ "<a   href  =    \"http://factorcode.org/\"    nofollow  foo   =  bar baz='quux'a=pirsqd  >" parse-html ] unit-test
57
58 [
59 V{
60     T{ tag f "html" H{ } f f }
61     T{ tag f "head" H{ } f f }
62     T{ tag f "head" H{ } f t }
63     T{ tag f "html" H{ } f t }
64 }
65 ] [ "<html<head</head</html" parse-html ] unit-test
66
67 [
68 V{
69     T{ tag f "head" H{ } f f }
70     T{ tag f "title" H{ } f f }
71     T{ tag f text f "Spagna" f }
72     T{ tag f "title" H{ } f t }
73     T{ tag f "head" H{ } f t }
74 }
75 ] [ "<head<title>Spagna</title></head" parse-html ] unit-test
76
77 [
78 V{
79     T{ tag
80         { name dtd }
81         { text
82             "DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Draft//EN\""
83         }
84     }
85 }
86 ]
87 [
88     "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Draft//EN\">"
89     parse-html
90 ] unit-test
91
92 [
93 V{
94     T{ tag { name comment } { text "comment" } }
95 }
96 ] [
97     "<!--comment-->" parse-html
98 ] unit-test
99
100 ! Issue #1233, trailing / in tags
101 {
102     V{
103         T{ tag
104             { name "img" }
105             { attributes H{ { "src" "http://factorcode.org" } } }
106         }
107     }
108 }
109 [ "<img src=\"http://factorcode.org\">" parse-html ] unit-test
110
111 {
112     V{
113         T{ tag
114             { name "img" }
115             { attributes H{ { "src" "http://factorcode.org" } } }
116         }
117     }
118 }
119 [ "<img src=\"http://factorcode.org\"/>" parse-html ] unit-test
120
121 {
122     V{
123         T{ tag
124             { name "img" }
125             { attributes H{ { "src" "http://factorcode.org" } } }
126         }
127     }
128 }
129 [ "<img src=\"http://factorcode.org\"////////>" parse-html ] unit-test