Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: utils/tests/css/src/SelectorLiteralTest.dart

Issue 10209016: test rename overhaul: step 2 css tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 #library("SelectorLiteralTest");
6 #import("../../../css/css.dart");
7
8 class SelectorLiteralTest {
9 static final String ERROR = 'CompilerException: <buffer>:';
10
11 static testMain() {
12 initCssWorld();
13 options.useColors = false;
14
15 testSimpleClassSelectorSuccesses();
16 testSimpleClassSelectorFailures();
17 testPrivateNameFailures();
18 }
19
20 static void testSimpleClassSelectorSuccesses() {
21 List<String> knownClasses = ['foobar', 'xyzzy', 'a-story', 'b-story'];
22 List<String> knownIds = ['id1', 'id2', 'id-number-3'];
23
24 CssWorld cssWorld = new CssWorld(knownClasses, knownIds);
25
26 try {
27 // Valid selectors for class names.
28 cssParseAndValidate('@{.foobar}', cssWorld);
29 cssParseAndValidate('@{.foobar .xyzzy}', cssWorld);
30 cssParseAndValidate('@{.foobar .a-story .xyzzy}', cssWorld);
31 cssParseAndValidate('@{.foobar .xyzzy .a-story .b-story}', cssWorld);
32
33 // Valid selectors for element IDs.
34 cssParseAndValidate('@{#id1}', cssWorld);
35 cssParseAndValidate('@{#id-number-3}', cssWorld);
36 cssParseAndValidate('@{#_privateId}', cssWorld);
37
38 // Valid selectors for private class names (leading underscore).
39 cssParseAndValidate('@{.foobar ._privateClass}', cssWorld);
40 cssParseAndValidate('@{.foobar ._privateClass .xyzzy}', cssWorld);
41 cssParseAndValidate('@{.foobar ._private1 .xyzzy ._private2}', cssWorld);
42
43 // Valid selectors for private element IDs (leading underscore).
44 cssParseAndValidate('@{._privateClass}', cssWorld);
45 } catch (final e) {
46 // CSS Expressions failed
47 Expect.fail(e.toString());
48 }
49 }
50
51 static void testSimpleClassSelectorFailures() {
52 List<String> knownClasses = ['foobar', 'xyzzy', 'a-story', 'b-story'];
53 List<String> knownIds = ['id1', 'id2', 'id-number-3'];
54
55 CssWorld cssWorld = new CssWorld(knownClasses, knownIds);
56
57 // Invalid class name.
58 String css = '@{.-foobar}';
59 try {
60 cssParseAndValidate('${css}', cssWorld);
61 Expect.fail("${css} should not succeed.");
62 } catch (final e) {
63 Expect.equals("CssSelectorException: Unknown selector name .-foobar",
64 e.toString());
65 }
66
67 // Error this class name is not known.
68 css = '@{.foobar1}';
69 try {
70 cssParseAndValidate('${css}', cssWorld);
71 Expect.fail("${css} should not succeed.");
72 } catch (final e) {
73 Expect.equals("CssSelectorException: Unknown selector name .foobar1",
74 e.toString());
75 }
76
77 // Error if any class name is not known.
78 css = '@{.foobar .xyzzy1}';
79 try {
80 cssParseAndValidate('${css}', cssWorld);
81 Expect.fail("${css} should not succeed.");
82 } catch (final e) {
83 Expect.equals("CssSelectorException: Unknown selector name .xyzzy1",
84 e.toString());
85 }
86
87 // Test for invalid class name (can't start with number).
88 css = '@{.foobar .1a-story .xyzzy}';
89 try {
90 cssParseAndValidate('${css}', cssWorld);
91 Expect.fail("${css} should not succeed.");
92 } catch (final e) {
93 Expect.equals("${ERROR}1:11: fatal: parsing error expected }\n" +
94 "${css}\n ^^", e.toString());
95 }
96
97 // element id must be single selector.
98 css = '@{#id1 #id2}';
99 try {
100 cssParseAndValidate('${css}', cssWorld);
101 Expect.fail("${css} should not succeed.");
102 } catch (final e) {
103 Expect.equals("CssSelectorException: Use of Id selector must be " +
104 "singleton starting at #id2", e.toString());
105 }
106
107 // element id must be single selector.
108 css = '@{#id-number-3 .foobar}';
109 try {
110 cssParseAndValidate('${css}', cssWorld);
111 Expect.fail("@{#id-number-3 .foobar} should not succeed.");
112 } catch (final e) {
113 // CSS Expressions failed
114 Expect.equals("CssSelectorException: Can not mix Id selector with "+
115 "class selector(s). Id selector must be singleton too many " +
116 "starting at .foobar", e.toString(), '');
117 }
118
119 // element id must be alone and only one element id.
120 css = '@{.foobar #id-number-3 #id1}';
121 try {
122 cssParseAndValidate('${css}', cssWorld);
123 Expect.fail("${css} should not succeed.");
124 } catch (final e) {
125 // CSS Expressions failed
126 Expect.equals("CssSelectorException: Use of Id selector must be " +
127 "singleton starting at #id-number-3", e.toString());
128 }
129
130 // Namespace selector not valid in @{css_expression}
131 css = '@{foo|div}';
132 try {
133 cssParseAndValidate('${css}', cssWorld);
134 Expect.fail("${css} should not succeed.");
135 } catch (final e) {
136 Expect.equals("CssSelectorException: Invalid template selector foo|div",
137 e.toString());
138 }
139
140 // class and element id not allowed together.
141 css = '@{.foobar foo|div}';
142 try {
143 cssParseAndValidate('${css}', cssWorld);
144 Expect.fail("$css} should not succeed.");
145 } catch (final e) {
146 Expect.equals("CssSelectorException: Invalid template selector foo|div",
147 e.toString());
148 }
149
150 // Element id and namespace not allowed together.
151 css = '@{#id1 foo|div}';
152 try {
153 cssParseAndValidate('${css}', cssWorld);
154 Expect.fail("${css} should not succeed.");
155 } catch (final e) {
156 Expect.equals("CssSelectorException: Invalid template selector foo|div",
157 e.toString());
158 }
159
160 // namespace and element id not allowed together.
161 css = '@{foo|div #id1}';
162 try {
163 cssParseAndValidate('${css}', cssWorld);
164 Expect.fail("${css} should not succeed.");
165 } catch (final e) {
166 Expect.equals("CssSelectorException: Invalid template selector foo|div",
167 e.toString());
168 }
169
170 // namespace / element not allowed.
171 css = '@{foo|div .foobar}';
172 try {
173 cssParseAndValidate('${css}', cssWorld);
174 Expect.fail("${css} should not succeed.");
175 } catch (final e) {
176 Expect.equals("CssSelectorException: Invalid template selector foo|div",
177 e.toString());
178 }
179
180 // Combinators not allowed.
181 css = '@{.foobar > .xyzzy}';
182 try {
183 cssParseAndValidate('${css}', cssWorld);
184 Expect.fail("${css} should not succeed.");
185 } catch (final e) {
186 Expect.equals("CssSelectorException: Selectors can not have " +
187 "combinators (>, +, or ~) before >.xyzzy", e.toString());
188 }
189 }
190
191 static void testPrivateNameFailures() {
192 List<String> knownClasses = ['foobar', 'xyzzy', 'a-story', 'b-story'];
193 List<String> knownIds = ['id1', 'id2', 'id-number-3'];
194
195 CssWorld cssWorld = new CssWorld(knownClasses, knownIds);
196
197 // Too many.
198 String css = '@{._private #id2}';
199 try {
200 cssParseAndValidate('${css}', cssWorld);
201 Expect.fail("${css} should not succeed.");
202 } catch (final e) {
203 Expect.equals("CssSelectorException: Use of Id selector must be " +
204 "singleton starting at #id2", e.toString());
205 }
206
207 // Unknown class foobar2.
208 css = '@{._private .foobar2}';
209 try {
210 cssParseAndValidate('${css}', cssWorld);
211 Expect.fail("${css} should not succeed.");
212 } catch (final e) {
213 Expect.equals("CssSelectorException: Unknown selector name .foobar2",
214 e.toString());
215 }
216
217 // Too many element IDs.
218 css = '@{#_privateId #id2}';
219 try {
220 cssParseAndValidate('${css}', cssWorld);
221 Expect.fail("${css} should not succeed.");
222 } catch (final e) {
223 Expect.equals("CssSelectorException: Use of Id selector must be " +
224 "singleton starting at #id2", e.toString());
225 }
226
227 // Too many element IDs.
228 css = '@{#_privateId1 #_privateId2}';
229 try {
230 cssParseAndValidate('${css}', cssWorld);
231 Expect.fail("${css} should not succeed.");
232 } catch (final e) {
233 Expect.equals("CssSelectorException: Use of Id selector must be " +
234 "singleton starting at #_privateId2", e.toString());
235 }
236 }
237
238 }
239
240 main() {
241 SelectorLiteralTest.testMain();
242 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698