@@ -22,12 +22,14 @@ import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
22
22
import 'package:analyzer_plugin/protocol/protocol.dart' as plugin;
23
23
import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin;
24
24
import 'package:analyzer_utilities/check/check.dart' ;
25
+ import 'package:meta/meta.dart' ;
25
26
import 'package:test/test.dart' ;
26
27
import 'package:test_reflective_loader/test_reflective_loader.dart' ;
27
28
28
29
import 'domain_completion_util.dart' ;
29
30
import 'mocks.dart' ;
30
31
import 'src/plugin/plugin_manager_test.dart' ;
32
+ import 'utils/change_check.dart' ;
31
33
32
34
void main () {
33
35
defineReflectiveSuite (() {
@@ -43,30 +45,31 @@ class CompletionDomainHandlerGetSuggestionDetails2Test
43
45
Future <void > test_alreadyImported () async {
44
46
await _configureWithWorkspaceRoot ();
45
47
46
- var validator = await _getTestCodeDetails ('''
48
+ var details = await _getTestCodeDetails ('''
47
49
import 'dart:math';
48
50
void f() {
49
51
Rand^
50
52
}
51
53
''' , completion: 'Random' , libraryUri: 'dart:math' );
52
- validator
53
- ..hasCompletion ('Random' )
54
- ..hasChange (). assertNoFileEdits () ;
54
+ check (details)
55
+ ..completion. isEqualTo ('Random' )
56
+ ..change.edits.isEmpty ;
55
57
}
56
58
57
59
Future <void > test_import_dart () async {
58
60
await _configureWithWorkspaceRoot ();
59
61
60
- var validator = await _getTestCodeDetails ('''
62
+ var details = await _getTestCodeDetails ('''
61
63
void f() {
62
64
R^
63
65
}
64
66
''' , completion: 'Random' , libraryUri: 'dart:math' );
65
- validator
66
- ..hasCompletion ('Random' )
67
- ..hasChange ()
67
+ check (details)
68
+ ..completion. isEqualTo ('Random' )
69
+ ..change
68
70
.hasFileEdit (testFilePathPlatform)
69
- .whenApplied (testFileContent, r'''
71
+ .appliedTo (testFileContent)
72
+ .isEqualTo (r'''
70
73
import 'dart:math';
71
74
72
75
void f() {
@@ -94,16 +97,17 @@ class Test {}
94
97
95
98
await _configureWithWorkspaceRoot ();
96
99
97
- var validator = await _getTestCodeDetails ('''
100
+ var details = await _getTestCodeDetails ('''
98
101
void f() {
99
102
T^
100
103
}
101
104
''' , completion: 'Test' , libraryUri: 'package:aaa/a.dart' );
102
- validator
103
- ..hasCompletion ('Test' )
104
- ..hasChange ()
105
+ check (details)
106
+ ..completion. isEqualTo ('Test' )
107
+ ..change
105
108
.hasFileEdit (testFilePathPlatform)
106
- .whenApplied (testFileContent, r'''
109
+ .appliedTo (testFileContent)
110
+ .isEqualTo (r'''
107
111
import 'package:aaa/a.dart';
108
112
109
113
void f() {
@@ -119,16 +123,17 @@ class Test {}
119
123
120
124
await _configureWithWorkspaceRoot ();
121
125
122
- var validator = await _getTestCodeDetails ('''
126
+ var details = await _getTestCodeDetails ('''
123
127
void f() {
124
128
T^
125
129
}
126
130
''' , completion: 'Test' , libraryUri: 'package:test/a.dart' );
127
- validator
128
- ..hasCompletion ('Test' )
129
- ..hasChange ()
131
+ check (details)
132
+ ..completion. isEqualTo ('Test' )
133
+ ..change
130
134
.hasFileEdit (testFilePathPlatform)
131
- .whenApplied (testFileContent, r'''
135
+ .appliedTo (testFileContent)
136
+ .isEqualTo (r'''
132
137
import 'package:test/a.dart';
133
138
134
139
void f() {
@@ -160,7 +165,7 @@ void f() {
160
165
expect (response.error? .code, RequestErrorCode .INVALID_FILE_PATH_FORMAT );
161
166
}
162
167
163
- Future <GetSuggestionDetails2Validator > _getCodeDetails ({
168
+ Future <CompletionGetSuggestionDetails2Result > _getCodeDetails ({
164
169
required String path,
165
170
required String content,
166
171
required String completion,
@@ -184,7 +189,7 @@ void f() {
184
189
);
185
190
}
186
191
187
- Future <GetSuggestionDetails2Validator > _getDetails ({
192
+ Future <CompletionGetSuggestionDetails2Result > _getDetails ({
188
193
required String path,
189
194
required int completionOffset,
190
195
required String completion,
@@ -198,11 +203,10 @@ void f() {
198
203
).toRequest ('0' );
199
204
200
205
var response = await _handleSuccessfulRequest (request);
201
- var result = CompletionGetSuggestionDetails2Result .fromResponse (response);
202
- return GetSuggestionDetails2Validator (result);
206
+ return CompletionGetSuggestionDetails2Result .fromResponse (response);
203
207
}
204
208
205
- Future <GetSuggestionDetails2Validator > _getTestCodeDetails (
209
+ Future <CompletionGetSuggestionDetails2Result > _getTestCodeDetails (
206
210
String content, {
207
211
required String completion,
208
212
required String libraryUri,
@@ -2548,20 +2552,6 @@ class CompletionGetSuggestions2ResponseValidator {
2548
2552
}
2549
2553
}
2550
2554
2551
- class GetSuggestionDetails2Validator {
2552
- final CompletionGetSuggestionDetails2Result result;
2553
-
2554
- GetSuggestionDetails2Validator (this .result);
2555
-
2556
- SourceChangeValidator hasChange () {
2557
- return SourceChangeValidator (result.change);
2558
- }
2559
-
2560
- void hasCompletion (Object completion) {
2561
- expect (result.completion, completion);
2562
- }
2563
- }
2564
-
2565
2555
class PubPackageAnalysisServerTest with ResourceProviderMixin {
2566
2556
late final MockServerChannel serverChannel;
2567
2557
late final AnalysisServer server;
@@ -2739,32 +2729,6 @@ class SingleSuggestionValidator {
2739
2729
}
2740
2730
}
2741
2731
2742
- class SourceChangeValidator {
2743
- final SourceChange change;
2744
-
2745
- SourceChangeValidator (this .change);
2746
-
2747
- void assertNoFileEdits () {
2748
- expect (change.edits, isEmpty);
2749
- }
2750
-
2751
- SourceFileEditValidator hasFileEdit (String path) {
2752
- var edit = change.edits.singleWhere ((e) => e.file == path);
2753
- return SourceFileEditValidator (edit);
2754
- }
2755
- }
2756
-
2757
- class SourceFileEditValidator {
2758
- final SourceFileEdit edit;
2759
-
2760
- SourceFileEditValidator (this .edit);
2761
-
2762
- void whenApplied (String applyTo, Object expected) {
2763
- var actual = SourceEdit .applySequence (applyTo, edit.edits);
2764
- expect (actual, expected);
2765
- }
2766
- }
2767
-
2768
2732
class SuggestionsValidator {
2769
2733
final List <CompletionSuggestion > suggestions;
2770
2734
final List <String >? libraryUrisToImport;
@@ -2853,3 +2817,21 @@ class SuggestionsValidator {
2853
2817
return withKind (CompletionSuggestionKind .IDENTIFIER );
2854
2818
}
2855
2819
}
2820
+
2821
+ extension on CheckTarget <CompletionGetSuggestionDetails2Result > {
2822
+ @useResult
2823
+ CheckTarget <String > get completion {
2824
+ return nest (
2825
+ value.completion,
2826
+ (selected) => 'has completion ${valueStr (selected )}' ,
2827
+ );
2828
+ }
2829
+
2830
+ @useResult
2831
+ CheckTarget <SourceChange > get change {
2832
+ return nest (
2833
+ value.change,
2834
+ (selected) => 'has change ${valueStr (selected )}' ,
2835
+ );
2836
+ }
2837
+ }
0 commit comments