Index: tests/language/src/SuperOperatorTest.dart |
=================================================================== |
--- tests/language/src/SuperOperatorTest.dart (revision 358) |
+++ tests/language/src/SuperOperatorTest.dart (working copy) |
@@ -6,25 +6,57 @@ |
class A { |
String val = ""; |
+ List things; |
+ |
+ A() : things = ['D', 'a', 'r', 't', 42]; |
+ |
operator + (String s) { |
val = val + s; |
return this; |
} |
+ |
+ operator [] (i) { |
+ return things[i]; |
+ } |
+ |
+ operator []= (i, val) { |
+ return things[i] = val; |
+ } |
} |
+ |
class B extends A { |
operator + (String s) { |
- super + (s + s); |
+ super + (s + s); // Call A.operator+(this, s + s). |
return this; |
} |
+ |
+ operator [] (i) { |
+ var temp = super[i]; |
+ return temp + temp; |
+ } |
+ |
+ operator []= (i, val) { |
+ // Make sure the index expression is only evaluated |
+ // once in the presence of a compound assignment. |
+ return super[i++] += val; |
+ } |
+ |
} |
main () { |
var a = new A(); |
- a = a + "William"; |
+ a = a + "William"; // operator + of class A. |
Expect.equals("William", a.val); |
+ Expect.equals("r", a[2]); // operator [] of class A. |
a = new B(); |
- a += "Tell"; |
+ a += "Tell"; // operator + of class B. |
Expect.equals("TellTell", a.val); |
+ Expect.equals("rr", a[2]); // operator [] of class B. |
+ |
+ a[4] = 1; // operator []= of class B. |
+ Expect.equals(43, a.things[4]); |
+ Expect.equals(86, a[4]); |
+ |
} |