@@ -59,6 +59,111 @@ foo(String str) {}
59
59
expect (result.path.first.name, 'f' );
60
60
}
61
61
62
+ Future <void > test_findReferences_inNullAware_listElement () async {
63
+ var text = r'''
64
+ List<int> f(int? foo) {
65
+ return [?foo /* target */];
66
+ }
67
+ ''' ;
68
+
69
+ pathname = sourcePath ('foo.dart' );
70
+ writeFile (pathname, text);
71
+ await standardAnalysisSetup ();
72
+ await analysisFinished;
73
+
74
+ var results = (await _findElementReferences (text))! ;
75
+ expect (results, hasLength (1 ));
76
+ var result = results.first;
77
+ expect (result.location.file, pathname);
78
+ expect (result.isPotential, isFalse);
79
+ expect (result.kind.name, SearchResultKind .READ .name);
80
+ expect (result.path.first.name, 'f' );
81
+ }
82
+
83
+ Future <void > test_findReferences_inNullAware_mapKey () async {
84
+ var text = r'''
85
+ Map<int, String> f(int? foo) {
86
+ return {?foo /* target */: "value"};
87
+ }
88
+ ''' ;
89
+
90
+ pathname = sourcePath ('foo.dart' );
91
+ writeFile (pathname, text);
92
+ await standardAnalysisSetup ();
93
+ await analysisFinished;
94
+
95
+ var results = (await _findElementReferences (text))! ;
96
+ expect (results, hasLength (1 ));
97
+ var result = results.first;
98
+ expect (result.location.file, pathname);
99
+ expect (result.isPotential, isFalse);
100
+ expect (result.kind.name, SearchResultKind .READ .name);
101
+ expect (result.path.first.name, 'f' );
102
+ }
103
+
104
+ Future <void > test_findReferences_inNullAware_mapKeyValue () async {
105
+ var text = r'''
106
+ Map<int, String> f(int? key, String? value) {
107
+ return {?key: ?value /* target */};
108
+ }
109
+ ''' ;
110
+
111
+ pathname = sourcePath ('foo.dart' );
112
+ writeFile (pathname, text);
113
+ await standardAnalysisSetup ();
114
+ await analysisFinished;
115
+
116
+ var results = (await _findElementReferences (text))! ;
117
+ expect (results, hasLength (1 ));
118
+ var result = results.first;
119
+ expect (result.location.file, pathname);
120
+ expect (result.isPotential, isFalse);
121
+ expect (result.kind.name, SearchResultKind .READ .name);
122
+ expect (result.path.first.name, 'f' );
123
+ }
124
+
125
+ Future <void > test_findReferences_inNullAware_mapValue () async {
126
+ var text = r'''
127
+ Map<String, int> f(int? foo) {
128
+ return {"key": ?foo /* target */};
129
+ }
130
+ ''' ;
131
+
132
+ pathname = sourcePath ('foo.dart' );
133
+ writeFile (pathname, text);
134
+ await standardAnalysisSetup ();
135
+ await analysisFinished;
136
+
137
+ var results = (await _findElementReferences (text))! ;
138
+ expect (results, hasLength (1 ));
139
+ var result = results.first;
140
+ expect (result.location.file, pathname);
141
+ expect (result.isPotential, isFalse);
142
+ expect (result.kind.name, SearchResultKind .READ .name);
143
+ expect (result.path.first.name, 'f' );
144
+ }
145
+
146
+ Future <void > test_findReferences_inNullAware_setElement () async {
147
+ var text = r'''
148
+ Set<int> f(int? foo) {
149
+ return {?foo /* target */};
150
+ }
151
+ ''' ;
152
+
153
+ pathname = sourcePath ('foo.dart' );
154
+ writeFile (pathname, text);
155
+ await standardAnalysisSetup ();
156
+ await analysisFinished;
157
+
158
+ var results = (await _findElementReferences (text))! ;
159
+ expect (results, hasLength (1 ));
160
+ var result = results.first;
161
+ expect (result.location.file, pathname);
162
+ expect (result.isPotential, isFalse);
163
+ expect (result.kind.name, SearchResultKind .READ .name);
164
+ expect (result.path.first.name, 'f' );
165
+ }
166
+
62
167
Future <List <SearchResult >?> _findElementReferences (String text) async {
63
168
var offset = text.indexOf (' /* target */' ) - 1 ;
64
169
var result = await sendSearchFindElementReferences (pathname, offset, false );
0 commit comments