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

Side by Side Diff: tests/language/getters_setters2_test.dart

Issue 2774783002: Re-land "Format all multitests" (Closed)
Patch Set: Created 3 years, 9 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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 4
5 import "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 6
7 // Tests classes with getters and setters that do not have the same type. 7 // Tests classes with getters and setters that do not have the same type.
8 8
9 class A { 9 class A {
10 int a() { return 37;} 10 int a() {
11 return 37;
12 }
11 } 13 }
12 14
13 class B extends A{ 15 class B extends A {
14 int b() { return 38; } 16 int b() {
17 return 38;
18 }
15 } 19 }
16 20
17 class C {} 21 class C {}
18 22
19 class T1 { 23 class T1 {
20 A getterField; 24 A getterField;
21 A get field { return getterField; } 25 A get field {
26 return getterField;
27 }
28
22 // OK, B is assignable to A 29 // OK, B is assignable to A
23 void set field(B arg) { getterField = arg; } 30 void set field(B arg) {
31 getterField = arg;
32 }
24 } 33 }
25 34
26 class T2 { 35 class T2 {
27 A getterField; 36 A getterField;
28 C setterField; 37 C setterField;
29 A get field { return getterField; } 38 A get field {
39 return getterField;
40 }
30 41
31 // Type C is not assignable to A 42 // Type C is not assignable to A
32 void set field(C arg) { setterField = arg; } //# 01: static type warning 43 void set field(C arg) { setterField = arg; } //# 01: static type warning
33 } 44 }
34 45
35 class T3 { 46 class T3 {
36 B getterField; 47 B getterField;
37 B get field { return getterField; } 48 B get field {
49 return getterField;
50 }
51
38 // OK, A is assignable to B 52 // OK, A is assignable to B
39 void set field(A arg) { getterField = arg; } 53 void set field(A arg) {
54 getterField = arg;
55 }
40 } 56 }
41 57
42
43 main() { 58 main() {
44 T1 instance1 = new T1(); 59 T1 instance1 = new T1();
45 T2 instance2 = new T2(); //# 01: continued 60 T2 instance2 = new T2(); //# 01: continued
46 T3 instance3 = new T3(); 61 T3 instance3 = new T3();
47 62
48 instance1.field = new B(); 63 instance1.field = new B();
49 A resultA = instance1.field; 64 A resultA = instance1.field;
50 instance1.field = new A(); //# 03: dynamic type error 65 instance1.field = new A(); //# 03: dynamic type error
51 B resultB = instance1.field; 66 B resultB = instance1.field;
52 67
53 int result; 68 int result;
54 result = instance1.field.a(); 69 result = instance1.field.a();
55 Expect.equals(37, result); 70 Expect.equals(37, result);
56 71
57 // Type 'A' has no method named 'b' 72 // Type 'A' has no method named 'b'
58 instance1.field.b(); //# 02: static type warning 73 instance1.field.b(); //# 02: static type warning
59 74
60 instance3.field = new B(); 75 instance3.field = new B();
61 result = instance3.field.a(); 76 result = instance3.field.a();
62 Expect.equals(37, result); 77 Expect.equals(37, result);
63 result = instance3.field.b(); 78 result = instance3.field.b();
64 Expect.equals(38, result); 79 Expect.equals(38, result);
65 } 80 }
OLDNEW
« no previous file with comments | « tests/language/getter_parameters_test.dart ('k') | tests/language/getters_setters_type_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698