OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library test.services.completion.dart.local; | 5 library test.services.completion.dart.local; |
6 | 6 |
7 import 'package:analysis_server/src/protocol_server.dart'; | 7 import 'package:analysis_server/src/protocol_server.dart'; |
8 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; | 8 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; |
9 import 'package:analysis_server/src/services/completion/local_computer.dart'; | 9 import 'package:analysis_server/src/services/completion/local_computer.dart'; |
10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
11 | 11 |
12 import '../../reflective_tests.dart'; | 12 import '../../reflective_tests.dart'; |
13 import 'completion_test_util.dart'; | 13 import 'completion_test_util.dart'; |
14 | 14 |
15 main() { | 15 main() { |
16 groupSep = ' | '; | 16 groupSep = ' | '; |
17 runReflectiveTests(LocalComputerTest); | 17 runReflectiveTests(LocalComputerTest); |
18 } | 18 } |
19 | 19 |
20 @reflectiveTest | 20 @reflectiveTest |
21 class LocalComputerTest extends AbstractSelectorSuggestionTest { | 21 class LocalComputerTest extends AbstractSelectorSuggestionTest { |
22 | |
23 @override | 22 @override |
24 CompletionSuggestion assertSuggestLocalClass(String name, {int relevance: | 23 CompletionSuggestion assertSuggestLocalClass(String name, |
25 DART_RELEVANCE_DEFAULT, bool isDeprecated: false}) { | 24 {int relevance: DART_RELEVANCE_DEFAULT, bool isDeprecated: false}) { |
26 return assertSuggestClass( | 25 return assertSuggestClass(name, |
27 name, | 26 relevance: relevance, isDeprecated: isDeprecated); |
28 relevance: relevance, | |
29 isDeprecated: isDeprecated); | |
30 } | 27 } |
31 | 28 |
32 @override | 29 @override |
33 CompletionSuggestion assertSuggestLocalClassTypeAlias(String name, | 30 CompletionSuggestion assertSuggestLocalClassTypeAlias(String name, |
34 {int relevance: DART_RELEVANCE_DEFAULT}) { | 31 {int relevance: DART_RELEVANCE_DEFAULT}) { |
35 return assertSuggestClassTypeAlias(name, relevance); | 32 return assertSuggestClassTypeAlias(name, relevance); |
36 } | 33 } |
37 | 34 |
38 @override | 35 @override |
39 CompletionSuggestion assertSuggestLocalField(String name, String type, | 36 CompletionSuggestion assertSuggestLocalField(String name, String type, |
40 {int relevance: DART_RELEVANCE_LOCAL_FIELD, bool deprecated: false}) { | 37 {int relevance: DART_RELEVANCE_LOCAL_FIELD, bool deprecated: false}) { |
41 return assertSuggestField( | 38 return assertSuggestField(name, type, |
42 name, | 39 relevance: relevance, isDeprecated: deprecated); |
43 type, | |
44 relevance: relevance, | |
45 isDeprecated: deprecated); | |
46 } | 40 } |
47 | 41 |
48 @override | 42 @override |
49 CompletionSuggestion assertSuggestLocalFunction(String name, | 43 CompletionSuggestion assertSuggestLocalFunction( |
50 String returnType, {bool deprecated: false, int relevance: | 44 String name, String returnType, |
51 DART_RELEVANCE_LOCAL_FUNCTION}) { | 45 {bool deprecated: false, int relevance: DART_RELEVANCE_LOCAL_FUNCTION}) { |
52 return assertSuggestFunction(name, returnType, deprecated, relevance); | 46 return assertSuggestFunction(name, returnType, deprecated, relevance); |
53 } | 47 } |
54 | 48 |
55 @override | 49 @override |
56 CompletionSuggestion assertSuggestLocalFunctionTypeAlias(String name, | 50 CompletionSuggestion assertSuggestLocalFunctionTypeAlias( |
57 String returnType, {bool deprecated: false, int relevance: | 51 String name, String returnType, |
58 DART_RELEVANCE_DEFAULT}) { | 52 {bool deprecated: false, int relevance: DART_RELEVANCE_DEFAULT}) { |
59 return assertSuggestFunctionTypeAlias( | 53 return assertSuggestFunctionTypeAlias( |
60 name, | 54 name, returnType, deprecated, relevance); |
61 returnType, | |
62 deprecated, | |
63 relevance); | |
64 } | 55 } |
65 | 56 |
66 @override | 57 @override |
67 CompletionSuggestion assertSuggestLocalGetter(String name, String returnType, | 58 CompletionSuggestion assertSuggestLocalGetter(String name, String returnType, |
68 {int relevance: DART_RELEVANCE_LOCAL_ACCESSOR, bool deprecated: false}) { | 59 {int relevance: DART_RELEVANCE_LOCAL_ACCESSOR, bool deprecated: false}) { |
69 return assertSuggestGetter( | 60 return assertSuggestGetter(name, returnType, |
70 name, | 61 relevance: relevance, isDeprecated: deprecated); |
71 returnType, | |
72 relevance: relevance, | |
73 isDeprecated: deprecated); | |
74 } | 62 } |
75 | 63 |
76 @override | 64 @override |
77 CompletionSuggestion assertSuggestLocalMethod(String name, | 65 CompletionSuggestion assertSuggestLocalMethod( |
78 String declaringType, String returnType, {int relevance: | 66 String name, String declaringType, String returnType, |
79 DART_RELEVANCE_LOCAL_METHOD, bool deprecated: false}) { | 67 {int relevance: DART_RELEVANCE_LOCAL_METHOD, bool deprecated: false}) { |
80 return assertSuggestMethod( | 68 return assertSuggestMethod(name, declaringType, returnType, |
81 name, | 69 relevance: relevance, isDeprecated: deprecated); |
82 declaringType, | |
83 returnType, | |
84 relevance: relevance, | |
85 isDeprecated: deprecated); | |
86 } | 70 } |
87 | 71 |
88 @override | 72 @override |
89 CompletionSuggestion assertSuggestLocalSetter(String name, {int relevance: | 73 CompletionSuggestion assertSuggestLocalSetter(String name, |
90 DART_RELEVANCE_LOCAL_ACCESSOR}) { | 74 {int relevance: DART_RELEVANCE_LOCAL_ACCESSOR}) { |
91 return assertSuggestSetter(name, relevance); | 75 return assertSuggestSetter(name, relevance); |
92 } | 76 } |
93 | 77 |
94 @override | 78 @override |
95 CompletionSuggestion assertSuggestLocalTopLevelVar(String name, | 79 CompletionSuggestion assertSuggestLocalTopLevelVar( |
96 String returnType, {int relevance: DART_RELEVANCE_LOCAL_TOP_LEVEL_VARIABLE
}) { | 80 String name, String returnType, |
| 81 {int relevance: DART_RELEVANCE_LOCAL_TOP_LEVEL_VARIABLE}) { |
97 return assertSuggestTopLevelVar(name, returnType, relevance); | 82 return assertSuggestTopLevelVar(name, returnType, relevance); |
98 } | 83 } |
99 | 84 |
100 @override | 85 @override |
101 CompletionSuggestion assertSuggestLocalVariable(String name, | 86 CompletionSuggestion assertSuggestLocalVariable( |
102 String returnType, {int relevance: DART_RELEVANCE_LOCAL_VARIABLE}) { | 87 String name, String returnType, |
| 88 {int relevance: DART_RELEVANCE_LOCAL_VARIABLE}) { |
103 // Local variables should only be suggested by LocalComputer | 89 // Local variables should only be suggested by LocalComputer |
104 CompletionSuggestion cs = assertSuggest( | 90 CompletionSuggestion cs = assertSuggest(name, |
105 name, | 91 csKind: CompletionSuggestionKind.INVOCATION, relevance: relevance); |
106 csKind: CompletionSuggestionKind.INVOCATION, | |
107 relevance: relevance); | |
108 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); | 92 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); |
109 Element element = cs.element; | 93 Element element = cs.element; |
110 expect(element, isNotNull); | 94 expect(element, isNotNull); |
111 expect(element.kind, equals(ElementKind.LOCAL_VARIABLE)); | 95 expect(element.kind, equals(ElementKind.LOCAL_VARIABLE)); |
112 expect(element.name, equals(name)); | 96 expect(element.name, equals(name)); |
113 expect(element.parameters, isNull); | 97 expect(element.parameters, isNull); |
114 expect(element.returnType, returnType != null ? returnType : 'dynamic'); | 98 expect(element.returnType, returnType != null ? returnType : 'dynamic'); |
115 assertHasNoParameterInfo(cs); | 99 assertHasNoParameterInfo(cs); |
116 return cs; | 100 return cs; |
117 } | 101 } |
118 | 102 |
119 CompletionSuggestion assertSuggestParameter(String name, String returnType, | 103 CompletionSuggestion assertSuggestParameter(String name, String returnType, |
120 {int relevance: DART_RELEVANCE_PARAMETER}) { | 104 {int relevance: DART_RELEVANCE_PARAMETER}) { |
121 CompletionSuggestion cs = assertSuggest( | 105 CompletionSuggestion cs = assertSuggest(name, |
122 name, | 106 csKind: CompletionSuggestionKind.INVOCATION, relevance: relevance); |
123 csKind: CompletionSuggestionKind.INVOCATION, | |
124 relevance: relevance); | |
125 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); | 107 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); |
126 Element element = cs.element; | 108 Element element = cs.element; |
127 expect(element, isNotNull); | 109 expect(element, isNotNull); |
128 expect(element.kind, equals(ElementKind.PARAMETER)); | 110 expect(element.kind, equals(ElementKind.PARAMETER)); |
129 expect(element.name, equals(name)); | 111 expect(element.name, equals(name)); |
130 expect(element.parameters, isNull); | 112 expect(element.parameters, isNull); |
131 expect( | 113 expect(element.returnType, |
132 element.returnType, | |
133 equals(returnType != null ? returnType : 'dynamic')); | 114 equals(returnType != null ? returnType : 'dynamic')); |
134 return cs; | 115 return cs; |
135 } | 116 } |
136 | 117 |
137 fail_mixin_ordering() { | 118 fail_mixin_ordering() { |
138 // TODO(paulberry): Duplicates aren't being removed, so we see both M1.m() | 119 // TODO(paulberry): Duplicates aren't being removed, so we see both M1.m() |
139 // and M2.m(). | 120 // and M2.m(). |
140 addTestSource(''' | 121 addTestSource(''' |
141 class B {} | 122 class B {} |
142 class M1 { | 123 class M1 { |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 assertSuggestLocalMethod('m', 'A', 'void'); | 640 assertSuggestLocalMethod('m', 'A', 'void'); |
660 expect(suggestion.parameterNames, hasLength(2)); | 641 expect(suggestion.parameterNames, hasLength(2)); |
661 expect(suggestion.parameterNames[0], 'x'); | 642 expect(suggestion.parameterNames[0], 'x'); |
662 expect(suggestion.parameterTypes[0], 'dynamic'); | 643 expect(suggestion.parameterTypes[0], 'dynamic'); |
663 expect(suggestion.parameterNames[1], 'y'); | 644 expect(suggestion.parameterNames[1], 'y'); |
664 expect(suggestion.parameterTypes[1], 'int'); | 645 expect(suggestion.parameterTypes[1], 'int'); |
665 expect(suggestion.requiredParameterCount, 2); | 646 expect(suggestion.requiredParameterCount, 2); |
666 expect(suggestion.hasNamedParameters, false); | 647 expect(suggestion.hasNamedParameters, false); |
667 } | 648 } |
668 } | 649 } |
OLD | NEW |