Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012, 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 // Test cascades. | |
| 6 | |
| 7 class A { | |
| 8 int x; | |
| 9 int y; | |
| 10 A(this.x, this.y); | |
| 11 A setX(int x) { this.x = x; return this; } | |
|
ahe
2012/04/16 08:55:23
Would be nice with a single empty line between the
Lasse Reichstein Nielsen
2012/04/16 12:41:38
Done.
| |
| 12 void setY(int y) { this.y = y; } | |
| 13 Function swap() { | |
| 14 int tmp = x; | |
| 15 x = y; | |
| 16 y = tmp; | |
| 17 return this.swap; | |
| 18 } | |
| 19 void check(int x, int y) { | |
| 20 Expect.equals(x, this.x); | |
| 21 Expect.equals(y, this.y); | |
| 22 } | |
| 23 int operator[](var i) { | |
| 24 if (i == 0) return x; | |
| 25 if (i == 1) return y; | |
| 26 if (i == "swap") return this.swap; | |
| 27 return null; | |
| 28 } | |
| 29 int operator[]=(int i, int value) { | |
| 30 if (i == 0) { | |
| 31 x = value; | |
| 32 } else if (i == 1) { | |
| 33 y = value; | |
| 34 } | |
| 35 } | |
| 36 } | |
| 37 | |
| 38 main() { | |
| 39 A a = new A(1, 2); | |
| 40 a..check(1, 2) | |
| 41 ..swap()..check(2, 1) | |
| 42 ..x = 4..y = 9..check(4, 9) | |
| 43 ..setX(10)..check(10, 9) | |
| 44 ..y = 5..check(10, 5) | |
| 45 ..swap()()()..check(5, 10) | |
| 46 ..[0] = 2..check(2, 10) | |
| 47 ..setX(10).setY(3)..check(10, 3) | |
| 48 ..setX(7)["swap"]()..check(3, 7) | |
| 49 ..["swap"]()()()..check(7, 3); | |
|
ahe
2012/04/16 08:55:23
I think this test will pass if cascades are no-ops
Lasse Reichstein Nielsen
2012/04/16 12:41:38
Good point. Done.
| |
| 50 a..(42); /// 01: compile-time error | |
|
ahe
2012/04/16 08:55:23
Additional suggestions for tests:
a..42; /// 02:
Lasse Reichstein Nielsen
2012/04/16 12:41:38
Done.
| |
| 51 } | |
| OLD | NEW |