| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 | 6 |
| 7 // Test cascades. | 7 // Test cascades. |
| 8 | 8 |
| 9 class A { | 9 class A { |
| 10 int x; | 10 int x; |
| 11 int y; | 11 int y; |
| 12 | 12 |
| 13 A(this.x, this.y); | 13 A(this.x, this.y); |
| 14 | 14 |
| 15 A setX(int x) { | 15 A setX(int x) { this.x = x; return this; } |
| 16 this.x = x; | |
| 17 return this; | |
| 18 } | |
| 19 | 16 |
| 20 void setY(int y) { | 17 void setY(int y) { this.y = y; } |
| 21 this.y = y; | |
| 22 } | |
| 23 | 18 |
| 24 Function swap() { | 19 Function swap() { |
| 25 int tmp = x; | 20 int tmp = x; |
| 26 x = y; | 21 x = y; |
| 27 y = tmp; | 22 y = tmp; |
| 28 return this.swap; | 23 return this.swap; |
| 29 } | 24 } |
| 30 | 25 |
| 31 void check(int x, int y) { | 26 void check(int x, int y) { |
| 32 Expect.equals(x, this.x); | 27 Expect.equals(x, this.x); |
| 33 Expect.equals(y, this.y); | 28 Expect.equals(y, this.y); |
| 34 } | 29 } |
| 35 | 30 |
| 36 operator [](var i) { | 31 operator[](var i) { |
| 37 if (i == 0) return x; | 32 if (i == 0) return x; |
| 38 if (i == 1) return y; | 33 if (i == 1) return y; |
| 39 if (i == "swap") return this.swap; | 34 if (i == "swap") return this.swap; |
| 40 return null; | 35 return null; |
| 41 } | 36 } |
| 42 | 37 |
| 43 int operator []=(int i, int value) { | 38 int operator[]=(int i, int value) { |
| 44 if (i == 0) { | 39 if (i == 0) { |
| 45 x = value; | 40 x = value; |
| 46 } else if (i == 1) { | 41 } else if (i == 1) { |
| 47 y = value; | 42 y = value; |
| 48 } | 43 } |
| 49 } | 44 } |
| 50 | 45 |
| 51 /** | 46 /** |
| 52 * A pseudo-keyword. | 47 * A pseudo-keyword. |
| 53 */ | 48 */ |
| 54 import() { | 49 import() { |
| 55 x++; | 50 x++; |
| 56 } | 51 } |
| 57 } | 52 } |
| 58 | 53 |
| 59 main() { | 54 main() { |
| 60 A a = new A(1, 2); | 55 A a = new A(1, 2); |
| 61 a | 56 a..check(1, 2) |
| 62 ..check(1, 2) | 57 ..swap()..check(2, 1) |
| 63 ..swap() | 58 ..x = 4..y = 9..check(4, 9) |
| 64 ..check(2, 1) | 59 ..setX(10)..check(10, 9) |
| 65 ..x = 4 | 60 ..y = 5..check(10, 5) |
| 66 ..y = 9 | 61 ..swap()()()..check(5, 10) |
| 67 ..check(4, 9) | 62 ..[0] = 2..check(2, 10) |
| 68 ..setX(10) | 63 ..setX(10).setY(3)..check(10, 3) |
| 69 ..check(10, 9) | 64 ..setX(7)["swap"]()..check(3, 7) |
| 70 ..y = 5 | 65 ..import()..check(4, 7) |
| 71 ..check(10, 5) | 66 ..["swap"]()()()..check(7, 4); |
| 72 ..swap()()() | 67 a.check(7,4); |
| 73 ..check(5, 10) | |
| 74 ..[0] = 2 | |
| 75 ..check(2, 10) | |
| 76 ..setX(10).setY(3) | |
| 77 ..check(10, 3) | |
| 78 ..setX(7)["swap"]() | |
| 79 ..check(3, 7) | |
| 80 ..import() | |
| 81 ..check(4, 7) | |
| 82 ..["swap"]()()() | |
| 83 ..check(7, 4); | |
| 84 a.check(7, 4); | |
| 85 a..(42); // //# 01: compile-time error | 68 a..(42); // //# 01: compile-time error |
| 86 a..37; // //# 02: compile-time error | 69 a..37; // //# 02: compile-time error |
| 87 a.."foo"; // //# 03: compile-time error | 70 a.."foo"; // //# 03: compile-time error |
| 88 } | 71 } |
| OLD | NEW |