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

Side by Side Diff: tests/language/call_through_getter_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) 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 4
5 import "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 6
7 // Tests that we can call functions through getters. 7 // Tests that we can call functions through getters.
8 8
9 const TOP_LEVEL_CONST = 1; 9 const TOP_LEVEL_CONST = 1;
10 const TOP_LEVEL_CONST_REF = TOP_LEVEL_CONST; 10 const TOP_LEVEL_CONST_REF = TOP_LEVEL_CONST;
11 const TOP_LEVEL_NULL = null; 11 const TOP_LEVEL_NULL = null;
12 12
13 var topLevel; 13 var topLevel;
14 14
15 class CallThroughGetterTest { 15 class CallThroughGetterTest {
16
17 static void testMain() { 16 static void testMain() {
18 testTopLevel(); 17 testTopLevel();
19 testField(); 18 testField();
20 testGetter(); 19 testGetter();
21 testMethod(); 20 testMethod();
22 testEvaluationOrder(); 21 testEvaluationOrder();
23 } 22 }
24 23
25 static void testTopLevel() { 24 static void testTopLevel() {
26 topLevel = () { 25 topLevel = () {
(...skipping 15 matching lines...) Expand all
42 A a = new A(); 41 A a = new A();
43 a.field = () => 42; 42 a.field = () => 42;
44 Expect.equals(42, a.field()); 43 Expect.equals(42, a.field());
45 Expect.equals(42, (a.field)()); 44 Expect.equals(42, (a.field)());
46 45
47 a.field = () => 87; 46 a.field = () => 87;
48 Expect.equals(87, a.field()); 47 Expect.equals(87, a.field());
49 Expect.equals(87, (a.field)()); 48 Expect.equals(87, (a.field)());
50 49
51 a.field = 99; 50 a.field = 99;
52 expectThrowsNoSuchMethod(() { a.field(); }); 51 expectThrowsNoSuchMethod(() {
53 expectThrowsNoSuchMethod(() { (a.field)(); }); 52 a.field();
53 });
54 expectThrowsNoSuchMethod(() {
55 (a.field)();
56 });
54 } 57 }
55 58
56 static void testGetter() { 59 static void testGetter() {
57 A a = new A(); 60 A a = new A();
58 a.field = () => 42; 61 a.field = () => 42;
59 Expect.equals(42, a.getter()); 62 Expect.equals(42, a.getter());
60 Expect.equals(42, (a.getter)()); 63 Expect.equals(42, (a.getter)());
61 64
62 a.field = () => 87; 65 a.field = () => 87;
63 Expect.equals(87, a.getter()); 66 Expect.equals(87, a.getter());
64 Expect.equals(87, (a.getter)()); 67 Expect.equals(87, (a.getter)());
65 68
66 a.field = 99; 69 a.field = 99;
67 expectThrowsNoSuchMethod(() { a.getter(); }); 70 expectThrowsNoSuchMethod(() {
68 expectThrowsNoSuchMethod(() { (a.getter)(); }); 71 a.getter();
72 });
73 expectThrowsNoSuchMethod(() {
74 (a.getter)();
75 });
69 } 76 }
70 77
71 static void testMethod() { 78 static void testMethod() {
72 A a = new A(); 79 A a = new A();
73 a.field = () => 42; 80 a.field = () => 42;
74 Expect.equals(true, a.method() is Function); 81 Expect.equals(true, a.method() is Function);
75 Expect.equals(42, a.method()()); 82 Expect.equals(42, a.method()());
76 83
77 a.field = () => 87; 84 a.field = () => 87;
78 Expect.equals(true, a.method() is Function); 85 Expect.equals(true, a.method() is Function);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 Expect.fail("Wrong exception. Expected: NoSuchMethodError" 122 Expect.fail("Wrong exception. Expected: NoSuchMethodError"
116 " got: ${exception}"); 123 " got: ${exception}");
117 } 124 }
118 } 125 }
119 126
120 static catchException(fn) { 127 static catchException(fn) {
121 bool caught = false; 128 bool caught = false;
122 var result = null; 129 var result = null;
123 try { 130 try {
124 fn(); 131 fn();
125 Expect.equals(true, false); // Shouldn't reach this. 132 Expect.equals(true, false); // Shouldn't reach this.
126 } catch (e) { 133 } catch (e) {
127 caught = true; 134 caught = true;
128 result = e; 135 result = e;
129 } 136 }
130 Expect.equals(true, caught); 137 Expect.equals(true, caught);
131 return result; 138 return result;
132 } 139 }
133
134 } 140 }
135 141
142 class A {
143 A() {}
144 var field;
145 get getter {
146 return field;
147 }
136 148
137 class A { 149 method() {
138 150 return field;
139 A() { } 151 }
140 var field;
141 get getter { return field; }
142 method() { return field; }
143
144 } 152 }
145 153
154 class B {
155 B() : _order = new StringBuffer("") {}
146 156
147 class B { 157 get g0 {
158 _mark('g');
159 return () {
160 return _mark('f');
161 };
162 }
148 163
149 B() : _order = new StringBuffer("") { } 164 get g1 {
165 _mark('g');
166 return (x) {
167 return _mark('f');
168 };
169 }
150 170
151 get g0 { _mark('g'); return () { return _mark('f'); }; } 171 get g2 {
152 get g1 { _mark('g'); return (x) { return _mark('f'); }; } 172 _mark('g');
153 get g2 { _mark('g'); return (x, y) { return _mark('f'); }; } 173 return (x, y) {
154 get g3 { _mark('g'); return (x, y, z) { return _mark('f'); }; } 174 return _mark('f');
175 };
176 }
155 177
156 get x { _mark('x'); return 0; } 178 get g3 {
157 get y { _mark('y'); return 1; } 179 _mark('g');
158 get z { _mark('z'); return 2; } 180 return (x, y, z) {
181 return _mark('f');
182 };
183 }
159 184
160 _mark(m) { _order.write(m); return _order.toString(); } 185 get x {
186 _mark('x');
187 return 0;
188 }
189
190 get y {
191 _mark('y');
192 return 1;
193 }
194
195 get z {
196 _mark('z');
197 return 2;
198 }
199
200 _mark(m) {
201 _order.write(m);
202 return _order.toString();
203 }
204
161 StringBuffer _order; 205 StringBuffer _order;
162
163 } 206 }
164 207
165 main() { 208 main() {
166 CallThroughGetterTest.testMain(); 209 CallThroughGetterTest.testMain();
167 } 210 }
OLDNEW
« no previous file with comments | « tests/language/call_nonexistent_static_test.dart ('k') | tests/language/call_type_literal_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698