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

Side by Side Diff: utils/tests/css/selector_literal_tests.dart

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

Powered by Google App Engine
This is Rietveld 408576698