OLD | NEW |
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 // Operator dart test program. | 4 // Operator dart test program. |
5 | 5 |
6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 | 7 |
8 class Helper { | 8 class Helper { |
9 int i; | 9 int i; |
10 Helper(int val) : i = val { } | 10 Helper(int val) : i = val {} |
11 operator [](int index) { | 11 operator [](int index) { |
12 return i + index; | 12 return i + index; |
13 } | 13 } |
| 14 |
14 void operator []=(int index, int val) { | 15 void operator []=(int index, int val) { |
15 i = val; | 16 i = val; |
16 } | 17 } |
17 } | 18 } |
18 | 19 |
19 class OperatorTest { | 20 class OperatorTest { |
20 static testMain() { | 21 static testMain() { |
21 Helper obj = new Helper(10); | 22 Helper obj = new Helper(10); |
22 Expect.equals(10, obj.i); | 23 Expect.equals(10, obj.i); |
23 obj[10] = 20; | 24 obj[10] = 20; |
24 Expect.equals(30, obj[10]); | 25 Expect.equals(30, obj[10]); |
25 } | 26 } |
26 } | 27 } |
27 | 28 |
28 | |
29 main() { | 29 main() { |
30 OperatorTest.testMain(); | 30 OperatorTest.testMain(); |
31 } | 31 } |
OLD | NEW |