| Index: pkg/analysis_server/test/src/computer/imported_elements_computer_test.dart
|
| diff --git a/pkg/analysis_server/test/src/computer/imported_elements_computer_test.dart b/pkg/analysis_server/test/src/computer/imported_elements_computer_test.dart
|
| index e9f7d0d25835832d9321d79e3383f4d3444012db..1d7c7d97fcf9cdc41fda751187b4da46f6e1b9da 100644
|
| --- a/pkg/analysis_server/test/src/computer/imported_elements_computer_test.dart
|
| +++ b/pkg/analysis_server/test/src/computer/imported_elements_computer_test.dart
|
| @@ -27,7 +27,125 @@ class ImportElementsComputerTest extends AbstractContextTest {
|
| sourcePath = provider.convertPath('/p/lib/source.dart');
|
| }
|
|
|
| - test_none() async {
|
| + test_dartAsync_noPrefix() async {
|
| + String selection = "Future<String> f = null;";
|
| + String content = """
|
| +import 'dart:async';
|
| +printer() {
|
| + $selection
|
| + print(await f);
|
| +}
|
| +""";
|
| + List<ImportedElements> elementsList = await _computeElements(
|
| + content, content.indexOf(selection), selection.length);
|
| + expect(elementsList, hasLength(2));
|
| + ImportedElements elements1 = elementsList[0];
|
| + ImportedElements elements2 = elementsList[1];
|
| + ImportedElements asyncElements;
|
| + ImportedElements coreElements;
|
| + if (elements1.path == '/lib/core/core.dart') {
|
| + coreElements = elements1;
|
| + asyncElements = elements2;
|
| + } else {
|
| + coreElements = elements2;
|
| + asyncElements = elements1;
|
| + }
|
| + expect(coreElements, isNotNull);
|
| + expect(coreElements.path, '/lib/core/core.dart');
|
| + expect(coreElements.prefix, '');
|
| + expect(coreElements.elements, unorderedEquals(['String']));
|
| +
|
| + expect(asyncElements, isNotNull);
|
| + expect(asyncElements.path, '/lib/async/async.dart');
|
| + expect(asyncElements.prefix, '');
|
| + expect(asyncElements.elements, unorderedEquals(['Future']));
|
| + }
|
| +
|
| + test_dartAsync_prefix() async {
|
| + String selection = "a.Future<String> f = null;";
|
| + String content = """
|
| +import 'dart:async' as a;
|
| +printer() {
|
| + $selection
|
| + print(await f);
|
| +}
|
| +""";
|
| + List<ImportedElements> elementsList = await _computeElements(
|
| + content, content.indexOf(selection), selection.length);
|
| + expect(elementsList, hasLength(2));
|
| + ImportedElements elements1 = elementsList[0];
|
| + ImportedElements elements2 = elementsList[1];
|
| + ImportedElements asyncElements;
|
| + ImportedElements coreElements;
|
| + if (elements1.path == '/lib/core/core.dart') {
|
| + coreElements = elements1;
|
| + asyncElements = elements2;
|
| + } else {
|
| + coreElements = elements2;
|
| + asyncElements = elements1;
|
| + }
|
| + expect(coreElements, isNotNull);
|
| + expect(coreElements.path, '/lib/core/core.dart');
|
| + expect(coreElements.prefix, '');
|
| + expect(coreElements.elements, unorderedEquals(['String']));
|
| +
|
| + expect(asyncElements, isNotNull);
|
| + expect(asyncElements.path, '/lib/async/async.dart');
|
| + expect(asyncElements.prefix, 'a');
|
| + expect(asyncElements.elements, unorderedEquals(['Future']));
|
| + }
|
| +
|
| + test_dartCore_noPrefix() async {
|
| + String selection = "String s = '';";
|
| + String content = """
|
| +blankLine() {
|
| + $selection
|
| + print(s);
|
| +}
|
| +""";
|
| + List<ImportedElements> elementsList = await _computeElements(
|
| + content, content.indexOf(selection), selection.length);
|
| + expect(elementsList, hasLength(1));
|
| + ImportedElements elements = elementsList[0];
|
| + expect(elements, isNotNull);
|
| + expect(elements.path, '/lib/core/core.dart');
|
| + expect(elements.prefix, '');
|
| + expect(elements.elements, unorderedEquals(['String']));
|
| + }
|
| +
|
| + test_dartCore_prefix() async {
|
| + String selection = "core.String s = '';";
|
| + String content = """
|
| +import 'dart:core' as core;
|
| +blankLine() {
|
| + $selection
|
| + print(s);
|
| +}
|
| +""";
|
| + List<ImportedElements> elementsList = await _computeElements(
|
| + content, content.indexOf(selection), selection.length);
|
| + expect(elementsList, hasLength(1));
|
| + ImportedElements elements = elementsList[0];
|
| + expect(elements, isNotNull);
|
| + expect(elements.path, '/lib/core/core.dart');
|
| + expect(elements.prefix, 'core');
|
| + expect(elements.elements, unorderedEquals(['String']));
|
| + }
|
| +
|
| + test_none_partialNames() async {
|
| + String selection = 'x + y';
|
| + String content = """
|
| +plusThree(int xx) {
|
| + int yy = 2;
|
| + print(x${selection}y);
|
| +}
|
| +""";
|
| + List<ImportedElements> elementsList = await _computeElements(
|
| + content, content.indexOf(selection), selection.length);
|
| + expect(elementsList, hasLength(0));
|
| + }
|
| +
|
| + test_none_wholeNames() async {
|
| String selection = 'x + y + 1';
|
| String content = """
|
| plusThree(int x) {
|
| @@ -35,9 +153,146 @@ plusThree(int x) {
|
| print($selection);
|
| }
|
| """;
|
| - List<ImportedElements> elements = await _computeElements(
|
| + List<ImportedElements> elementsList = await _computeElements(
|
| + content, content.indexOf(selection), selection.length);
|
| + expect(elementsList, hasLength(0));
|
| + }
|
| +
|
| + test_package_multipleInSame() async {
|
| + addPackageSource('foo', 'foo.dart', '''
|
| +class A {
|
| + static String a = '';
|
| +}
|
| +class B {
|
| + static String b = '';
|
| +}
|
| +''');
|
| + String selection = "A.a + B.b";
|
| + String content = """
|
| +import 'package:foo/foo.dart';
|
| +blankLine() {
|
| + print($selection);
|
| +}
|
| +""";
|
| + List<ImportedElements> elementsList = await _computeElements(
|
| + content, content.indexOf(selection), selection.length);
|
| + expect(elementsList, hasLength(1));
|
| + ImportedElements elements = elementsList[0];
|
| + expect(elements, isNotNull);
|
| + expect(elements.path, '/pubcache/foo/lib/foo.dart');
|
| + expect(elements.prefix, '');
|
| + expect(elements.elements, unorderedEquals(['A', 'B']));
|
| + }
|
| +
|
| + test_package_noPrefix() async {
|
| + addPackageSource('foo', 'foo.dart', '''
|
| +class Foo {
|
| + static String first = '';
|
| +}
|
| +''');
|
| + String selection = "Foo.first";
|
| + String content = """
|
| +import 'package:foo/foo.dart';
|
| +blankLine() {
|
| + print($selection);
|
| +}
|
| +""";
|
| + List<ImportedElements> elementsList = await _computeElements(
|
| + content, content.indexOf(selection), selection.length);
|
| + expect(elementsList, hasLength(1));
|
| + ImportedElements elements = elementsList[0];
|
| + expect(elements, isNotNull);
|
| + expect(elements.path, '/pubcache/foo/lib/foo.dart');
|
| + expect(elements.prefix, '');
|
| + expect(elements.elements, unorderedEquals(['Foo']));
|
| + }
|
| +
|
| + test_package_prefix_selected() async {
|
| + addPackageSource('foo', 'foo.dart', '''
|
| +class Foo {
|
| + static String first = '';
|
| +}
|
| +''');
|
| + String selection = "f.Foo.first";
|
| + String content = """
|
| +import 'package:foo/foo.dart' as f;
|
| +blankLine() {
|
| + print($selection);
|
| +}
|
| +""";
|
| + List<ImportedElements> elementsList = await _computeElements(
|
| + content, content.indexOf(selection), selection.length);
|
| + expect(elementsList, hasLength(1));
|
| + ImportedElements elements = elementsList[0];
|
| + expect(elements, isNotNull);
|
| + expect(elements.path, '/pubcache/foo/lib/foo.dart');
|
| + expect(elements.prefix, 'f');
|
| + expect(elements.elements, unorderedEquals(['Foo']));
|
| + }
|
| +
|
| + test_package_prefix_unselected() async {
|
| + addPackageSource('foo', 'foo.dart', '''
|
| +class Foo {
|
| + static String first = '';
|
| +}
|
| +''');
|
| + String selection = "Foo.first";
|
| + String content = """
|
| +import 'package:foo/foo.dart' as f;
|
| +blankLine() {
|
| + print(f.$selection);
|
| +}
|
| +""";
|
| + List<ImportedElements> elementsList = await _computeElements(
|
| content, content.indexOf(selection), selection.length);
|
| - expect(elements, hasLength(0));
|
| + expect(elementsList, hasLength(1));
|
| + ImportedElements elements = elementsList[0];
|
| + expect(elements, isNotNull);
|
| + expect(elements.path, '/pubcache/foo/lib/foo.dart');
|
| + expect(elements.prefix, '');
|
| + expect(elements.elements, unorderedEquals(['Foo']));
|
| + }
|
| +
|
| + test_package_prefixedAndNot() async {
|
| + addPackageSource('foo', 'foo.dart', '''
|
| +class Foo {
|
| + static String first = '';
|
| + static String second = '';
|
| +}
|
| +''');
|
| + String selection = "f.Foo.first + Foo.second";
|
| + String content = """
|
| +import 'package:foo/foo.dart';
|
| +import 'package:foo/foo.dart' as f;
|
| +blankLine() {
|
| + print($selection);
|
| +}
|
| +""";
|
| + List<ImportedElements> elementsList = await _computeElements(
|
| + content, content.indexOf(selection), selection.length);
|
| +
|
| + expect(elementsList, hasLength(2));
|
| + ImportedElements elements1 = elementsList[0];
|
| + ImportedElements elements2 = elementsList[1];
|
| + ImportedElements notPrefixedElements;
|
| + ImportedElements prefixedElements;
|
| + if (elements1.prefix == '') {
|
| + prefixedElements = elements2;
|
| + notPrefixedElements = elements1;
|
| + } else {
|
| + prefixedElements = elements1;
|
| + notPrefixedElements = elements2;
|
| + }
|
| +
|
| + expect(notPrefixedElements, isNotNull);
|
| + expect(notPrefixedElements.path, '/pubcache/foo/lib/foo.dart');
|
| + expect(notPrefixedElements.prefix, '');
|
| + expect(notPrefixedElements.elements, unorderedEquals(['Foo']));
|
| +
|
| + expect(prefixedElements, isNotNull);
|
| + expect(prefixedElements.path, '/pubcache/foo/lib/foo.dart');
|
| + expect(prefixedElements.prefix, 'f');
|
| + expect(prefixedElements.elements, unorderedEquals(['Foo']));
|
| }
|
|
|
| Future<List<ImportedElements>> _computeElements(
|
|
|