|
9 | 9 | /// different meanings, where the existing grammar didn’t allow the `?` token to
|
10 | 10 | /// be followed by `.` anywhere.
|
11 | 11 | ///
|
12 |
| -/// @description Checks that `?.id` is parsed as `?. id` which is a compile-time |
13 |
| -/// error. |
| 12 | +/// @description Checks that `?.id` is parsed like `? .id`. |
14 | 13 |
|
15 | 14 |
|
16 |
| -// SharedOptions=--enable-experiment=dot-shorthands,null-aware-elements |
| 15 | +// SharedOptions=--enable-experiment=dot-shorthands |
| 16 | + |
| 17 | +import '../../Utils/expect.dart'; |
17 | 18 |
|
18 | 19 | class C {
|
19 | 20 | int value;
|
@@ -57,164 +58,43 @@ extension type ET(int value) {
|
57 | 58 | static ET? three() => ET(3);
|
58 | 59 | }
|
59 | 60 |
|
60 |
| -void testConstructors() { |
61 |
| - var l = <C>[ |
62 |
| - ?.id(0) |
63 |
| -// ^^ |
64 |
| -// [analyzer] unspecified |
65 |
| -// [cfe] unspecified |
66 |
| - ]; |
67 |
| - |
68 |
| - var s = <C>{ |
69 |
| - ?.new(0), |
70 |
| -// ^^ |
71 |
| -// [analyzer] unspecified |
72 |
| -// [cfe] unspecified |
73 |
| - }; |
74 |
| - |
75 |
| - var m1 = <String, ET> { |
76 |
| - "key": ?.id(0) |
77 |
| -// ^^ |
78 |
| -// [analyzer] unspecified |
79 |
| -// [cfe] unspecified |
80 |
| - ?.new(0): "value1", |
81 |
| -// ^^ |
82 |
| -// [analyzer] unspecified |
83 |
| -// [cfe] unspecified |
84 |
| - }; |
85 |
| - |
86 |
| - var m2 = <ET, String> { |
87 |
| - ?.new(0): "value" |
88 |
| -// ^^ |
89 |
| -// [analyzer] unspecified |
90 |
| -// [cfe] unspecified |
91 |
| - }; |
92 |
| -} |
93 |
| - |
94 |
| -void testVariables() { |
95 |
| - var l = <C>[ |
96 |
| - ?.one |
97 |
| -// ^^ |
98 |
| -// [analyzer] unspecified |
99 |
| -// [cfe] unspecified |
100 |
| - ]; |
101 |
| - |
102 |
| - var s = <M>{ |
103 |
| - ?.one |
104 |
| -// ^^ |
105 |
| -// [analyzer] unspecified |
106 |
| -// [cfe] unspecified |
107 |
| - }; |
108 |
| - |
109 |
| - var m1 = <String, E>{ |
110 |
| - "key": ?.one, |
111 |
| -// ^^ |
112 |
| -// [analyzer] unspecified |
113 |
| -// [cfe] unspecified |
114 |
| - }; |
115 |
| - |
116 |
| - var m2 = <ET, String> { |
117 |
| - ?.one: "value" |
118 |
| -// ^^ |
119 |
| -// [analyzer] unspecified |
120 |
| -// [cfe] unspecified |
121 |
| - }; |
122 |
| -} |
123 |
| - |
124 |
| -void testGetters() { |
125 |
| - var l = <C>[ |
126 |
| - ?.two |
127 |
| -// ^^ |
128 |
| -// [analyzer] unspecified |
129 |
| -// [cfe] unspecified |
130 |
| - ]; |
131 |
| - |
132 |
| - var s = <M>{ |
133 |
| - ?.two |
134 |
| -// ^^ |
135 |
| -// [analyzer] unspecified |
136 |
| -// [cfe] unspecified |
137 |
| - }; |
138 |
| - |
139 |
| - var m1 = <String, E>{ |
140 |
| - "key": ?.two, |
141 |
| -// ^^ |
142 |
| -// [analyzer] unspecified |
143 |
| -// [cfe] unspecified |
144 |
| - }; |
145 |
| - |
146 |
| - var m2 = <ET, String> { |
147 |
| - ?.two: "value" |
148 |
| -// ^^ |
149 |
| -// [analyzer] unspecified |
150 |
| -// [cfe] unspecified |
151 |
| - }; |
152 |
| -} |
153 |
| - |
154 |
| -void testMethods() { |
155 |
| - var l = <C>[ |
156 |
| - ?.three() |
157 |
| -// ^^ |
158 |
| -// [analyzer] unspecified |
159 |
| -// [cfe] unspecified |
| 61 | +main() { |
| 62 | + var l1 = <C>[ |
| 63 | + ?.id(0), // ignore: invalid_null_aware_operator |
| 64 | + ?.new(0), // ignore: invalid_null_aware_operator |
| 65 | + ?.one, |
| 66 | + ?.two, |
| 67 | + ?.three() |
160 | 68 | ];
|
| 69 | + Expect.listEquals([C(0), C(0), C(1), C(2), C(3)], l1); |
161 | 70 |
|
162 | 71 | var s = <M>{
|
163 |
| - ?.three() |
164 |
| -// ^^ |
165 |
| -// [analyzer] unspecified |
166 |
| -// [cfe] unspecified |
| 72 | + ?.one, |
| 73 | + ?.two, |
| 74 | + ?.three() |
167 | 75 | };
|
| 76 | + Expect.setEquals({MC(1), MC(2), MC(3)}, s); |
168 | 77 |
|
169 | 78 | var m1 = <String, E>{
|
170 |
| - "key": ?.three(), |
171 |
| -// ^^ |
172 |
| -// [analyzer] unspecified |
173 |
| -// [cfe] unspecified |
| 79 | + "key0": ?.e1, // ignore: invalid_null_aware_operator |
| 80 | + "key1": ?.one, |
| 81 | + "key2": ?.two, |
| 82 | + "key3": ?.three() |
174 | 83 | };
|
| 84 | + Expect.mapEquals({"key0": E.e1, "key1": E.e1, "key2": E.e2, "key3":E.e3}, m1); |
175 | 85 |
|
176 | 86 | var m2 = <ET, String> {
|
177 |
| - ?.three(): "value" |
178 |
| -// ^^ |
179 |
| -// [analyzer] unspecified |
180 |
| -// [cfe] unspecified |
181 |
| - }; |
182 |
| -} |
183 |
| - |
184 |
| -void testEnumValues() { |
185 |
| - var l = <E>[ |
186 |
| - ?.e0 |
187 |
| -// ^^ |
188 |
| -// [analyzer] unspecified |
189 |
| -// [cfe] unspecified |
190 |
| - ]; |
191 |
| - |
192 |
| - var s = <E>{ |
193 |
| - ?.e0 |
194 |
| -// ^^ |
195 |
| -// [analyzer] unspecified |
196 |
| -// [cfe] unspecified |
197 |
| - }; |
198 |
| - |
199 |
| - var m1 = <String, E>{ |
200 |
| - "key": ?.e0, |
201 |
| -// ^^ |
202 |
| -// [analyzer] unspecified |
203 |
| -// [cfe] unspecified |
204 |
| - }; |
205 |
| - |
206 |
| - var m2 = <E, String> { |
207 |
| - ?.e0: "value" |
208 |
| -// ^^ |
209 |
| -// [analyzer] unspecified |
210 |
| -// [cfe] unspecified |
| 87 | + ?.id(-1): "value0", |
| 88 | + ?.new(0): "value1", |
| 89 | + ?.one: "value2", |
| 90 | + ?.two: "value3", |
| 91 | + ?.three(): "value4" |
211 | 92 | };
|
212 |
| -} |
213 |
| - |
214 |
| -main() { |
215 |
| - testConstructors(); |
216 |
| - testVariables(); |
217 |
| - testGetters(); |
218 |
| - testMethods(); |
219 |
| - testEnumValues(); |
| 93 | + Expect.mapEquals({ |
| 94 | + ET(-1): "value0", |
| 95 | + ET(0): "value1", |
| 96 | + ET(1): "value2", |
| 97 | + ET(2): "value3", |
| 98 | + ET(3): "value4" |
| 99 | + }, m2); |
220 | 100 | }
|
0 commit comments