| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 'mock_sdk.dart'; | 5 import 'mock_sdk.dart'; |
| 6 import 'package:analyzer/file_system/memory_file_system.dart'; | 6 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 7 import 'package:analyzer/src/generated/ast.dart'; | 7 import 'package:analyzer/src/generated/ast.dart'; |
| 8 import 'package:analyzer/src/generated/element.dart'; | 8 import 'package:analyzer/src/generated/element.dart'; |
| 9 import 'package:analyzer/src/generated/sdk.dart'; | 9 import 'package:analyzer/src/generated/sdk.dart'; |
| 10 import 'package:analyzer/src/generated/source.dart'; | 10 import 'package:analyzer/src/generated/source.dart'; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 } | 172 } |
| 173 main() { | 173 main() { |
| 174 new A().f1; | 174 new A().f1; |
| 175 } | 175 } |
| 176 '''); | 176 '''); |
| 177 helper.assertHasField('A.f1'); | 177 helper.assertHasField('A.f1'); |
| 178 helper.assertNoField('A.f2'); | 178 helper.assertNoField('A.f2'); |
| 179 helper.assertNoField('B.f1'); | 179 helper.assertNoField('B.f1'); |
| 180 helper.assertNoField('B.f2'); | 180 helper.assertNoField('B.f2'); |
| 181 }); | 181 }); |
| 182 |
| 183 test('Ordinary constructor with initializer list', () { |
| 184 var helper = new TreeShakerTestHelper(''' |
| 185 class A { |
| 186 A() : x = f(); |
| 187 var x; |
| 188 foo() {} |
| 189 } |
| 190 f() {} |
| 191 main() { |
| 192 new A().foo(); |
| 193 } |
| 194 '''); |
| 195 helper.assertHasMethod('A.foo'); |
| 196 helper.assertHasFunction('f'); |
| 197 }); |
| 198 |
| 199 test('Redirecting constructor', () { |
| 200 var helper = new TreeShakerTestHelper(''' |
| 201 class A { |
| 202 A.a1() : this.a2(); |
| 203 A.a2(); |
| 204 foo() {} |
| 205 } |
| 206 main() { |
| 207 new A.a1().foo(); |
| 208 } |
| 209 '''); |
| 210 helper.assertHasMethod('A.foo'); |
| 211 }); |
| 212 |
| 213 test('Factory constructor', () { |
| 214 var helper = new TreeShakerTestHelper(''' |
| 215 class A { |
| 216 factory A() { |
| 217 return new B(); |
| 218 } |
| 219 foo() {} |
| 220 } |
| 221 class B { |
| 222 B(); |
| 223 foo() {} |
| 224 } |
| 225 main() { |
| 226 new A().foo(); |
| 227 } |
| 228 '''); |
| 229 helper.assertHasMethod('B.foo'); |
| 230 helper.assertNoMethod('A.foo'); |
| 231 }); |
| 232 |
| 233 test('Redirecting factory constructor', () { |
| 234 var helper = new TreeShakerTestHelper(''' |
| 235 class A { |
| 236 factory A() = B; |
| 237 foo() {} |
| 238 } |
| 239 class B { |
| 240 B(); |
| 241 foo() {} |
| 242 } |
| 243 main() { |
| 244 new A().foo(); |
| 245 } |
| 246 '''); |
| 247 helper.assertHasMethod('B.foo'); |
| 248 helper.assertNoMethod('A.foo'); |
| 249 }); |
| 182 } | 250 } |
| 183 | 251 |
| 184 class TreeShakerTestHelper { | 252 class TreeShakerTestHelper { |
| 185 /** | 253 /** |
| 186 * The name of the root file. | 254 * The name of the root file. |
| 187 */ | 255 */ |
| 188 String rootFile = '/root.dart'; | 256 String rootFile = '/root.dart'; |
| 189 | 257 |
| 190 /** | 258 /** |
| 191 * ClosedWorld that resulted from tree shaking. | 259 * ClosedWorld that resulted from tree shaking. |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 /** | 434 /** |
| 367 * Asserts that [world] doesn't contain a method with the given qualified | 435 * Asserts that [world] doesn't contain a method with the given qualified |
| 368 * name. | 436 * name. |
| 369 * | 437 * |
| 370 * [qualifiedName] - the qualified name in form 'className.methodName'. | 438 * [qualifiedName] - the qualified name in form 'className.methodName'. |
| 371 */ | 439 */ |
| 372 void assertNoMethod(String qualifiedName) { | 440 void assertNoMethod(String qualifiedName) { |
| 373 expect(methods, isNot(contains(qualifiedName))); | 441 expect(methods, isNot(contains(qualifiedName))); |
| 374 } | 442 } |
| 375 } | 443 } |
| OLD | NEW |