Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(860)

Side by Side Diff: tests/language/src/SuperOperatorTest.dart

Issue 9969159: - Remove more String operator + from tests. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // Dart test for testing super operator calls 4 // Dart test for testing super operator calls
5 5
6 6
7 class A { 7 class A {
8 String val = ""; 8 String val = "";
9 List things; 9 List things;
10 10
11 A() : things = ['D', 'a', 'r', 't', 42]; 11 A() : things = ['D', 'a', 'r', 't', 42];
12 12
13 operator + (String s) { 13 operator + (String s) {
14 val = val + s; 14 val = "${val}${s}";
hausner 2012/04/11 18:01:24 or val.concat(s);
15 return this; 15 return this;
16 } 16 }
17 17
18 operator [] (i) { 18 operator [] (i) {
19 return things[i]; 19 return things[i];
20 } 20 }
21 21
22 operator []= (i, val) { 22 operator []= (i, val) {
23 return things[i] = val; 23 return things[i] = val;
24 } 24 }
25 } 25 }
26 26
27 27
28 class B extends A { 28 class B extends A {
29 operator + (String s) { 29 operator + (String s) {
30 super + (s + s); // Call A.operator+(this, s + s). 30 super + ("${s}${s}"); // Call A.operator+(this, s + s).
hausner 2012/04/11 18:01:24 + in comment is meaningless.
Ivan Posva 2012/04/13 13:29:17 Done.
31 return this; 31 return this;
32 } 32 }
33 33
34 operator [] (i) { 34 operator [] (i) {
35 var temp = super[i]; 35 var temp = super[i];
36 if (temp is String) {
37 return "$temp$temp";
hausner 2012/04/11 18:01:24 or return temp.concat(temp);
38 }
36 return temp + temp; 39 return temp + temp;
37 } 40 }
38 41
39 operator []= (i, val) { 42 operator []= (i, val) {
40 // Make sure the index expression is only evaluated 43 // Make sure the index expression is only evaluated
41 // once in the presence of a compound assignment. 44 // once in the presence of a compound assignment.
42 return super[i++] += val; 45 return super[i++] += val;
43 } 46 }
44 47
45 } 48 }
46 49
47 main () { 50 main () {
48 var a = new A(); 51 var a = new A();
49 a = a + "William"; // operator + of class A. 52 a = a + "William"; // operator + of class A.
50 Expect.equals("William", a.val); 53 Expect.equals("William", a.val);
51 Expect.equals("r", a[2]); // operator [] of class A. 54 Expect.equals("r", a[2]); // operator [] of class A.
52 55
53 a = new B(); 56 a = new B();
54 a += "Tell"; // operator + of class B. 57 a += "Tell"; // operator + of class B.
55 Expect.equals("TellTell", a.val); 58 Expect.equals("TellTell", a.val);
56 Expect.equals("rr", a[2]); // operator [] of class B. 59 Expect.equals("rr", a[2]); // operator [] of class B.
57 60
58 a[4] = 1; // operator []= of class B. 61 a[4] = 1; // operator []= of class B.
59 Expect.equals(43, a.things[4]); 62 Expect.equals(43, a.things[4]);
60 Expect.equals(86, a[4]); 63 Expect.equals(86, a[4]);
61 64
62 } 65 }
OLDNEW
« tests/language/src/StringConcatTest.dart ('K') | « tests/language/src/StringConcatTest.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698