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

Side by Side Diff: tests/language/src/NamingTest.dart

Issue 10248007: test rename overhaul: step 8 - language tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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 | « tests/language/src/Naming2Test.dart ('k') | tests/language/src/NativeTest.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 class A {
6 A() { NamingTest.count++; }
7 foo(a, b) {
8 Expect.equals(1, a);
9 Expect.equals(2, b);
10 }
11 }
12
13 class MyException {
14 MyException() {}
15 }
16
17 class debugger {
18 static final int __PROTO__ = 5;
19
20 int x;
21
22 factory debugger.F() {
23 return new debugger(1);
24 }
25 debugger(x) : this.x = x + 1 { }
26 debugger.C(x) : this.x = x + 2 { }
27 debugger.C$C(x) : this.x = x + 3 { }
28 debugger.C$I(x) : this.x = x + 4 { }
29 }
30
31 class debugger$C {
32 int x;
33
34 factory debugger$C.F() {
35 return new debugger$C(1);
36 }
37 debugger$C(x) : this.x = x + 5 { }
38 debugger$C.C(x) : this.x = x + 6 { }
39 debugger$C.C$C(x) : this.x = x + 7 { }
40 debugger$C.C$I(x) : this.x = x + 8 { }
41 }
42
43 class debugger$C$C {
44 int x;
45
46 factory debugger$C$C.F() {
47 return new debugger$C$C(1);
48 }
49 debugger$C$C(x) : this.x = x + 9 { }
50 debugger$C$C.C(x) : this.x = x + 10 { }
51 debugger$C$C.C$C(x) : this.x = x + 11 { }
52 debugger$C$C.C$I(x) : this.x = x + 12 { }
53 }
54
55 class with extends debugger$C {
56 int y;
57
58 factory with.F() {
59 return new with(1, 2);
60 }
61 with(x, y) : super(x), this.y = y + 1 { }
62 with.I(x, y) : super.C(x), this.y = y + 2 { }
63 with.C(x, y) : super.C$C(x), this.y = y + 3 { }
64 with.I$C(x, y) : super.C$I(x), this.y = y + 4 { }
65 with.C$C(x, y) : super(x), this.y = y + 5 { }
66 with.C$C$C(x, y) : super.C(x), this.y = y + 6 { }
67 with.$C$I(x, y) : super.C$C(x), this.y = y + 7 { }
68 with.$$I$C(x, y) : super.C$I(x), this.y = y + 8 { }
69 with.$(x, y) : super(x), this.y = y + 9 { }
70 with.$$(x, y) : super.C(x), this.y = y + 10 { }
71 }
72
73 class with$I extends debugger$C {
74 int y;
75
76 factory with$I.F() {
77 return new with$I(1, 2);
78 }
79 with$I(x, y) : super(x), this.y = y + 11 { }
80 with$I.I(x, y) : super.C(x), this.y = y + 12 { }
81 with$I.C(x, y) : super.C$C(x), this.y = y + 13 { }
82 with$I.I$C(x, y) : super.C$I(x), this.y = y + 14 { }
83 with$I.C$C(x, y) : super(x), this.y = y + 15 { }
84 with$I.C$C$C(x, y) : super.C(x), this.y = y + 16 { }
85 with$I.$C$I(x, y) : super.C$C(x), this.y = y + 17 { }
86 with$I.$$I$C(x, y) : super.C$I(x), this.y = y + 18 { }
87 with$I.$(x, y) : super(x), this.y = y + 19 { }
88 with$I.$$(x, y) : super.C(x), this.y = y + 20 { }
89 }
90
91 class with$C extends debugger$C$C {
92 int y;
93
94 factory with$C.F() {
95 return new with$C(1, 2);
96 }
97 with$C(x, y) : super(x), this.y = y + 21 { }
98 with$C.I(x, y) : super.C(x), this.y = y + 22 { }
99 with$C.C(x, y) : super.C$C(x), this.y = y + 23 { }
100 with$C.I$C(x, y) : super.C$I(x), this.y = y + 24 { }
101 with$C.C$C(x, y) : super(x), this.y = y + 25 { }
102 with$C.C$C$C(x, y) : super.C(x), this.y = y + 26 { }
103 with$C.$C$I(x, y) : super.C$C(x), this.y = y + 27 { }
104 with$C.$$I$C(x, y) : super.C$I(x), this.y = y + 28 { }
105 with$C.$(x, y) : super(x), this.y = y + 29 { }
106 with$C.$$(x, y) : super.C(x), this.y = y + 30 { }
107 }
108
109 class with$I$C extends debugger$C$C {
110 int y;
111
112 factory with$I$C.F() {
113 return new with$I$C(1, 2);
114 }
115 with$I$C(x, y) : super(x), this.y = y + 31 { }
116 with$I$C.I(x, y) : super.C(x), this.y = y + 32 { }
117 with$I$C.C(x, y) : super.C$C(x), this.y = y + 33 { }
118 with$I$C.I$C(x, y) : super.C$I(x), this.y = y + 34 { }
119 with$I$C.C$C(x, y) : super(x), this.y = y + 35 { }
120 with$I$C.C$C$C(x, y) : super.C(x), this.y = y + 36 { }
121 with$I$C.$C$I(x, y) : super.C$C(x), this.y = y + 37 { }
122 with$I$C.$$I$C(x, y) : super.C$I(x), this.y = y + 38 { }
123 with$I$C.$(x, y) : super(x), this.y = y + 39 { }
124 with$I$C.$$(x, y) : super.C(x), this.y = y + 40 { }
125 }
126
127 class Tata {
128 var prototype;
129
130 Tata() : this.prototype = 0 {}
131
132 __PROTO__$() { return 12; }
133 }
134
135 class Toto extends Tata {
136 var __PROTO__;
137
138 Toto() : super(), this.__PROTO__ = 0 { }
139
140 prototype$() { return 10; }
141
142 titi() {
143 Expect.equals(0, prototype);
144 Expect.equals(0, __PROTO__);
145 prototype = 3;
146 __PROTO__ = 5;
147 Expect.equals(3, prototype);
148 Expect.equals(5, __PROTO__);
149 Expect.equals(10, prototype$());
150 Expect.equals(12, __PROTO__$());
151 Expect.equals(12, this.__PROTO__$());
152 Expect.equals(10, this.prototype$());
153 Expect.equals(12, __PROTO__$());
154 }
155 }
156
157 class Bug4082360 {
158 int x_;
159 Bug4082360() {}
160
161 int get x() { return x_; }
162 void set x(int value) { x_ = value; }
163
164 void indirectSet(int value) { x = value; }
165
166 static void test() {
167 var bug = new Bug4082360();
168 bug.indirectSet(42);
169 Expect.equals(42, bug.x_);
170 Expect.equals(42, bug.x);
171 }
172 }
173
174 class Hoisting {
175 var f_;
176 Hoisting.negate(var x) {
177 f_ = () { return x; };
178 }
179
180 operator negate() {
181 var x = 3;
182 return () { return x + 1; };
183 }
184
185 operator[] (x) {
186 return () { return x + 3; };
187 }
188
189 static void test() {
190 var h = new Hoisting.negate(1);
191 Expect.equals(1, (h.f_)());
192 var f = -h;
193 Expect.equals(4, f());
194 Expect.equals(4, h.negate()());
195 Expect.equals(7, h[4]());
196 }
197 }
198
199 // It is not possible to make sure that the backend uses the hardcoded names
200 // we are testing against. This test might therefore become rapidly out of date
201 class NamingTest {
202 static int count;
203
204 static testExceptionNaming() {
205 // Exceptions use a hardcoded "e" as exception name. If the namer works
206 // correctly then it will be renamed in case of clashes.
207 var e = 3;
208 var caught = false;
209 try {
210 throw new MyException();
211 } catch (var exc) {
212 try {
213 throw new MyException();
214 } catch (var exc2) {
215 exc = 9;
216 }
217 Expect.equals(9, exc);
218 caught = true;
219 }
220 Expect.equals(true, caught);
221 Expect.equals(3, e);
222 }
223
224 static testTmpNaming() {
225 Expect.equals(0, count);
226 var tmp$0 = 1;
227 var tmp$1 = 2;
228 new A().foo(tmp$0, tmp$1++);
229 Expect.equals(1, count);
230 Expect.equals(3, tmp$1);
231 }
232
233 static testScopeNaming() {
234 // Alias scopes use a hardcoded "dartc_scp$<depth>" as names.
235 var dartc_scp$1 = 5;
236 var foo = 8;
237 var f = () {
238 var dartc_scp$1 = 15;
239 return foo + dartc_scp$1;
240 };
241 Expect.equals(5, dartc_scp$1);
242 Expect.equals(23, f());
243 }
244
245 static testGlobalMangling() {
246 var x;
247 x = new debugger(0);
248 Expect.equals(1, x.x);
249 x = new debugger.C(0);
250 Expect.equals(2, x.x);
251 x = new debugger.C$C(0);
252 Expect.equals(3, x.x);
253 x = new debugger.C$I(0);
254 Expect.equals(4, x.x);
255 x = new debugger$C(0);
256 Expect.equals(5, x.x);
257 x = new debugger$C.C(0);
258 Expect.equals(6, x.x);
259 x = new debugger$C.C$C(0);
260 Expect.equals(7, x.x);
261 x = new debugger$C.C$I(0);
262 Expect.equals(8, x.x);
263 x = new debugger$C$C(0);
264 Expect.equals(9, x.x);
265 x = new debugger$C$C.C(0);
266 Expect.equals(10, x.x);
267 x = new debugger$C$C.C$C(0);
268 Expect.equals(11, x.x);
269 x = new debugger$C$C.C$I(0);
270 Expect.equals(12, x.x);
271 x = new with(0, 0);
272 Expect.equals(5, x.x);
273 Expect.equals(1, x.y);
274 x = new with.I(0, 0);
275 Expect.equals(6, x.x);
276 Expect.equals(2, x.y);
277 x = new with.C(0, 0);
278 Expect.equals(7, x.x);
279 Expect.equals(3, x.y);
280 x = new with.I$C(0, 0);
281 Expect.equals(8, x.x);
282 Expect.equals(4, x.y);
283 x = new with.C$C(0, 0);
284 Expect.equals(5, x.x);
285 Expect.equals(5, x.y);
286 x = new with.C$C$C(0, 0);
287 Expect.equals(6, x.x);
288 Expect.equals(6, x.y);
289 x = new with.$C$I(0, 0);
290 Expect.equals(7, x.x);
291 Expect.equals(7, x.y);
292 x = new with.$$I$C(0, 0);
293 Expect.equals(8, x.x);
294 Expect.equals(8, x.y);
295 x = new with.$(0, 0);
296 Expect.equals(5, x.x);
297 Expect.equals(9, x.y);
298 x = new with.$$(0, 0);
299 Expect.equals(6, x.x);
300 Expect.equals(10, x.y);
301 x = new with$I(0, 0);
302 Expect.equals(5, x.x);
303 Expect.equals(11, x.y);
304 x = new with$I.I(0, 0);
305 Expect.equals(6, x.x);
306 Expect.equals(12, x.y);
307 x = new with$I.C(0, 0);
308 Expect.equals(7, x.x);
309 Expect.equals(13, x.y);
310 x = new with$I.I$C(0, 0);
311 Expect.equals(8, x.x);
312 Expect.equals(14, x.y);
313 x = new with$I.C$C(0, 0);
314 Expect.equals(5, x.x);
315 Expect.equals(15, x.y);
316 x = new with$I.C$C$C(0, 0);
317 Expect.equals(6, x.x);
318 Expect.equals(16, x.y);
319 x = new with$I.$C$I(0, 0);
320 Expect.equals(7, x.x);
321 Expect.equals(17, x.y);
322 x = new with$I.$$I$C(0, 0);
323 Expect.equals(8, x.x);
324 Expect.equals(18, x.y);
325 x = new with$I.$(0, 0);
326 Expect.equals(5, x.x);
327 Expect.equals(19, x.y);
328 x = new with$I.$$(0, 0);
329 Expect.equals(6, x.x);
330 Expect.equals(20, x.y);
331 x = new with$C(0, 0);
332 Expect.equals(9, x.x);
333 Expect.equals(21, x.y);
334 x = new with$C.I(0, 0);
335 Expect.equals(10, x.x);
336 Expect.equals(22, x.y);
337 x = new with$C.C(0, 0);
338 Expect.equals(11, x.x);
339 Expect.equals(23, x.y);
340 x = new with$C.I$C(0, 0);
341 Expect.equals(12, x.x);
342 Expect.equals(24, x.y);
343 x = new with$C.C$C(0, 0);
344 Expect.equals(9, x.x);
345 Expect.equals(25, x.y);
346 x = new with$C.C$C$C(0, 0);
347 Expect.equals(10, x.x);
348 Expect.equals(26, x.y);
349 x = new with$C.$C$I(0, 0);
350 Expect.equals(11, x.x);
351 Expect.equals(27, x.y);
352 x = new with$C.$$I$C(0, 0);
353 Expect.equals(12, x.x);
354 Expect.equals(28, x.y);
355 x = new with$C.$(0, 0);
356 Expect.equals(9, x.x);
357 Expect.equals(29, x.y);
358 x = new with$C.$$(0, 0);
359 Expect.equals(10, x.x);
360 Expect.equals(30, x.y);
361 x = new with$I$C(0, 0);
362 Expect.equals(9, x.x);
363 Expect.equals(31, x.y);
364 x = new with$I$C.I(0, 0);
365 Expect.equals(10, x.x);
366 Expect.equals(32, x.y);
367 x = new with$I$C.C(0, 0);
368 Expect.equals(11, x.x);
369 Expect.equals(33, x.y);
370 x = new with$I$C.I$C(0, 0);
371 Expect.equals(12, x.x);
372 Expect.equals(34, x.y);
373 x = new with$I$C.C$C(0, 0);
374 Expect.equals(9, x.x);
375 Expect.equals(35, x.y);
376 x = new with$I$C.C$C$C(0, 0);
377 Expect.equals(10, x.x);
378 Expect.equals(36, x.y);
379 x = new with$I$C.$C$I(0, 0);
380 Expect.equals(11, x.x);
381 Expect.equals(37, x.y);
382 x = new with$I$C.$$I$C(0, 0);
383 Expect.equals(12, x.x);
384 Expect.equals(38, x.y);
385 x = new with$I$C.$(0, 0);
386 Expect.equals(9, x.x);
387 Expect.equals(39, x.y);
388 x = new with$I$C.$$(0, 0);
389 Expect.equals(10, x.x);
390 Expect.equals(40, x.y);
391 var wasCaught = false;
392 try {
393 throw new with(0, 0);
394 } catch(with e) {
395 wasCaught = true;
396 Expect.equals(5, e.x);
397 }
398 Expect.equals(true, wasCaught);
399 }
400
401 static void testMemberMangling() {
402 Expect.equals(5, debugger.__PROTO__);
403 new Toto().titi();
404 }
405
406 static void testFactoryMangling() {
407 var o = new debugger.F();
408 Expect.equals(2, o.x);
409 o = new debugger$C.F();
410 Expect.equals(6, o.x);
411 o = new debugger$C$C.F();
412 Expect.equals(10, o.x);
413 o = new with.F();
414 Expect.equals(6, o.x);
415 Expect.equals(3, o.y);
416 o = new with$I.F();
417 Expect.equals(6, o.x);
418 Expect.equals(13, o.y);
419 o = new with$C.F();
420 Expect.equals(10, o.x);
421 Expect.equals(23, o.y);
422 o = new with$I$C.F();
423 Expect.equals(10, o.x);
424 Expect.equals(33, o.y);
425 }
426
427 static testFunctionParameters() {
428 a(with) {
429 return with;
430 }
431
432 b(eval) {
433 return eval;
434 }
435
436 c(arguments) {
437 return arguments;
438 }
439
440 Expect.equals(10, a(10));
441 Expect.equals(10, b(10));
442 Expect.equals(10, c(10));
443 }
444
445 static testPseudoTokens() {
446 var EOS = 400;
447 var ILLEGAL = 99;
448 Expect.equals(499, EOS + ILLEGAL);
449 }
450
451 static testDollar() {
452 Expect.equals(123, $(123).wrapped);
453 var x = new Object(), y = new Object();
454 Expect.identical(x, $(x).wrapped);
455 Expect.identical(y, $(x).$add(y));
456 Expect.identical(x, $(x).$negate());
457 Expect.equals(123, $(x) + x);
458 Expect.equals(444, -$(x));
459 }
460
461 static void testMain() {
462 count = 0;
463 testExceptionNaming();
464 testTmpNaming();
465 testScopeNaming();
466 testGlobalMangling();
467 testMemberMangling();
468 testFactoryMangling();
469 testFunctionParameters();
470 Bug4082360.test();
471 Hoisting.test();
472 testPseudoTokens();
473 testDollar();
474 }
475 }
476
477 // Test that the generated JS names don't conflict with "$"
478 class DartQuery {
479 Object wrapped;
480 DartQuery(this.wrapped);
481
482 $add(Object other) => other;
483 $negate() => wrapped;
484
485 operator +(Object other) => 123;
486 operator negate() => 444;
487 }
488
489 $add(Object first, Object second) => second;
490 DartQuery $(Object obj) => new DartQuery(obj);
491
492 // Ensure we don't have false positive. named constructor and methods
493 // are in different namespaces, therefore it is ok to have a method
494 // called foo and a named constructor CLASS.foo
495 class Naming1Test {
496 Naming1Test.foo() { }
497 foo() { }
498
499 static void main(args) {
500 var a = new Naming1Test.foo();
501 a.foo();
502 }
503 }
504
505 // Ensure we don't have false positive.
506 class Naming2Test {
507 Naming2Test() { }
508 int get foo() { return 1; }
509 set foo(x) { }
510
511 static void main(args) {
512 var a = new Naming2Test();
513 Expect.throws(() => a.foo(2), (e) => e is ObjectNotClosureException);
514 }
515 }
516
517 main() {
518 NamingTest.testMain();
519 Naming1Test.main(null);
520 Naming2Test.main(null);
521 }
OLDNEW
« no previous file with comments | « tests/language/src/Naming2Test.dart ('k') | tests/language/src/NativeTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698