OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #import("../../../css/css.dart"); | 5 #import("../../../css/css.dart"); |
6 #import('../../../../frog/lang.dart', prefix:'lang'); | 6 #import('../../../../frog/lang.dart', prefix:'lang'); |
7 | 7 |
8 class SelectorLiteralTest { | 8 class SelectorLiteralTest { |
9 static final String ERROR = 'CompilerException: <buffer>:'; | 9 static final String ERROR = 'CompilerException: <buffer>:'; |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... |
35 cssParseAndValidate('@{#id-number-3}', cssWorld); | 35 cssParseAndValidate('@{#id-number-3}', cssWorld); |
36 cssParseAndValidate('@{#_privateId}', cssWorld); | 36 cssParseAndValidate('@{#_privateId}', cssWorld); |
37 | 37 |
38 // Valid selectors for private class names (leading underscore). | 38 // Valid selectors for private class names (leading underscore). |
39 cssParseAndValidate('@{.foobar ._privateClass}', cssWorld); | 39 cssParseAndValidate('@{.foobar ._privateClass}', cssWorld); |
40 cssParseAndValidate('@{.foobar ._privateClass .xyzzy}', cssWorld); | 40 cssParseAndValidate('@{.foobar ._privateClass .xyzzy}', cssWorld); |
41 cssParseAndValidate('@{.foobar ._private1 .xyzzy ._private2}', cssWorld); | 41 cssParseAndValidate('@{.foobar ._private1 .xyzzy ._private2}', cssWorld); |
42 | 42 |
43 // Valid selectors for private element IDs (leading underscore). | 43 // Valid selectors for private element IDs (leading underscore). |
44 cssParseAndValidate('@{._privateClass}', cssWorld); | 44 cssParseAndValidate('@{._privateClass}', cssWorld); |
45 } catch (var e) { | 45 } catch (final e) { |
46 // CSS Expressions failed | 46 // CSS Expressions failed |
47 Expect.fail(e.toString()); | 47 Expect.fail(e.toString()); |
48 } | 48 } |
49 } | 49 } |
50 | 50 |
51 static void testSimpleClassSelectorFailures() { | 51 static void testSimpleClassSelectorFailures() { |
52 List<String> knownClasses = ['foobar', 'xyzzy', 'a-story', 'b-story']; | 52 List<String> knownClasses = ['foobar', 'xyzzy', 'a-story', 'b-story']; |
53 List<String> knownIds = ['id1', 'id2', 'id-number-3']; | 53 List<String> knownIds = ['id1', 'id2', 'id-number-3']; |
54 | 54 |
55 CssWorld cssWorld = new CssWorld(knownClasses, knownIds); | 55 CssWorld cssWorld = new CssWorld(knownClasses, knownIds); |
56 | 56 |
57 // Invalid class name. | 57 // Invalid class name. |
58 String css = '@{.-foobar}'; | 58 String css = '@{.-foobar}'; |
59 try { | 59 try { |
60 cssParseAndValidate('${css}', cssWorld); | 60 cssParseAndValidate('${css}', cssWorld); |
61 Expect.fail("${css} should not succeed."); | 61 Expect.fail("${css} should not succeed."); |
62 } catch (var e) { | 62 } catch (final e) { |
63 Expect.equals("${ERROR}1:4: fatal: expected identifier, but found " + | 63 Expect.equals("CssSelectorException: Unknown selector name .-foobar", |
64 "TokenKind(506)(-)\n${css}\n ^", e.toString()); | 64 e.toString()); |
65 } | 65 } |
66 | 66 |
67 // Error this class name is not known. | 67 // Error this class name is not known. |
68 css = '@{.foobar1}'; | 68 css = '@{.foobar1}'; |
69 try { | 69 try { |
70 cssParseAndValidate('${css}', cssWorld); | 70 cssParseAndValidate('${css}', cssWorld); |
71 Expect.fail("${css} should not succeed."); | 71 Expect.fail("${css} should not succeed."); |
72 } catch (var e) { | 72 } catch (final e) { |
73 Expect.equals("CssSelectorException: Unknown selector name .foobar1", | 73 Expect.equals("CssSelectorException: Unknown selector name .foobar1", |
74 e.toString()); | 74 e.toString()); |
75 } | 75 } |
76 | 76 |
77 // Error if any class name is not known. | 77 // Error if any class name is not known. |
78 css = '@{.foobar .xyzzy1}'; | 78 css = '@{.foobar .xyzzy1}'; |
79 try { | 79 try { |
80 cssParseAndValidate('${css}', cssWorld); | 80 cssParseAndValidate('${css}', cssWorld); |
81 Expect.fail("${css} should not succeed."); | 81 Expect.fail("${css} should not succeed."); |
82 } catch (var e) { | 82 } catch (final e) { |
83 Expect.equals("CssSelectorException: Unknown selector name .xyzzy1", | 83 Expect.equals("CssSelectorException: Unknown selector name .xyzzy1", |
84 e.toString()); | 84 e.toString()); |
85 } | 85 } |
86 | 86 |
87 // Test for invalid class name (can't start with number). | 87 // Test for invalid class name (can't start with number). |
88 css = '@{.foobar .1a-story .xyzzy}'; | 88 css = '@{.foobar .1a-story .xyzzy}'; |
89 try { | 89 try { |
90 cssParseAndValidate('${css}', cssWorld); | 90 cssParseAndValidate('${css}', cssWorld); |
91 Expect.fail("${css} should not succeed."); | 91 Expect.fail("${css} should not succeed."); |
92 } catch (var e) { | 92 } catch (final e) { |
93 Expect.equals( | 93 Expect.equals("${ERROR}1:11: fatal: expected }, but found double(.1)\n" + |
94 "${ERROR}1:12: fatal: expected identifier, but found error(1a)\n" + | 94 "${css}\n ^^", e.toString()); |
95 "${css}\n ^^", e.toString()); | |
96 } | 95 } |
97 | 96 |
98 // element id must be single selector. | 97 // element id must be single selector. |
99 css = '@{#id1 #id2}'; | 98 css = '@{#id1 #id2}'; |
100 try { | 99 try { |
101 cssParseAndValidate('${css}', cssWorld); | 100 cssParseAndValidate('${css}', cssWorld); |
102 Expect.fail("${css} should not succeed."); | 101 Expect.fail("${css} should not succeed."); |
103 } catch (var e) { | 102 } catch (final e) { |
104 Expect.equals("CssSelectorException: Use of Id selector must be " + | 103 Expect.equals("CssSelectorException: Use of Id selector must be " + |
105 "singleton starting at #id2", e.toString()); | 104 "singleton starting at #id2", e.toString()); |
106 } | 105 } |
107 | 106 |
108 // element id must be single selector. | 107 // element id must be single selector. |
109 css = '@{#id-number-3 .foobar}'; | 108 css = '@{#id-number-3 .foobar}'; |
110 try { | 109 try { |
111 cssParseAndValidate('${css}', cssWorld); | 110 cssParseAndValidate('${css}', cssWorld); |
112 Expect.fail("@{#id-number-3 .foobar} should not succeed."); | 111 Expect.fail("@{#id-number-3 .foobar} should not succeed."); |
113 } catch (var e) { | 112 } catch (final e) { |
114 // CSS Expressions failed | 113 // CSS Expressions failed |
115 Expect.equals("CssSelectorException: Can not mix Id selector with "+ | 114 Expect.equals("CssSelectorException: Can not mix Id selector with "+ |
116 "class selector(s). Id selector must be singleton too many " + | 115 "class selector(s). Id selector must be singleton too many " + |
117 "starting at .foobar", e.toString(), ''); | 116 "starting at .foobar", e.toString(), ''); |
118 } | 117 } |
119 | 118 |
120 // element id must be alone and only one element id. | 119 // element id must be alone and only one element id. |
121 css = '@{.foobar #id-number-3 #id1}'; | 120 css = '@{.foobar #id-number-3 #id1}'; |
122 try { | 121 try { |
123 cssParseAndValidate('${css}', cssWorld); | 122 cssParseAndValidate('${css}', cssWorld); |
124 Expect.fail("${css} should not succeed."); | 123 Expect.fail("${css} should not succeed."); |
125 } catch (var e) { | 124 } catch (final e) { |
126 // CSS Expressions failed | 125 // CSS Expressions failed |
127 Expect.equals("CssSelectorException: Use of Id selector must be " + | 126 Expect.equals("CssSelectorException: Use of Id selector must be " + |
128 "singleton starting at #id-number-3", e.toString()); | 127 "singleton starting at #id-number-3", e.toString()); |
129 } | 128 } |
130 | 129 |
131 // Namespace selector not valid in @{css_expression} | 130 // Namespace selector not valid in @{css_expression} |
132 css = '@{foo|div}'; | 131 css = '@{foo|div}'; |
133 try { | 132 try { |
134 cssParseAndValidate('${css}', cssWorld); | 133 cssParseAndValidate('${css}', cssWorld); |
135 Expect.fail("${css} should not succeed."); | 134 Expect.fail("${css} should not succeed."); |
136 } catch (var e) { | 135 } catch (final e) { |
137 Expect.equals("CssSelectorException: Invalid template selector foo|div", | 136 Expect.equals("CssSelectorException: Invalid template selector foo|div", |
138 e.toString()); | 137 e.toString()); |
139 } | 138 } |
140 | 139 |
141 // class and element id not allowed together. | 140 // class and element id not allowed together. |
142 css = '@{.foobar foo|div}'; | 141 css = '@{.foobar foo|div}'; |
143 try { | 142 try { |
144 cssParseAndValidate('${css}', cssWorld); | 143 cssParseAndValidate('${css}', cssWorld); |
145 Expect.fail("$css} should not succeed."); | 144 Expect.fail("$css} should not succeed."); |
146 } catch (var e) { | 145 } catch (final e) { |
147 Expect.equals("CssSelectorException: Invalid template selector foo|div", | 146 Expect.equals("CssSelectorException: Invalid template selector foo|div", |
148 e.toString()); | 147 e.toString()); |
149 } | 148 } |
150 | 149 |
151 // Element id and namespace not allowed together. | 150 // Element id and namespace not allowed together. |
152 css = '@{#id1 foo|div}'; | 151 css = '@{#id1 foo|div}'; |
153 try { | 152 try { |
154 cssParseAndValidate('${css}', cssWorld); | 153 cssParseAndValidate('${css}', cssWorld); |
155 Expect.fail("${css} should not succeed."); | 154 Expect.fail("${css} should not succeed."); |
156 } catch (var e) { | 155 } catch (final e) { |
157 Expect.equals("CssSelectorException: Invalid template selector foo|div", | 156 Expect.equals("CssSelectorException: Invalid template selector foo|div", |
158 e.toString()); | 157 e.toString()); |
159 } | 158 } |
160 | 159 |
161 // namespace and element id not allowed together. | 160 // namespace and element id not allowed together. |
162 css = '@{foo|div #id1}'; | 161 css = '@{foo|div #id1}'; |
163 try { | 162 try { |
164 cssParseAndValidate('${css}', cssWorld); | 163 cssParseAndValidate('${css}', cssWorld); |
165 Expect.fail("${css} should not succeed."); | 164 Expect.fail("${css} should not succeed."); |
166 } catch (var e) { | 165 } catch (final e) { |
167 Expect.equals("CssSelectorException: Invalid template selector foo|div", | 166 Expect.equals("CssSelectorException: Invalid template selector foo|div", |
168 e.toString()); | 167 e.toString()); |
169 } | 168 } |
170 | 169 |
171 // namespace / element not allowed. | 170 // namespace / element not allowed. |
172 css = '@{foo|div .foobar}'; | 171 css = '@{foo|div .foobar}'; |
173 try { | 172 try { |
174 cssParseAndValidate('${css}', cssWorld); | 173 cssParseAndValidate('${css}', cssWorld); |
175 Expect.fail("${css} should not succeed."); | 174 Expect.fail("${css} should not succeed."); |
176 } catch (var e) { | 175 } catch (final e) { |
177 Expect.equals("CssSelectorException: Invalid template selector foo|div", | 176 Expect.equals("CssSelectorException: Invalid template selector foo|div", |
178 e.toString()); | 177 e.toString()); |
179 } | 178 } |
180 | 179 |
181 // Combinators not allowed. | 180 // Combinators not allowed. |
182 css = '@{.foobar > .xyzzy}'; | 181 css = '@{.foobar > .xyzzy}'; |
183 try { | 182 try { |
184 cssParseAndValidate('${css}', cssWorld); | 183 cssParseAndValidate('${css}', cssWorld); |
185 Expect.fail("${css} should not succeed."); | 184 Expect.fail("${css} should not succeed."); |
186 } catch (var e) { | 185 } catch (final e) { |
187 Expect.equals("CssSelectorException: Selectors can not have " + | 186 Expect.equals("CssSelectorException: Selectors can not have " + |
188 "combinators (>, +, or ~) before .xyzzy", e.toString()); | 187 "combinators (>, +, or ~) before >.xyzzy", e.toString()); |
189 } | 188 } |
190 } | 189 } |
191 | 190 |
192 static void testPrivateNameFailures() { | 191 static void testPrivateNameFailures() { |
193 List<String> knownClasses = ['foobar', 'xyzzy', 'a-story', 'b-story']; | 192 List<String> knownClasses = ['foobar', 'xyzzy', 'a-story', 'b-story']; |
194 List<String> knownIds = ['id1', 'id2', 'id-number-3']; | 193 List<String> knownIds = ['id1', 'id2', 'id-number-3']; |
195 | 194 |
196 CssWorld cssWorld = new CssWorld(knownClasses, knownIds); | 195 CssWorld cssWorld = new CssWorld(knownClasses, knownIds); |
197 | 196 |
198 // Too many. | 197 // Too many. |
199 String css = '@{._private #id2}'; | 198 String css = '@{._private #id2}'; |
200 try { | 199 try { |
201 cssParseAndValidate('${css}', cssWorld); | 200 cssParseAndValidate('${css}', cssWorld); |
202 Expect.fail("${css} should not succeed."); | 201 Expect.fail("${css} should not succeed."); |
203 } catch (var e) { | 202 } catch (final e) { |
204 Expect.equals("CssSelectorException: Use of Id selector must be " + | 203 Expect.equals("CssSelectorException: Use of Id selector must be " + |
205 "singleton starting at #id2", e.toString()); | 204 "singleton starting at #id2", e.toString()); |
206 } | 205 } |
207 | 206 |
208 // Unknown class foobar2. | 207 // Unknown class foobar2. |
209 css = '@{._private .foobar2}'; | 208 css = '@{._private .foobar2}'; |
210 try { | 209 try { |
211 cssParseAndValidate('${css}', cssWorld); | 210 cssParseAndValidate('${css}', cssWorld); |
212 Expect.fail("${css} should not succeed."); | 211 Expect.fail("${css} should not succeed."); |
213 } catch (var e) { | 212 } catch (final e) { |
214 Expect.equals("CssSelectorException: Unknown selector name .foobar2", | 213 Expect.equals("CssSelectorException: Unknown selector name .foobar2", |
215 e.toString()); | 214 e.toString()); |
216 } | 215 } |
217 | 216 |
218 // Too many element IDs. | 217 // Too many element IDs. |
219 css = '@{#_privateId #id2}'; | 218 css = '@{#_privateId #id2}'; |
220 try { | 219 try { |
221 cssParseAndValidate('${css}', cssWorld); | 220 cssParseAndValidate('${css}', cssWorld); |
222 Expect.fail("${css} should not succeed."); | 221 Expect.fail("${css} should not succeed."); |
223 } catch (var e) { | 222 } catch (final e) { |
224 Expect.equals("CssSelectorException: Use of Id selector must be " + | 223 Expect.equals("CssSelectorException: Use of Id selector must be " + |
225 "singleton starting at #id2", e.toString()); | 224 "singleton starting at #id2", e.toString()); |
226 } | 225 } |
227 | 226 |
228 // Too many element IDs. | 227 // Too many element IDs. |
229 css = '@{#_privateId1 #_privateId2}'; | 228 css = '@{#_privateId1 #_privateId2}'; |
230 try { | 229 try { |
231 cssParseAndValidate('${css}', cssWorld); | 230 cssParseAndValidate('${css}', cssWorld); |
232 Expect.fail("${css} should not succeed."); | 231 Expect.fail("${css} should not succeed."); |
233 } catch (var e) { | 232 } catch (final e) { |
234 Expect.equals("CssSelectorException: Use of Id selector must be " + | 233 Expect.equals("CssSelectorException: Use of Id selector must be " + |
235 "singleton starting at #_privateId2", e.toString()); | 234 "singleton starting at #_privateId2", e.toString()); |
236 } | 235 } |
237 } | 236 } |
238 | 237 |
239 } | 238 } |
240 | 239 |
241 main() { | 240 main() { |
242 SelectorLiteralTest.testMain(); | 241 SelectorLiteralTest.testMain(); |
243 } | 242 } |
OLD | NEW |