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

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

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

Powered by Google App Engine
This is Rietveld 408576698