| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 // Test of [qualifiedNamesIn] and [canNamesResolveTo]. |
| 6 library trydart.qualified_names_test; |
| 7 |
| 8 import 'package:dart2js_incremental/library_updater.dart' show |
| 9 canNamesResolveTo, |
| 10 qualifiedNamesIn; |
| 11 |
| 12 import 'compiler_test_case.dart'; |
| 13 |
| 14 typedef Checker(LibraryElement script); |
| 15 |
| 16 class NameTestCase extends CompilerTestCase { |
| 17 final Checker check; |
| 18 |
| 19 NameTestCase(String source, this.check) |
| 20 : super(source); |
| 21 |
| 22 Future run() => mainApp.then(check); |
| 23 } |
| 24 |
| 25 main() { |
| 26 runTests(tests.map((l) => new NameTestCase(l.first, l.last)).toList()); |
| 27 } |
| 28 |
| 29 final List tests = [ |
| 30 ["main() { x; }", |
| 31 (LibraryElement script) { |
| 32 var names = qualifiedNamesIn(script.findLocal("main")); |
| 33 Expect.setEquals(["main", "x"].toSet(), names); |
| 34 }], |
| 35 |
| 36 ["main() { x; x.y; }", |
| 37 (LibraryElement script) { |
| 38 var names = qualifiedNamesIn(script.findLocal("main")); |
| 39 Expect.setEquals(["main", "x", "x.y"].toSet(), names); |
| 40 }], |
| 41 |
| 42 ["main() { x; x.y; x.y.z; x.y.z.w;}", |
| 43 (LibraryElement script) { |
| 44 var names = qualifiedNamesIn(script.findLocal("main")); |
| 45 // ".w" is skipped. |
| 46 Expect.setEquals(["main", "x", "x.y", "x.y.z"].toSet(), names); |
| 47 }], |
| 48 |
| 49 |
| 50 ["x() {} y() {} z() {} w() {} main() { x; x.y; x.y.z; x.y.z.w;}", |
| 51 (LibraryElement script) { |
| 52 var main = script.findLocal("main"); |
| 53 var names = qualifiedNamesIn(main); |
| 54 var x = script.findLocal("x"); |
| 55 var y = script.findLocal("y"); |
| 56 var z = script.findLocal("z"); |
| 57 var w = script.findLocal("w"); |
| 58 Expect.isTrue(canNamesResolveTo(names, main, script)); |
| 59 Expect.isTrue(canNamesResolveTo(names, x, script)); |
| 60 Expect.isFalse(canNamesResolveTo(names, y, script)); |
| 61 Expect.isFalse(canNamesResolveTo(names, z, script)); |
| 62 Expect.isFalse(canNamesResolveTo(names, w, script)); |
| 63 }], |
| 64 ]; |
| OLD | NEW |