| 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 class A { | |
| 6 List<int> list; | |
| 7 A(int a, int b) : list = <int>[a, b]; | |
| 8 operator [](index) => list[index]; | |
| 9 operator []=(index, value) => list[index] = value; | |
| 10 } | |
| 11 | |
| 12 class B { | |
| 13 int value; | |
| 14 List trace; | |
| 15 B(this.trace) : value = 100; | |
| 16 operator [](index) { | |
| 17 trace.add(-3); | |
| 18 trace.add(index); | |
| 19 trace.add(this.value); | |
| 20 this.value = this.value + 1; | |
| 21 return this; | |
| 22 } | |
| 23 | |
| 24 operator []=(index, value) { | |
| 25 trace.add(-5); | |
| 26 trace.add(index); | |
| 27 trace.add(value.value); | |
| 28 this.value = this.value + 1; | |
| 29 } | |
| 30 | |
| 31 operator +(int value) { | |
| 32 trace.add(-4); | |
| 33 trace.add(this.value); | |
| 34 trace.add(value); | |
| 35 this.value = this.value + 1; | |
| 36 return this; | |
| 37 } | |
| 38 } | |
| 39 | |
| 40 B getB(trace) { | |
| 41 trace.add(-1); | |
| 42 return new B(trace); | |
| 43 } | |
| 44 int getIndex(trace) { | |
| 45 trace.add(-2); | |
| 46 return 42; | |
| 47 } | |
| 48 | |
| 49 main() { | |
| 50 A a = new A(1, 2); | |
| 51 Expect.equals(1, a[0]); | |
| 52 Expect.equals(2, a[1]); | |
| 53 | |
| 54 Expect.equals(1, a[0]++); | |
| 55 Expect.equals(2, a[0]); | |
| 56 | |
| 57 Expect.equals(2, a[0]--); | |
| 58 Expect.equals(1, a[0]); | |
| 59 | |
| 60 Expect.equals(0, --a[0]); | |
| 61 Expect.equals(0, a[0]); | |
| 62 | |
| 63 Expect.equals(1, ++a[0]); | |
| 64 Expect.equals(1, a[0]); | |
| 65 | |
| 66 a[0] += 2; | |
| 67 Expect.equals(3, a[0]); | |
| 68 | |
| 69 List trace = new List(); | |
| 70 getB(trace)[getIndex(trace)] += 37; | |
| 71 | |
| 72 Expect.listEquals([-1, -2, -3, 42, 100, -4, 101, 37, -5, 42, 102], trace); | |
| 73 } | |
| OLD | NEW |