Chromium Code Reviews| 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..90790709546f1a3884edc160ecfb55bf26a5541c 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,138 @@ class ImportElementsComputerTest extends AbstractContextTest { |
| sourcePath = provider.convertPath('/p/lib/source.dart'); |
| } |
| - test_none() async { |
| + test_dartAsync_noPrefix() async { |
|
scheglov
2017/08/01 15:16:34
I would add a test for using a class defined in th
Brian Wilkerson
2017/08/01 15:31:43
Done
|
| + 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_comment() async { |
| + String selection = 'comment'; |
| + String content = """ |
| +// Method $selection. |
| +blankLine() { |
| + print(''); |
| +} |
| +"""; |
| + List<ImportedElements> elementsList = await _computeElements( |
| + content, content.indexOf(selection), selection.length); |
| + expect(elementsList, hasLength(0)); |
| + } |
| + |
| + 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 +166,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(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(['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(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( |