Index: pkg/analysis_server/test/services/completion/local_computer_test.dart |
diff --git a/pkg/analysis_server/test/services/completion/local_computer_test.dart b/pkg/analysis_server/test/services/completion/local_computer_test.dart |
index 6e20e79f6a551469336694dd8291502ab64cd826..2f1a55966774efc2a89adb32702bcd013c0d44b1 100644 |
--- a/pkg/analysis_server/test/services/completion/local_computer_test.dart |
+++ b/pkg/analysis_server/test/services/completion/local_computer_test.dart |
@@ -5,9 +5,9 @@ |
library test.services.completion.dart.local; |
import 'package:analysis_server/src/services/completion/local_computer.dart'; |
-import '../../reflective_tests.dart'; |
import 'package:unittest/unittest.dart'; |
+import '../../reflective_tests.dart'; |
import 'completion_test_util.dart'; |
main() { |
@@ -24,29 +24,56 @@ class LocalComputerTest extends AbstractCompletionTest { |
computer = new LocalComputer(); |
} |
- test_block() { |
+ test_BinaryExpression_LHS() { |
+ // SimpleIdentifier BinaryExpression VariableDeclaration |
+ // VariableDeclarationList VariableDeclarationStatement |
+ addTestSource('main() {int a = 1, b = ^ + 2;}'); |
+ expect(computeFast(), isTrue); |
+ assertSuggestLocalVariable('a', 'int'); |
+ assertNotSuggested('b'); |
+ } |
+ |
+ test_BinaryExpression_RHS() { |
+ // SimpleIdentifier BinaryExpression VariableDeclaration |
+ // VariableDeclarationList VariableDeclarationStatement |
+ addTestSource('main() {int a = 1, b = 2 + ^;}'); |
+ expect(computeFast(), isTrue); |
+ assertSuggestLocalVariable('a', 'int'); |
+ assertNotSuggested('b'); |
+ } |
+ |
+ test_Block() { |
+ // Block BlockFunctionBody |
addTestSource('class A {a() {var f; {var x;} ^ var g;}}'); |
expect(computeFast(), isTrue); |
+ assertSuggestClass('A'); |
assertSuggestLocalVariable('f', null); |
assertNotSuggested('g'); |
assertNotSuggested('x'); |
} |
- test_catch() { |
+ test_CatchClause_typed() { |
+ // Block CatchClause TryStatement |
addTestSource('class A {a() {try{} on E catch (e) {^}}}'); |
expect(computeFast(), isTrue); |
assertSuggestParameter('e', 'E'); |
} |
- test_catch2() { |
+ test_CatchClause_untyped() { |
+ // Block CatchClause TryStatement |
addTestSource('class A {a() {try{} catch (e, s) {^}}}'); |
expect(computeFast(), isTrue); |
assertSuggestParameter('e', null); |
assertSuggestParameter('s', 'StackTrace'); |
} |
- test_compilationUnit_declarations() { |
- addTestSource('@deprecated class A {^} class _B {} A T;'); |
+ test_ClassDeclaration_body() { |
+ // ClassDeclaration CompilationUnit |
+ addTestSource( // |
+ 'import "boo.dart" as x;' // |
+ ' @deprecated class A {^}' // |
+ ' class _B {}' // |
+ ' A T;'); |
expect(computeFast(), isTrue); |
var a = assertSuggestClass('A'); |
expect(a.element.isDeprecated, isTrue); |
@@ -55,45 +82,49 @@ class LocalComputerTest extends AbstractCompletionTest { |
expect(b.element.isDeprecated, isFalse); |
expect(b.element.isPrivate, isTrue); |
assertSuggestTopLevelVar('T', 'A'); |
- } |
- |
- test_compilationUnit_directives() { |
- addTestSource('import "boo.dart" as x; class A {^}'); |
- expect(computeFast(), isTrue); |
assertSuggestLibraryPrefix('x'); |
} |
- test_field_name() { |
- addTestSource('class A {B ^}}'); |
+ test_ExpressionStatement_name() { |
+ // ExpressionStatement Block |
+ addTestSource('class A {a() {var f; A ^}}'); |
expect(computeFast(), isTrue); |
assertNotSuggested('A'); |
+ assertNotSuggested('a'); |
+ assertNotSuggested('f'); |
} |
- test_field_name2() { |
- addTestSource('class A {var ^}}'); |
+ test_FieldDeclaration_name() { |
+ // SimpleIdentifier VariableDeclaration VariableDeclarationList |
+ // FieldDeclaration |
+ addTestSource('class A {B ^}}'); |
expect(computeFast(), isTrue); |
assertNotSuggested('A'); |
} |
- test_for() { |
- addTestSource('main(args) {for (int i; i < 10; ++i) {^}}'); |
+ test_ForEachStatement_body_typed() { |
+ // Block ForEachStatement |
+ addTestSource('main(args) {for (int foo in bar) {^}}'); |
expect(computeFast(), isTrue); |
- assertSuggestLocalVariable('i', 'int'); |
+ assertSuggestLocalVariable('foo', 'int'); |
} |
- test_forEach() { |
+ test_ForEachStatement_body_untyped() { |
+ // Block ForEachStatement |
addTestSource('main(args) {for (foo in bar) {^}}'); |
expect(computeFast(), isTrue); |
assertSuggestLocalVariable('foo', null); |
} |
- test_forEach2() { |
- addTestSource('main(args) {for (int foo in bar) {^}}'); |
+ test_ForStatement_body() { |
+ // Block ForStatement |
+ addTestSource('main(args) {for (int i; i < 10; ++i) {^}}'); |
expect(computeFast(), isTrue); |
- assertSuggestLocalVariable('foo', 'int'); |
+ assertSuggestLocalVariable('i', 'int'); |
} |
- test_function() { |
+ test_FunctionExpression_body_function() { |
+ // Block BlockFunctionBody FunctionExpression |
addTestSource('String foo(List args) {x.then((R b) {^});}'); |
expect(computeFast(), isTrue); |
var f = assertSuggestFunction('foo', 'String', false); |
@@ -102,7 +133,22 @@ class LocalComputerTest extends AbstractCompletionTest { |
assertSuggestParameter('b', 'R'); |
} |
- test_getters() { |
+ test_InstanceCreationExpression() { |
+ // SimpleIdentifier TypeName ConstructorName InstanceCreationExpression |
+ addTestSource('class A {a() {var f; {var x;} new ^}} class B { }'); |
+ expect(computeFast(), isTrue); |
+ assertSuggestClass('A'); |
+ assertSuggestClass('B'); |
+ // TODO (danrubel) should only suggest types |
+ //assertNotSuggested('a'); |
+ assertSuggestMethod('a', 'A', null); |
+ //assertNotSuggested('f'); |
+ assertSuggestLocalVariable('f', null); |
+ assertNotSuggested('x'); |
+ } |
+ |
+ test_MethodDeclaration_body_getters() { |
+ // Block BlockFunctionBody MethodDeclaration |
addTestSource('class A {@deprecated X get f => 0; Z a() {^} get _g => 1;}'); |
expect(computeFast(), isTrue); |
var a = assertSuggestMethod('a', 'A', 'Z'); |
@@ -116,23 +162,8 @@ class LocalComputerTest extends AbstractCompletionTest { |
expect(g.element.isPrivate, isTrue); |
} |
- test_local_name() { |
- addTestSource('class A {a() {var f; A ^}}'); |
- expect(computeFast(), isTrue); |
- assertNotSuggested('A'); |
- assertNotSuggested('a'); |
- assertNotSuggested('f'); |
- } |
- |
- test_local_name2() { |
- addTestSource('class _A {a() {var f; var ^}}'); |
- expect(computeFast(), isTrue); |
- assertNotSuggested('A'); |
- assertNotSuggested('a'); |
- assertNotSuggested('f'); |
- } |
- |
- test_members() { |
+ test_MethodDeclaration_members() { |
+ // Block BlockFunctionBody MethodDeclaration |
addTestSource('class A {@deprecated X f; Z _a() {^} var _g;}'); |
expect(computeFast(), isTrue); |
var a = assertSuggestMethod('_a', 'A', 'Z'); |
@@ -146,7 +177,8 @@ class LocalComputerTest extends AbstractCompletionTest { |
expect(g.element.isPrivate, isTrue); |
} |
- test_methodParam_named() { |
+ test_MethodDeclaration_parameters_named() { |
+ // Block BlockFunctionBody MethodDeclaration |
addTestSource('class A {@deprecated Z a(X x, {y: boo}) {^}}'); |
expect(computeFast(), isTrue); |
var a = assertSuggestMethod('a', 'A', 'Z'); |
@@ -156,7 +188,8 @@ class LocalComputerTest extends AbstractCompletionTest { |
assertSuggestParameter('y', null); |
} |
- test_methodParam_positional() { |
+ test_MethodDeclaration_parameters_positional() { |
+ // Block BlockFunctionBody MethodDeclaration |
addTestSource('class A {Z a(X x, [int y=1]) {^}}'); |
expect(computeFast(), isTrue); |
assertSuggestMethod('a', 'A', 'Z'); |
@@ -164,22 +197,40 @@ class LocalComputerTest extends AbstractCompletionTest { |
assertSuggestParameter('y', 'int'); |
} |
- test_topLevelVar_name() { |
+ test_TopLevelVariableDeclaration_typed_name() { |
+ // SimpleIdentifier VariableDeclaration VariableDeclarationList |
+ // TopLevelVariableDeclaration |
addTestSource('class A {} B ^'); |
expect(computeFast(), isTrue); |
assertNotSuggested('A'); |
} |
- test_topLevelVar_name2() { |
+ test_TopLevelVariableDeclaration_untyped_name() { |
+ // SimpleIdentifier VariableDeclaration VariableDeclarationList |
+ // TopLevelVariableDeclaration |
addTestSource('class A {} var ^'); |
expect(computeFast(), isTrue); |
assertNotSuggested('A'); |
} |
- test_variableDeclaration() { |
- addTestSource('main() {int a = 1, b = 2 + ^;}'); |
+ test_VariableDeclarationStatement_name() { |
+ // SimpleIdentifier VariableDeclaration VariableDeclarationList |
+ // VariableDeclarationStatement |
+ addTestSource('class _A {a() {var f; var ^}}'); |
expect(computeFast(), isTrue); |
- assertSuggestLocalVariable('a', 'int'); |
- assertNotSuggested('b'); |
+ assertNotSuggested('A'); |
+ assertNotSuggested('a'); |
+ assertNotSuggested('f'); |
+ } |
+ |
+ test_VariableDeclaration_RHS() { |
+ |
+ // VariableDeclaration VariableDeclarationList VariableDeclarationStatement |
+ addTestSource('class A {a() {var f; {var x;} var e = ^ var g;}}'); |
+ expect(computeFast(), isTrue); |
+ assertSuggestClass('A'); |
+ assertSuggestLocalVariable('f', null); |
+ assertNotSuggested('g'); |
+ assertNotSuggested('x'); |
} |
} |