@@ -63,6 +63,162 @@ class Foo {
6363 );
6464 }
6565
66+ Future <void > test_nullAwareElements_inList () async {
67+ var code = TestCode .parse ('''
68+ class Foo<T> {
69+ List<int> a(String b) {
70+ return [?(1 ^+ 2) * 3];
71+ }
72+ }
73+ ''' );
74+
75+ await initialize ();
76+ await openFile (mainFileUri, code.code);
77+ var lineInfo = LineInfo .fromContent (code.code);
78+
79+ // The returned List corresponds to the input list of positions, and not
80+ // the set of ranges - each range within that list has a (recursive) parent
81+ // to walk up all ranges for that position.
82+ var regions = await getSelectionRanges (mainFileUri, [
83+ code.position.position,
84+ ]);
85+ expect (regions! .length, equals (1 )); // Only one position was sent.
86+ var regionTexts =
87+ _getSelectionRangeText (lineInfo, code.code, regions.first).toList ();
88+
89+ expect (
90+ regionTexts,
91+ equals ([
92+ '1 + 2' ,
93+ '(1 + 2)' ,
94+ '(1 + 2) * 3' ,
95+ '?(1 + 2) * 3' ,
96+ '[?(1 + 2) * 3]' ,
97+ 'return [?(1 + 2) * 3];' ,
98+ '{\n return [?(1 + 2) * 3];\n }' ,
99+ 'List<int> a(String b) {\n return [?(1 + 2) * 3];\n }' ,
100+ 'class Foo<T> {\n List<int> a(String b) {\n return [?(1 + 2) * 3];\n }\n }' ,
101+ ]),
102+ );
103+ }
104+
105+ Future <void > test_nullAwareElements_inMapKey () async {
106+ var code = TestCode .parse ('''
107+ class Foo<T> {
108+ Map<int, String> a(String b) {
109+ return {?(1 ^+ 2) * 3: b};
110+ }
111+ }
112+ ''' );
113+
114+ await initialize ();
115+ await openFile (mainFileUri, code.code);
116+ var lineInfo = LineInfo .fromContent (code.code);
117+
118+ // The returned List corresponds to the input list of positions, and not
119+ // the set of ranges - each range within that list has a (recursive) parent
120+ // to walk up all ranges for that position.
121+ var regions = await getSelectionRanges (mainFileUri, [
122+ code.position.position,
123+ ]);
124+ expect (regions! .length, equals (1 )); // Only one position was sent.
125+ var regionTexts =
126+ _getSelectionRangeText (lineInfo, code.code, regions.first).toList ();
127+
128+ expect (
129+ regionTexts,
130+ equals ([
131+ '1 + 2' ,
132+ '(1 + 2)' ,
133+ '(1 + 2) * 3' ,
134+ '?(1 + 2) * 3: b' ,
135+ '{?(1 + 2) * 3: b}' ,
136+ 'return {?(1 + 2) * 3: b};' ,
137+ '{\n return {?(1 + 2) * 3: b};\n }' ,
138+ 'Map<int, String> a(String b) {\n return {?(1 + 2) * 3: b};\n }' ,
139+ 'class Foo<T> {\n Map<int, String> a(String b) {\n return {?(1 + 2) * 3: b};\n }\n }' ,
140+ ]),
141+ );
142+ }
143+
144+ Future <void > test_nullAwareElements_inMapValue () async {
145+ var code = TestCode .parse ('''
146+ class Foo<T> {
147+ Map<String, int> a(String b) {
148+ return {b: ?(1 ^+ 2) * 3};
149+ }
150+ }
151+ ''' );
152+
153+ await initialize ();
154+ await openFile (mainFileUri, code.code);
155+ var lineInfo = LineInfo .fromContent (code.code);
156+
157+ // The returned List corresponds to the input list of positions, and not
158+ // the set of ranges - each range within that list has a (recursive) parent
159+ // to walk up all ranges for that position.
160+ var regions = await getSelectionRanges (mainFileUri, [
161+ code.position.position,
162+ ]);
163+ expect (regions! .length, equals (1 )); // Only one position was sent.
164+ var regionTexts =
165+ _getSelectionRangeText (lineInfo, code.code, regions.first).toList ();
166+
167+ expect (
168+ regionTexts,
169+ equals ([
170+ '1 + 2' ,
171+ '(1 + 2)' ,
172+ '(1 + 2) * 3' ,
173+ 'b: ?(1 + 2) * 3' ,
174+ '{b: ?(1 + 2) * 3}' ,
175+ 'return {b: ?(1 + 2) * 3};' ,
176+ '{\n return {b: ?(1 + 2) * 3};\n }' ,
177+ 'Map<String, int> a(String b) {\n return {b: ?(1 + 2) * 3};\n }' ,
178+ 'class Foo<T> {\n Map<String, int> a(String b) {\n return {b: ?(1 + 2) * 3};\n }\n }' ,
179+ ]),
180+ );
181+ }
182+
183+ Future <void > test_nullAwareElements_inSet () async {
184+ var code = TestCode .parse ('''
185+ class Foo<T> {
186+ Set<int> a(String b) {
187+ return {?(1 ^+ 2) * 3};
188+ }
189+ }
190+ ''' );
191+
192+ await initialize ();
193+ await openFile (mainFileUri, code.code);
194+ var lineInfo = LineInfo .fromContent (code.code);
195+
196+ // The returned List corresponds to the input list of positions, and not
197+ // the set of ranges - each range within that list has a (recursive) parent
198+ // to walk up all ranges for that position.
199+ var regions = await getSelectionRanges (mainFileUri, [
200+ code.position.position,
201+ ]);
202+ expect (regions! .length, equals (1 )); // Only one position was sent.
203+ var regionTexts =
204+ _getSelectionRangeText (lineInfo, code.code, regions.first).toList ();
205+
206+ expect (
207+ regionTexts,
208+ equals ([
209+ '1 + 2' ,
210+ '(1 + 2)' ,
211+ '(1 + 2) * 3' ,
212+ '?(1 + 2) * 3' ,
213+ '{?(1 + 2) * 3}' ,
214+ 'return {?(1 + 2) * 3};' ,
215+ '{\n return {?(1 + 2) * 3};\n }' ,
216+ 'Set<int> a(String b) {\n return {?(1 + 2) * 3};\n }' ,
217+ 'class Foo<T> {\n Set<int> a(String b) {\n return {?(1 + 2) * 3};\n }\n }' ,
218+ ]),
219+ );
220+ }
221+
66222 Future <void > test_single () async {
67223 var code = TestCode .parse ('''
68224class Foo<T> {
0 commit comments