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

Unified Diff: dart/tests/try/poi/qualified_names_test.dart

Issue 724843002: Rewrite, document, and test qualifiedNamesIn. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: dart/tests/try/poi/qualified_names_test.dart
diff --git a/dart/tests/try/poi/qualified_names_test.dart b/dart/tests/try/poi/qualified_names_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..3b15adf0ac7793ad5ac792898eb3267287614135
--- /dev/null
+++ b/dart/tests/try/poi/qualified_names_test.dart
@@ -0,0 +1,64 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Test of [qualifiedNamesIn] and [canNamesResolveTo].
+library trydart.qualified_names_test;
+
+import 'package:dart2js_incremental/library_updater.dart' show
+ canNamesResolveTo,
+ qualifiedNamesIn;
+
+import 'compiler_test_case.dart';
+
+typedef Checker(LibraryElement script);
+
+class NameTestCase extends CompilerTestCase {
+ final Checker check;
+
+ NameTestCase(String source, this.check)
+ : super(source);
+
+ Future run() => mainApp.then(check);
+}
+
+main() {
+ runTests(tests.map((l) => new NameTestCase(l.first, l.last)).toList());
+}
+
+final List tests = [
+ ["main() { x; }",
+ (LibraryElement script) {
+ var names = qualifiedNamesIn(script.findLocal("main"));
+ Expect.setEquals(["main", "x"].toSet(), names);
+ }],
+
+ ["main() { x; x.y; }",
+ (LibraryElement script) {
+ var names = qualifiedNamesIn(script.findLocal("main"));
+ Expect.setEquals(["main", "x", "x.y"].toSet(), names);
+ }],
+
+ ["main() { x; x.y; x.y.z; x.y.z.w;}",
+ (LibraryElement script) {
+ var names = qualifiedNamesIn(script.findLocal("main"));
+ // ".w" is skipped.
+ Expect.setEquals(["main", "x", "x.y", "x.y.z"].toSet(), names);
+ }],
+
+
+ ["x() {} y() {} z() {} w() {} main() { x; x.y; x.y.z; x.y.z.w;}",
+ (LibraryElement script) {
+ var main = script.findLocal("main");
+ var names = qualifiedNamesIn(main);
+ var x = script.findLocal("x");
+ var y = script.findLocal("y");
+ var z = script.findLocal("z");
+ var w = script.findLocal("w");
+ Expect.isTrue(canNamesResolveTo(names, main, script));
+ Expect.isTrue(canNamesResolveTo(names, x, script));
+ Expect.isFalse(canNamesResolveTo(names, y, script));
+ Expect.isFalse(canNamesResolveTo(names, z, script));
+ Expect.isFalse(canNamesResolveTo(names, w, script));
+ }],
+];

Powered by Google App Engine
This is Rietveld 408576698