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