Chromium Code Reviews| Index: pkg/analysis_server/test/services/completion/dart/arglist_contributor_test.dart |
| diff --git a/pkg/analysis_server/test/services/completion/dart/arglist_contributor_test.dart b/pkg/analysis_server/test/services/completion/dart/arglist_contributor_test.dart |
| index b06ac9ef0288a3d427f1e4ff46d8072c5cf7feb4..982beb0feebe2dd2ad3b8651a1dd814ccfb8048f 100644 |
| --- a/pkg/analysis_server/test/services/completion/dart/arglist_contributor_test.dart |
| +++ b/pkg/analysis_server/test/services/completion/dart/arglist_contributor_test.dart |
| @@ -32,6 +32,20 @@ class ArgListContributorTest extends DartCompletionContributorTest { |
| } |
| } |
| + /** |
| + * Assert that there is a suggestion with the given parameter [name] that has |
| + * the given [completion], [selectionOffset] and [selectionLength]. |
| + */ |
| + void assertSuggestArgumentAndCompletion(String name, |
| + {String completion, int selectionOffset, int selectionLength: 0}) { |
| + CompletionSuggestion suggestion = |
| + suggestions.firstWhere((s) => s.parameterName == name); |
| + expect(suggestion, isNotNull); |
| + expect(suggestion.completion, completion); |
| + expect(suggestion.selectionOffset, selectionOffset); |
| + expect(suggestion.selectionLength, selectionLength); |
| + } |
| + |
| void assertSuggestArgumentList( |
| List<String> paramNames, List<String> paramTypes) { |
| // DEPRECATED... argument lists are no longer suggested. |
| @@ -84,10 +98,15 @@ class ArgListContributorTest extends DartCompletionContributorTest { |
| * the only suggestions. |
| */ |
| void assertSuggestArgumentsAndTypes( |
| - {Map<String, String> namedArgumentsWithTypes, bool includeColon: true}) { |
| + {Map<String, String> namedArgumentsWithTypes, |
| + bool includeColon: true, |
| + bool includeComma: false}) { |
| List<CompletionSuggestion> expected = new List<CompletionSuggestion>(); |
| namedArgumentsWithTypes.forEach((String name, String type) { |
| String completion = includeColon ? '$name: ' : name; |
| + if (includeComma) { |
| + completion = '$completion,'; |
| + } |
| expected.add(assertSuggest(completion, |
| csKind: CompletionSuggestionKind.NAMED_ARGUMENT, |
| relevance: DART_RELEVANCE_NAMED_PARAMETER, |
| @@ -131,6 +150,32 @@ class A { const A({int one, String two: 'defaultValue'}); } |
| assertSuggestions([', one: ']); |
| } |
| + test_ArgumentList_local_constructor_named_param_prepend() async { |
| + // |
| + addTestSource(''' |
| +class A { A({int one, String two: 'defaultValue'}) { } } |
| +main() { new A(^ two: 'foo');}'''); |
| + await computeSuggestions(); |
| + |
| + assertSuggestArgumentsAndTypes( |
| + namedArgumentsWithTypes: {'one': 'int'}, includeComma: true); |
| + assertSuggestArgumentAndCompletion('one', |
| + completion: 'one: ,', selectionOffset: 5); |
| + } |
| + |
| + test_ArgumentList_local_constructor_named_param_prefixed_prepend() async { |
| + // |
| + addTestSource(''' |
| +class A { A({int one, String two: 'defaultValue'}) { } } |
| +main() { new A(o^ two: 'foo');}'''); |
|
danrubel
2017/04/27 14:04:13
I recommend two more tests... each with a trailing
pquitslund
2017/04/27 17:09:54
Thank you, yes! Done.
|
| + await computeSuggestions(); |
| + |
| + assertSuggestArgumentsAndTypes( |
| + namedArgumentsWithTypes: {'one': 'int'}, includeComma: true); |
| + assertSuggestArgumentAndCompletion('one', |
| + completion: 'one: ,', selectionOffset: 5); |
| + } |
| + |
| test_Annotation_imported_constructor_named_param() async { |
| addSource( |
| '/libA.dart', |
| @@ -543,8 +588,11 @@ main() { |
| class A { A({int one, String two: 'defaultValue'}) { } } |
| main() { new A(^);}'''); |
| await computeSuggestions(); |
| + |
| assertSuggestArgumentsAndTypes( |
| namedArgumentsWithTypes: {'one': 'int', 'two': 'String'}); |
| + assertSuggestArgumentAndCompletion('one', |
| + completion: 'one: ', selectionOffset: 5); |
|
danrubel
2017/04/27 14:04:13
And several more tests similar to this one.
new A
pquitslund
2017/04/27 17:09:54
Done.
|
| } |
| test_ArgumentList_local_constructor_named_param2() async { |