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 import 'package:analysis_server/src/provisional/completion/dart/completion_dart.
dart'; | 5 import 'package:analysis_server/src/provisional/completion/dart/completion_dart.
dart'; |
6 import 'package:analysis_server/src/services/completion/dart/arglist_contributor
.dart'; | 6 import 'package:analysis_server/src/services/completion/dart/arglist_contributor
.dart'; |
7 import 'package:analyzer_plugin/protocol/protocol_common.dart'; | 7 import 'package:analyzer_plugin/protocol/protocol_common.dart'; |
8 import 'package:test/test.dart'; | 8 import 'package:test/test.dart'; |
9 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 9 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
10 | 10 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 msg.writeln(' found: $actualTypes'); | 88 msg.writeln(' found: $actualTypes'); |
89 fail(msg.toString()); | 89 fail(msg.toString()); |
90 } | 90 } |
91 | 91 |
92 /** | 92 /** |
93 * Assert that the specified named argument suggestions with their types are | 93 * Assert that the specified named argument suggestions with their types are |
94 * the only suggestions. | 94 * the only suggestions. |
95 */ | 95 */ |
96 void assertSuggestArgumentsAndTypes( | 96 void assertSuggestArgumentsAndTypes( |
97 {Map<String, String> namedArgumentsWithTypes, | 97 {Map<String, String> namedArgumentsWithTypes, |
| 98 List<int> requiredParamIndices: const <int>[], |
98 bool includeColon: true, | 99 bool includeColon: true, |
99 bool includeComma: false}) { | 100 bool includeComma: false}) { |
100 List<CompletionSuggestion> expected = new List<CompletionSuggestion>(); | 101 List<CompletionSuggestion> expected = new List<CompletionSuggestion>(); |
| 102 int paramIndex = 0; |
101 namedArgumentsWithTypes.forEach((String name, String type) { | 103 namedArgumentsWithTypes.forEach((String name, String type) { |
102 String completion = includeColon ? '$name: ' : name; | 104 String completion = includeColon ? '$name: ' : name; |
103 // Selection should be before any trailing commas. | 105 // Selection should be before any trailing commas. |
104 int selectionOffset = completion.length; | 106 int selectionOffset = completion.length; |
105 if (includeComma) { | 107 if (includeComma) { |
106 completion = '$completion,'; | 108 completion = '$completion,'; |
107 } | 109 } |
| 110 int relevance = requiredParamIndices.contains(paramIndex++) |
| 111 ? DART_RELEVANCE_NAMED_PARAMETER_REQUIRED |
| 112 : DART_RELEVANCE_NAMED_PARAMETER; |
108 expected.add(assertSuggest(completion, | 113 expected.add(assertSuggest(completion, |
109 csKind: CompletionSuggestionKind.NAMED_ARGUMENT, | 114 csKind: CompletionSuggestionKind.NAMED_ARGUMENT, |
110 relevance: DART_RELEVANCE_NAMED_PARAMETER, | 115 relevance: relevance, |
111 paramName: name, | 116 paramName: name, |
112 paramType: type, | 117 paramType: type, |
113 selectionOffset: selectionOffset)); | 118 selectionOffset: selectionOffset)); |
114 }); | 119 }); |
115 assertNoOtherSuggestions(expected); | 120 assertNoOtherSuggestions(expected); |
116 } | 121 } |
117 | 122 |
118 /** | 123 /** |
119 * Assert that the specified suggestions are the only suggestions. | 124 * Assert that the specified suggestions are the only suggestions. |
120 */ | 125 */ |
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 class A { A({int one, String two: 'defaultValue'}) { } } | 861 class A { A({int one, String two: 'defaultValue'}) { } } |
857 main() { new A(^, two: 'foo');}'''); | 862 main() { new A(^, two: 'foo');}'''); |
858 await computeSuggestions(); | 863 await computeSuggestions(); |
859 | 864 |
860 assertSuggestArgumentsAndTypes( | 865 assertSuggestArgumentsAndTypes( |
861 namedArgumentsWithTypes: {'one': 'int'}, includeComma: false); | 866 namedArgumentsWithTypes: {'one': 'int'}, includeComma: false); |
862 assertSuggestArgumentAndCompletion('one', | 867 assertSuggestArgumentAndCompletion('one', |
863 completion: 'one: ', selectionOffset: 5); | 868 completion: 'one: ', selectionOffset: 5); |
864 } | 869 } |
865 | 870 |
| 871 test_ArgumentList_local_constructor_required_param_0() async { |
| 872 addMetaPackageSource(); |
| 873 addTestSource(''' |
| 874 import 'package:meta/meta.dart'; |
| 875 class A { A({int one, @required String two: 'defaultValue'}) { } } |
| 876 main() { new A(^);}'''); |
| 877 await computeSuggestions(); |
| 878 assertSuggestArgumentsAndTypes( |
| 879 namedArgumentsWithTypes: {'one': 'int', 'two': 'String'}, |
| 880 requiredParamIndices: [1]); |
| 881 } |
| 882 |
866 test_ArgumentList_local_function_1() async { | 883 test_ArgumentList_local_function_1() async { |
867 // ArgumentList MethodInvocation ExpressionStatement Block | 884 // ArgumentList MethodInvocation ExpressionStatement Block |
868 addTestSource(''' | 885 addTestSource(''' |
869 import '/libA.dart' | 886 import '/libA.dart' |
870 expect(arg) { } | 887 expect(arg) { } |
871 class B { } | 888 class B { } |
872 String bar() => true; | 889 String bar() => true; |
873 void main() {expect(^)}'''); | 890 void main() {expect(^)}'''); |
874 await computeSuggestions(); | 891 await computeSuggestions(); |
875 assertSuggestArgumentList(['arg'], ['dynamic']); | 892 assertSuggestArgumentList(['arg'], ['dynamic']); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1015 addTestSource(''' | 1032 addTestSource(''' |
1016 import '/libA.dart' | 1033 import '/libA.dart' |
1017 class B { | 1034 class B { |
1018 expect(arg, int blat) { } | 1035 expect(arg, int blat) { } |
1019 void foo() {expect(^)}} | 1036 void foo() {expect(^)}} |
1020 String bar() => true;'''); | 1037 String bar() => true;'''); |
1021 await computeSuggestions(); | 1038 await computeSuggestions(); |
1022 assertSuggestArgumentList(['arg', 'blat'], ['dynamic', 'int']); | 1039 assertSuggestArgumentList(['arg', 'blat'], ['dynamic', 'int']); |
1023 } | 1040 } |
1024 } | 1041 } |
OLD | NEW |