Skip to content

Commit e7f14ab

Browse files
committed
Add test_generator_expression_argument
1 parent 56c73cc commit e7f14ab

2 files changed

Lines changed: 346 additions & 0 deletions

File tree

‎parser/src/parser.rs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,19 @@ with (0 as a, 1 as b,): pass
310310
}
311311
}
312312

313+
#[test]
314+
fn test_generator_expression_argument() {
315+
let source = r#"' '.join(
316+
sql
317+
for sql in (
318+
"LIMIT %d" % limit if limit else None,
319+
("OFFSET %d" % offset) if offset else None,
320+
)
321+
)"#;
322+
let parse_ast = parse_expression(source, "<test>").unwrap();
323+
insta::assert_debug_snapshot!(parse_ast);
324+
}
325+
313326
#[test]
314327
fn test_dict_unpacking() {
315328
let parse_ast = parse_expression(r#"{"a": "b", **c, "d": "e"}"#, "<test>").unwrap();
Lines changed: 333 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,333 @@
1+
---
2+
source: compiler/parser/src/parser.rs
3+
expression: parse_ast
4+
---
5+
Located {
6+
location: Location {
7+
row: 1,
8+
column: 0,
9+
},
10+
end_location: Some(
11+
Location {
12+
row: 7,
13+
column: 1,
14+
},
15+
),
16+
custom: (),
17+
node: Call {
18+
func: Located {
19+
location: Location {
20+
row: 1,
21+
column: 0,
22+
},
23+
end_location: Some(
24+
Location {
25+
row: 1,
26+
column: 8,
27+
},
28+
),
29+
custom: (),
30+
node: Attribute {
31+
value: Located {
32+
location: Location {
33+
row: 1,
34+
column: 0,
35+
},
36+
end_location: Some(
37+
Location {
38+
row: 1,
39+
column: 3,
40+
},
41+
),
42+
custom: (),
43+
node: Constant {
44+
value: Str(
45+
" ",
46+
),
47+
kind: None,
48+
},
49+
},
50+
attr: "join",
51+
ctx: Load,
52+
},
53+
},
54+
args: [
55+
Located {
56+
location: Location {
57+
row: 2,
58+
column: 4,
59+
},
60+
end_location: Some(
61+
Location {
62+
row: 6,
63+
column: 5,
64+
},
65+
),
66+
custom: (),
67+
node: GeneratorExp {
68+
elt: Located {
69+
location: Location {
70+
row: 2,
71+
column: 4,
72+
},
73+
end_location: Some(
74+
Location {
75+
row: 2,
76+
column: 7,
77+
},
78+
),
79+
custom: (),
80+
node: Name {
81+
id: "sql",
82+
ctx: Load,
83+
},
84+
},
85+
generators: [
86+
Comprehension {
87+
target: Located {
88+
location: Location {
89+
row: 3,
90+
column: 8,
91+
},
92+
end_location: Some(
93+
Location {
94+
row: 3,
95+
column: 11,
96+
},
97+
),
98+
custom: (),
99+
node: Name {
100+
id: "sql",
101+
ctx: Store,
102+
},
103+
},
104+
iter: Located {
105+
location: Location {
106+
row: 3,
107+
column: 15,
108+
},
109+
end_location: Some(
110+
Location {
111+
row: 6,
112+
column: 5,
113+
},
114+
),
115+
custom: (),
116+
node: Tuple {
117+
elts: [
118+
Located {
119+
location: Location {
120+
row: 4,
121+
column: 8,
122+
},
123+
end_location: Some(
124+
Location {
125+
row: 4,
126+
column: 45,
127+
},
128+
),
129+
custom: (),
130+
node: IfExp {
131+
test: Located {
132+
location: Location {
133+
row: 4,
134+
column: 30,
135+
},
136+
end_location: Some(
137+
Location {
138+
row: 4,
139+
column: 35,
140+
},
141+
),
142+
custom: (),
143+
node: Name {
144+
id: "limit",
145+
ctx: Load,
146+
},
147+
},
148+
body: Located {
149+
location: Location {
150+
row: 4,
151+
column: 8,
152+
},
153+
end_location: Some(
154+
Location {
155+
row: 4,
156+
column: 26,
157+
},
158+
),
159+
custom: (),
160+
node: BinOp {
161+
left: Located {
162+
location: Location {
163+
row: 4,
164+
column: 8,
165+
},
166+
end_location: Some(
167+
Location {
168+
row: 4,
169+
column: 18,
170+
},
171+
),
172+
custom: (),
173+
node: Constant {
174+
value: Str(
175+
"LIMIT %d",
176+
),
177+
kind: None,
178+
},
179+
},
180+
op: Mod,
181+
right: Located {
182+
location: Location {
183+
row: 4,
184+
column: 21,
185+
},
186+
end_location: Some(
187+
Location {
188+
row: 4,
189+
column: 26,
190+
},
191+
),
192+
custom: (),
193+
node: Name {
194+
id: "limit",
195+
ctx: Load,
196+
},
197+
},
198+
},
199+
},
200+
orelse: Located {
201+
location: Location {
202+
row: 4,
203+
column: 41,
204+
},
205+
end_location: Some(
206+
Location {
207+
row: 4,
208+
column: 45,
209+
},
210+
),
211+
custom: (),
212+
node: Constant {
213+
value: None,
214+
kind: None,
215+
},
216+
},
217+
},
218+
},
219+
Located {
220+
location: Location {
221+
row: 5,
222+
column: 8,
223+
},
224+
end_location: Some(
225+
Location {
226+
row: 5,
227+
column: 50,
228+
},
229+
),
230+
custom: (),
231+
node: IfExp {
232+
test: Located {
233+
location: Location {
234+
row: 5,
235+
column: 34,
236+
},
237+
end_location: Some(
238+
Location {
239+
row: 5,
240+
column: 40,
241+
},
242+
),
243+
custom: (),
244+
node: Name {
245+
id: "offset",
246+
ctx: Load,
247+
},
248+
},
249+
body: Located {
250+
location: Location {
251+
row: 5,
252+
column: 9,
253+
},
254+
end_location: Some(
255+
Location {
256+
row: 5,
257+
column: 29,
258+
},
259+
),
260+
custom: (),
261+
node: BinOp {
262+
left: Located {
263+
location: Location {
264+
row: 5,
265+
column: 9,
266+
},
267+
end_location: Some(
268+
Location {
269+
row: 5,
270+
column: 20,
271+
},
272+
),
273+
custom: (),
274+
node: Constant {
275+
value: Str(
276+
"OFFSET %d",
277+
),
278+
kind: None,
279+
},
280+
},
281+
op: Mod,
282+
right: Located {
283+
location: Location {
284+
row: 5,
285+
column: 23,
286+
},
287+
end_location: Some(
288+
Location {
289+
row: 5,
290+
column: 29,
291+
},
292+
),
293+
custom: (),
294+
node: Name {
295+
id: "offset",
296+
ctx: Load,
297+
},
298+
},
299+
},
300+
},
301+
orelse: Located {
302+
location: Location {
303+
row: 5,
304+
column: 46,
305+
},
306+
end_location: Some(
307+
Location {
308+
row: 5,
309+
column: 50,
310+
},
311+
),
312+
custom: (),
313+
node: Constant {
314+
value: None,
315+
kind: None,
316+
},
317+
},
318+
},
319+
},
320+
],
321+
ctx: Load,
322+
},
323+
},
324+
ifs: [],
325+
is_async: 0,
326+
},
327+
],
328+
},
329+
},
330+
],
331+
keywords: [],
332+
},
333+
}

0 commit comments

Comments
 (0)