microsoft/qdk

Public

mirrored from https://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
cc8e7546d95df3356cfccb59c23cbce76b0bd229

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

compiler/qsc_parse/src/expr/tests.rs

2437lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4#![allow(clippy::needless_raw_string_hashes)]
5
6use super::expr;
7use crate::tests::check;
8use expect_test::expect;
9
10#[test]
11fn lit_int() {
12 check(expr, "123", &expect!["Expr _id_ [0-3]: Lit: Int(123)"]);
13}
14
15#[test]
16fn lit_int_underscore() {
17 check(
18 expr,
19 "123_456",
20 &expect!["Expr _id_ [0-7]: Lit: Int(123456)"],
21 );
22}
23
24#[test]
25fn lit_int_leading_zero() {
26 check(expr, "0123", &expect!["Expr _id_ [0-4]: Lit: Int(123)"]);
27}
28
29#[test]
30fn lit_int_max() {
31 check(
32 expr,
33 "9_223_372_036_854_775_807",
34 &expect!["Expr _id_ [0-25]: Lit: Int(9223372036854775807)"],
35 );
36}
37
38// NOTE: Since we need to support literals of value i64::MIN while also parsing the negative sign
39// as a unary operator, we need to allow one special case of overflow that is the absolute value
40// of i64::MIN. This will wrap to a negative value. See the `lit_int_min` test below.
41// To check for other issues with handling i64::MIN, hexadecimal and binary literals
42// of i64::MIN also need to be tested.
43#[test]
44fn lit_int_overflow_min() {
45 check(
46 expr,
47 "9_223_372_036_854_775_808",
48 &expect!["Expr _id_ [0-25]: Lit: Int(-9223372036854775808)"],
49 );
50}
51
52#[test]
53fn lit_int_overflow_min_hexadecimal() {
54 check(
55 expr,
56 "0x8000000000000000",
57 &expect!["Expr _id_ [0-18]: Lit: Int(-9223372036854775808)"],
58 );
59}
60
61#[test]
62fn lit_int_overflow_min_binary() {
63 check(
64 expr,
65 "0b1000000000000000000000000000000000000000000000000000000000000000",
66 &expect!["Expr _id_ [0-66]: Lit: Int(-9223372036854775808)"],
67 );
68}
69
70#[test]
71fn lit_int_too_big() {
72 check(
73 expr,
74 "9_223_372_036_854_775_809",
75 &expect![[r#"
76 Error(
77 Lit(
78 "integer",
79 Span {
80 lo: 0,
81 hi: 25,
82 },
83 ),
84 )
85 "#]],
86 );
87}
88
89#[test]
90fn lit_int_too_big_hexadecimal() {
91 check(
92 expr,
93 "0x8000000000000001",
94 &expect![[r#"
95 Error(
96 Lit(
97 "integer",
98 Span {
99 lo: 0,
100 hi: 18,
101 },
102 ),
103 )
104 "#]],
105 );
106}
107
108#[test]
109fn lit_int_too_big_binary() {
110 check(
111 expr,
112 "0b1000000000000000000000000000000000000000000000000000000000000001",
113 &expect![[r#"
114 Error(
115 Lit(
116 "integer",
117 Span {
118 lo: 0,
119 hi: 66,
120 },
121 ),
122 )
123 "#]],
124 );
125}
126
127// NOTE: Since we need to support literals of value i64::MIN while also parsing the negative sign
128// as a unary operator, we need to allow one special case of overflow that is the absolute value
129// of i64::MIN. This will wrap to a negative value, and then negate of i64::MIN is i64::MIN, so
130// the correct value is achieved at runtime.
131#[test]
132fn lit_int_min() {
133 check(
134 expr,
135 "-9_223_372_036_854_775_808",
136 &expect![[r#"
137 Expr _id_ [0-26]: UnOp (Neg):
138 Expr _id_ [1-26]: Lit: Int(-9223372036854775808)"#]],
139 );
140}
141
142#[test]
143fn lit_int_hexadecimal() {
144 check(
145 expr,
146 "0x1a2b3c",
147 &expect!["Expr _id_ [0-8]: Lit: Int(1715004)"],
148 );
149}
150
151#[test]
152fn lit_int_octal() {
153 check(
154 expr,
155 "0o1234567",
156 &expect!["Expr _id_ [0-9]: Lit: Int(342391)"],
157 );
158}
159
160#[test]
161fn lit_int_binary() {
162 check(expr, "0b10110", &expect!["Expr _id_ [0-7]: Lit: Int(22)"]);
163}
164
165#[test]
166fn lit_bigint() {
167 check(expr, "123L", &expect!["Expr _id_ [0-4]: Lit: BigInt(123)"]);
168}
169
170#[test]
171fn lit_bigint_underscore() {
172 check(
173 expr,
174 "123_456L",
175 &expect!["Expr _id_ [0-8]: Lit: BigInt(123456)"],
176 );
177}
178
179#[test]
180fn lit_bigint_hexadecimal() {
181 check(
182 expr,
183 "0x1a2b3cL",
184 &expect!["Expr _id_ [0-9]: Lit: BigInt(1715004)"],
185 );
186}
187
188#[test]
189fn lit_bigint_octal() {
190 check(
191 expr,
192 "0o1234567L",
193 &expect!["Expr _id_ [0-10]: Lit: BigInt(342391)"],
194 );
195}
196
197#[test]
198fn lit_bigint_binary() {
199 check(
200 expr,
201 "0b10110L",
202 &expect!["Expr _id_ [0-8]: Lit: BigInt(22)"],
203 );
204}
205
206#[test]
207fn lit_double() {
208 check(expr, "1.23", &expect!["Expr _id_ [0-4]: Lit: Double(1.23)"]);
209}
210
211#[test]
212fn lit_double_leading_dot() {
213 check(
214 expr,
215 ".23",
216 &expect![[r#"
217 Error(
218 Rule(
219 "expression",
220 Dot,
221 Span {
222 lo: 0,
223 hi: 1,
224 },
225 ),
226 )
227 "#]],
228 );
229}
230
231#[test]
232fn lit_double_trailing_dot() {
233 check(expr, "1.", &expect!["Expr _id_ [0-2]: Lit: Double(1)"]);
234}
235
236#[test]
237fn lit_double_underscore() {
238 check(
239 expr,
240 "123_456.78",
241 &expect!["Expr _id_ [0-10]: Lit: Double(123456.78)"],
242 );
243}
244
245#[test]
246fn lit_double_leading_zero() {
247 check(expr, "0.23", &expect!["Expr _id_ [0-4]: Lit: Double(0.23)"]);
248}
249
250#[test]
251fn lit_double_trailing_exp_0() {
252 check(
253 expr,
254 "0e",
255 &expect![[r#"
256 Error(
257 Lit(
258 "floating-point",
259 Span {
260 lo: 0,
261 hi: 2,
262 },
263 ),
264 )
265 "#]],
266 );
267}
268
269#[test]
270fn lit_double_trailing_exp_1() {
271 check(
272 expr,
273 "1e",
274 &expect![[r#"
275 Error(
276 Lit(
277 "floating-point",
278 Span {
279 lo: 0,
280 hi: 2,
281 },
282 ),
283 )
284 "#]],
285 );
286}
287
288#[test]
289fn lit_double_trailing_dot_trailing_exp() {
290 check(
291 expr,
292 "1.e",
293 &expect![[r#"
294 Error(
295 Lit(
296 "floating-point",
297 Span {
298 lo: 0,
299 hi: 3,
300 },
301 ),
302 )
303 "#]],
304 );
305}
306
307#[test]
308fn lit_double_dot_trailing_exp() {
309 check(
310 expr,
311 "1.2e",
312 &expect![[r#"
313 Error(
314 Lit(
315 "floating-point",
316 Span {
317 lo: 0,
318 hi: 4,
319 },
320 ),
321 )
322 "#]],
323 );
324}
325
326#[test]
327fn lit_double_trailing_exp_dot() {
328 check(
329 expr,
330 "1e.",
331 &expect![[r#"
332 Error(
333 Lit(
334 "floating-point",
335 Span {
336 lo: 0,
337 hi: 2,
338 },
339 ),
340 )
341 "#]],
342 );
343}
344
345#[test]
346fn lit_int_hexadecimal_dot() {
347 check(expr, "0x123.45", &expect!["Expr _id_ [0-5]: Lit: Int(291)"]);
348}
349
350#[test]
351fn lit_string() {
352 check(
353 expr,
354 r#""foo""#,
355 &expect![[r#"Expr _id_ [0-5]: Lit: String("foo")"#]],
356 );
357}
358
359#[test]
360fn lit_string_escape_quote() {
361 check(
362 expr,
363 r#""foo\"bar""#,
364 &expect![[r#"Expr _id_ [0-10]: Lit: String("foo\"bar")"#]],
365 );
366}
367
368#[test]
369fn lit_string_escape_backslash() {
370 check(
371 expr,
372 r#""\\""#,
373 &expect![[r#"Expr _id_ [0-4]: Lit: String("\\")"#]],
374 );
375}
376
377#[test]
378fn lit_string_escape_newline() {
379 check(
380 expr,
381 r#""\n""#,
382 &expect![[r#"Expr _id_ [0-4]: Lit: String("\n")"#]],
383 );
384}
385
386#[test]
387fn lit_string_escape_carriage_return() {
388 check(
389 expr,
390 r#""\r""#,
391 &expect![[r#"Expr _id_ [0-4]: Lit: String("\r")"#]],
392 );
393}
394
395#[test]
396fn lit_string_escape_tab() {
397 check(
398 expr,
399 r#""\t""#,
400 &expect![[r#"Expr _id_ [0-4]: Lit: String("\t")"#]],
401 );
402}
403
404#[test]
405fn lit_string_unknown_escape() {
406 check(
407 expr,
408 r#""\x""#,
409 &expect![[r#"
410 Error(
411 Escape(
412 'x',
413 Span {
414 lo: 2,
415 hi: 3,
416 },
417 ),
418 )
419 "#]],
420 );
421}
422
423#[test]
424fn lit_string_unmatched_quote() {
425 check(
426 expr,
427 r#""Uh oh.."#,
428 &expect![[r#"
429 Error(
430 Rule(
431 "expression",
432 Eof,
433 Span {
434 lo: 8,
435 hi: 8,
436 },
437 ),
438 )
439
440 [
441 Error(
442 Lex(
443 UnterminatedString(
444 Span {
445 lo: 0,
446 hi: 0,
447 },
448 ),
449 ),
450 ),
451 ]"#]],
452 );
453}
454
455#[test]
456fn lit_string_empty() {
457 check(
458 expr,
459 r#""""#,
460 &expect![[r#"Expr _id_ [0-2]: Lit: String("")"#]],
461 );
462}
463
464#[test]
465fn lit_false() {
466 check(expr, "false", &expect!["Expr _id_ [0-5]: Lit: Bool(false)"]);
467}
468
469#[test]
470fn lit_true() {
471 check(expr, "true", &expect!["Expr _id_ [0-4]: Lit: Bool(true)"]);
472}
473
474#[test]
475fn lit_zero() {
476 check(expr, "Zero", &expect!["Expr _id_ [0-4]: Lit: Result(Zero)"]);
477}
478
479#[test]
480fn lit_one() {
481 check(expr, "One", &expect!["Expr _id_ [0-3]: Lit: Result(One)"]);
482}
483
484#[test]
485fn lit_pauli_i() {
486 check(expr, "PauliI", &expect!["Expr _id_ [0-6]: Lit: Pauli(I)"]);
487}
488
489#[test]
490fn lit_pauli_x() {
491 check(expr, "PauliX", &expect!["Expr _id_ [0-6]: Lit: Pauli(X)"]);
492}
493
494#[test]
495fn lit_pauli_y() {
496 check(expr, "PauliY", &expect!["Expr _id_ [0-6]: Lit: Pauli(Y)"]);
497}
498
499#[test]
500fn lit_pauli_z() {
501 check(expr, "PauliZ", &expect!["Expr _id_ [0-6]: Lit: Pauli(Z)"]);
502}
503
504#[test]
505fn hole() {
506 check(expr, "_", &expect!["Expr _id_ [0-1]: Hole"]);
507}
508
509#[test]
510fn single_path() {
511 check(
512 expr,
513 "foo",
514 &expect![[r#"Expr _id_ [0-3]: Path: Path _id_ [0-3] (Ident _id_ [0-3] "foo")"#]],
515 );
516}
517
518#[test]
519fn double_path() {
520 check(
521 expr,
522 "foo.bar",
523 &expect![[
524 r#"Expr _id_ [0-7]: Path: Path _id_ [0-7] (Ident _id_ [0-3] "foo") (Ident _id_ [4-7] "bar")"#
525 ]],
526 );
527}
528
529#[test]
530fn fail() {
531 check(
532 expr,
533 r#"fail "message""#,
534 &expect![[r#"Expr _id_ [0-14]: Fail: Expr _id_ [5-14]: Lit: String("message")"#]],
535 );
536}
537
538#[test]
539fn for_in() {
540 check(
541 expr,
542 "for x in xs { x }",
543 &expect![[r#"
544 Expr _id_ [0-17]: For:
545 Pat _id_ [4-5]: Bind:
546 Ident _id_ [4-5] "x"
547 Expr _id_ [9-11]: Path: Path _id_ [9-11] (Ident _id_ [9-11] "xs")
548 Block _id_ [12-17]:
549 Stmt _id_ [14-15]: Expr: Expr _id_ [14-15]: Path: Path _id_ [14-15] (Ident _id_ [14-15] "x")"#]],
550 );
551}
552
553#[test]
554fn if_then() {
555 check(
556 expr,
557 "if c { e }",
558 &expect![[r#"
559 Expr _id_ [0-10]: If:
560 Expr _id_ [3-4]: Path: Path _id_ [3-4] (Ident _id_ [3-4] "c")
561 Block _id_ [5-10]:
562 Stmt _id_ [7-8]: Expr: Expr _id_ [7-8]: Path: Path _id_ [7-8] (Ident _id_ [7-8] "e")"#]],
563 );
564}
565
566#[test]
567fn if_else() {
568 check(
569 expr,
570 "if c { x } else { y }",
571 &expect![[r#"
572 Expr _id_ [0-21]: If:
573 Expr _id_ [3-4]: Path: Path _id_ [3-4] (Ident _id_ [3-4] "c")
574 Block _id_ [5-10]:
575 Stmt _id_ [7-8]: Expr: Expr _id_ [7-8]: Path: Path _id_ [7-8] (Ident _id_ [7-8] "x")
576 Expr _id_ [11-21]: Expr Block: Block _id_ [16-21]:
577 Stmt _id_ [18-19]: Expr: Expr _id_ [18-19]: Path: Path _id_ [18-19] (Ident _id_ [18-19] "y")"#]],
578 );
579}
580
581#[test]
582fn if_elif() {
583 check(
584 expr,
585 "if c1 { x } elif c2 { y }",
586 &expect![[r#"
587 Expr _id_ [0-25]: If:
588 Expr _id_ [3-5]: Path: Path _id_ [3-5] (Ident _id_ [3-5] "c1")
589 Block _id_ [6-11]:
590 Stmt _id_ [8-9]: Expr: Expr _id_ [8-9]: Path: Path _id_ [8-9] (Ident _id_ [8-9] "x")
591 Expr _id_ [12-25]: If:
592 Expr _id_ [17-19]: Path: Path _id_ [17-19] (Ident _id_ [17-19] "c2")
593 Block _id_ [20-25]:
594 Stmt _id_ [22-23]: Expr: Expr _id_ [22-23]: Path: Path _id_ [22-23] (Ident _id_ [22-23] "y")"#]],
595 );
596}
597
598#[test]
599fn if_elif_else() {
600 check(
601 expr,
602 "if c1 { x } elif c2 { y } else { z }",
603 &expect![[r#"
604 Expr _id_ [0-36]: If:
605 Expr _id_ [3-5]: Path: Path _id_ [3-5] (Ident _id_ [3-5] "c1")
606 Block _id_ [6-11]:
607 Stmt _id_ [8-9]: Expr: Expr _id_ [8-9]: Path: Path _id_ [8-9] (Ident _id_ [8-9] "x")
608 Expr _id_ [12-36]: If:
609 Expr _id_ [17-19]: Path: Path _id_ [17-19] (Ident _id_ [17-19] "c2")
610 Block _id_ [20-25]:
611 Stmt _id_ [22-23]: Expr: Expr _id_ [22-23]: Path: Path _id_ [22-23] (Ident _id_ [22-23] "y")
612 Expr _id_ [26-36]: Expr Block: Block _id_ [31-36]:
613 Stmt _id_ [33-34]: Expr: Expr _id_ [33-34]: Path: Path _id_ [33-34] (Ident _id_ [33-34] "z")"#]],
614 );
615}
616
617#[test]
618fn repeat_until() {
619 check(
620 expr,
621 "repeat { x } until c",
622 &expect![[r#"
623 Expr _id_ [0-20]: Repeat:
624 Block _id_ [7-12]:
625 Stmt _id_ [9-10]: Expr: Expr _id_ [9-10]: Path: Path _id_ [9-10] (Ident _id_ [9-10] "x")
626 Expr _id_ [19-20]: Path: Path _id_ [19-20] (Ident _id_ [19-20] "c")
627 <no fixup>"#]],
628 );
629}
630
631#[test]
632fn repeat_until_fixup() {
633 check(
634 expr,
635 "repeat { x } until c fixup { y }",
636 &expect![[r#"
637 Expr _id_ [0-32]: Repeat:
638 Block _id_ [7-12]:
639 Stmt _id_ [9-10]: Expr: Expr _id_ [9-10]: Path: Path _id_ [9-10] (Ident _id_ [9-10] "x")
640 Expr _id_ [19-20]: Path: Path _id_ [19-20] (Ident _id_ [19-20] "c")
641 Block _id_ [27-32]:
642 Stmt _id_ [29-30]: Expr: Expr _id_ [29-30]: Path: Path _id_ [29-30] (Ident _id_ [29-30] "y")"#]],
643 );
644}
645
646#[test]
647fn return_expr() {
648 check(
649 expr,
650 "return x",
651 &expect![[
652 r#"Expr _id_ [0-8]: Return: Expr _id_ [7-8]: Path: Path _id_ [7-8] (Ident _id_ [7-8] "x")"#
653 ]],
654 );
655}
656
657#[test]
658fn set() {
659 check(
660 expr,
661 "set x = y",
662 &expect![[r#"
663 Expr _id_ [0-9]: Assign:
664 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "x")
665 Expr _id_ [8-9]: Path: Path _id_ [8-9] (Ident _id_ [8-9] "y")"#]],
666 );
667}
668
669#[test]
670fn set_hole() {
671 check(
672 expr,
673 "set _ = 1",
674 &expect![[r#"
675 Expr _id_ [0-9]: Assign:
676 Expr _id_ [4-5]: Hole
677 Expr _id_ [8-9]: Lit: Int(1)"#]],
678 );
679}
680
681#[test]
682fn set_hole_tuple() {
683 check(
684 expr,
685 "set (x, _) = (1, 2)",
686 &expect![[r#"
687 Expr _id_ [0-19]: Assign:
688 Expr _id_ [4-10]: Tuple:
689 Expr _id_ [5-6]: Path: Path _id_ [5-6] (Ident _id_ [5-6] "x")
690 Expr _id_ [8-9]: Hole
691 Expr _id_ [13-19]: Tuple:
692 Expr _id_ [14-15]: Lit: Int(1)
693 Expr _id_ [17-18]: Lit: Int(2)"#]],
694 );
695}
696
697#[test]
698fn set_hole_tuple_nested() {
699 check(
700 expr,
701 "set (_, (x, _)) = (1, (2, 3))",
702 &expect![[r#"
703 Expr _id_ [0-29]: Assign:
704 Expr _id_ [4-15]: Tuple:
705 Expr _id_ [5-6]: Hole
706 Expr _id_ [8-14]: Tuple:
707 Expr _id_ [9-10]: Path: Path _id_ [9-10] (Ident _id_ [9-10] "x")
708 Expr _id_ [12-13]: Hole
709 Expr _id_ [18-29]: Tuple:
710 Expr _id_ [19-20]: Lit: Int(1)
711 Expr _id_ [22-28]: Tuple:
712 Expr _id_ [23-24]: Lit: Int(2)
713 Expr _id_ [26-27]: Lit: Int(3)"#]],
714 );
715}
716
717#[test]
718fn set_bitwise_and() {
719 check(
720 expr,
721 "set x &&&= y",
722 &expect![[r#"
723 Expr _id_ [0-12]: AssignOp (AndB):
724 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "x")
725 Expr _id_ [11-12]: Path: Path _id_ [11-12] (Ident _id_ [11-12] "y")"#]],
726 );
727}
728
729#[test]
730fn set_logical_and() {
731 check(
732 expr,
733 "set x and= y",
734 &expect![[r#"
735 Expr _id_ [0-12]: AssignOp (AndL):
736 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "x")
737 Expr _id_ [11-12]: Path: Path _id_ [11-12] (Ident _id_ [11-12] "y")"#]],
738 );
739}
740
741#[test]
742fn set_bitwise_or() {
743 check(
744 expr,
745 "set x |||= y",
746 &expect![[r#"
747 Expr _id_ [0-12]: AssignOp (OrB):
748 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "x")
749 Expr _id_ [11-12]: Path: Path _id_ [11-12] (Ident _id_ [11-12] "y")"#]],
750 );
751}
752
753#[test]
754fn set_exp() {
755 check(
756 expr,
757 "set x ^= y",
758 &expect![[r#"
759 Expr _id_ [0-10]: AssignOp (Exp):
760 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "x")
761 Expr _id_ [9-10]: Path: Path _id_ [9-10] (Ident _id_ [9-10] "y")"#]],
762 );
763}
764
765#[test]
766fn set_bitwise_xor() {
767 check(
768 expr,
769 "set x ^^^= y",
770 &expect![[r#"
771 Expr _id_ [0-12]: AssignOp (XorB):
772 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "x")
773 Expr _id_ [11-12]: Path: Path _id_ [11-12] (Ident _id_ [11-12] "y")"#]],
774 );
775}
776
777#[test]
778fn set_shr() {
779 check(
780 expr,
781 "set x >>>= y",
782 &expect![[r#"
783 Expr _id_ [0-12]: AssignOp (Shr):
784 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "x")
785 Expr _id_ [11-12]: Path: Path _id_ [11-12] (Ident _id_ [11-12] "y")"#]],
786 );
787}
788
789#[test]
790fn set_shl() {
791 check(
792 expr,
793 "set x <<<= y",
794 &expect![[r#"
795 Expr _id_ [0-12]: AssignOp (Shl):
796 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "x")
797 Expr _id_ [11-12]: Path: Path _id_ [11-12] (Ident _id_ [11-12] "y")"#]],
798 );
799}
800
801#[test]
802fn set_sub() {
803 check(
804 expr,
805 "set x -= y",
806 &expect![[r#"
807 Expr _id_ [0-10]: AssignOp (Sub):
808 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "x")
809 Expr _id_ [9-10]: Path: Path _id_ [9-10] (Ident _id_ [9-10] "y")"#]],
810 );
811}
812
813#[test]
814fn set_logical_or() {
815 check(
816 expr,
817 "set x or= y",
818 &expect![[r#"
819 Expr _id_ [0-11]: AssignOp (OrL):
820 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "x")
821 Expr _id_ [10-11]: Path: Path _id_ [10-11] (Ident _id_ [10-11] "y")"#]],
822 );
823}
824
825#[test]
826fn set_mod() {
827 check(
828 expr,
829 "set x %= y",
830 &expect![[r#"
831 Expr _id_ [0-10]: AssignOp (Mod):
832 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "x")
833 Expr _id_ [9-10]: Path: Path _id_ [9-10] (Ident _id_ [9-10] "y")"#]],
834 );
835}
836
837#[test]
838fn set_add() {
839 check(
840 expr,
841 "set x += y",
842 &expect![[r#"
843 Expr _id_ [0-10]: AssignOp (Add):
844 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "x")
845 Expr _id_ [9-10]: Path: Path _id_ [9-10] (Ident _id_ [9-10] "y")"#]],
846 );
847}
848
849#[test]
850fn set_div() {
851 check(
852 expr,
853 "set x /= y",
854 &expect![[r#"
855 Expr _id_ [0-10]: AssignOp (Div):
856 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "x")
857 Expr _id_ [9-10]: Path: Path _id_ [9-10] (Ident _id_ [9-10] "y")"#]],
858 );
859}
860
861#[test]
862fn set_mul() {
863 check(
864 expr,
865 "set x *= y",
866 &expect![[r#"
867 Expr _id_ [0-10]: AssignOp (Mul):
868 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "x")
869 Expr _id_ [9-10]: Path: Path _id_ [9-10] (Ident _id_ [9-10] "y")"#]],
870 );
871}
872
873#[test]
874fn set_with_update() {
875 check(
876 expr,
877 "set x w/= i <- y",
878 &expect![[r#"
879 Expr _id_ [0-16]: AssignUpdate:
880 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "x")
881 Expr _id_ [10-11]: Path: Path _id_ [10-11] (Ident _id_ [10-11] "i")
882 Expr _id_ [15-16]: Path: Path _id_ [15-16] (Ident _id_ [15-16] "y")"#]],
883 );
884}
885
886#[test]
887fn while_expr() {
888 check(
889 expr,
890 "while c { x }",
891 &expect![[r#"
892 Expr _id_ [0-13]: While:
893 Expr _id_ [6-7]: Path: Path _id_ [6-7] (Ident _id_ [6-7] "c")
894 Block _id_ [8-13]:
895 Stmt _id_ [10-11]: Expr: Expr _id_ [10-11]: Path: Path _id_ [10-11] (Ident _id_ [10-11] "x")"#]],
896 );
897}
898
899#[test]
900fn within_apply() {
901 check(
902 expr,
903 "within { x } apply { y }",
904 &expect![[r#"
905 Expr _id_ [0-24]: Conjugate:
906 Block _id_ [7-12]:
907 Stmt _id_ [9-10]: Expr: Expr _id_ [9-10]: Path: Path _id_ [9-10] (Ident _id_ [9-10] "x")
908 Block _id_ [19-24]:
909 Stmt _id_ [21-22]: Expr: Expr _id_ [21-22]: Path: Path _id_ [21-22] (Ident _id_ [21-22] "y")"#]],
910 );
911}
912
913#[test]
914fn unit() {
915 check(expr, "()", &expect!["Expr _id_ [0-2]: Unit"]);
916}
917
918#[test]
919fn paren() {
920 check(
921 expr,
922 "(x)",
923 &expect![[
924 r#"Expr _id_ [0-3]: Paren: Expr _id_ [1-2]: Path: Path _id_ [1-2] (Ident _id_ [1-2] "x")"#
925 ]],
926 );
927}
928
929#[test]
930fn singleton_tuple() {
931 check(
932 expr,
933 "(x,)",
934 &expect![[r#"
935 Expr _id_ [0-4]: Tuple:
936 Expr _id_ [1-2]: Path: Path _id_ [1-2] (Ident _id_ [1-2] "x")"#]],
937 );
938}
939
940#[test]
941fn pair() {
942 check(
943 expr,
944 "(x, y)",
945 &expect![[r#"
946 Expr _id_ [0-6]: Tuple:
947 Expr _id_ [1-2]: Path: Path _id_ [1-2] (Ident _id_ [1-2] "x")
948 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "y")"#]],
949 );
950}
951
952#[test]
953fn array_empty() {
954 check(expr, "[]", &expect!["Expr _id_ [0-2]: Array:"]);
955}
956
957#[test]
958fn array_single() {
959 check(
960 expr,
961 "[x]",
962 &expect![[r#"
963 Expr _id_ [0-3]: Array:
964 Expr _id_ [1-2]: Path: Path _id_ [1-2] (Ident _id_ [1-2] "x")"#]],
965 );
966}
967
968#[test]
969fn array_pair() {
970 check(
971 expr,
972 "[x, y]",
973 &expect![[r#"
974 Expr _id_ [0-6]: Array:
975 Expr _id_ [1-2]: Path: Path _id_ [1-2] (Ident _id_ [1-2] "x")
976 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "y")"#]],
977 );
978}
979
980#[test]
981fn array_repeat() {
982 check(
983 expr,
984 "[0, size = 3]",
985 &expect![[r#"
986 Expr _id_ [0-13]: ArrayRepeat:
987 Expr _id_ [1-2]: Lit: Int(0)
988 Expr _id_ [11-12]: Lit: Int(3)"#]],
989 );
990}
991
992#[test]
993fn array_repeat_complex() {
994 check(
995 expr,
996 "[Foo(), size = Count() + 1]",
997 &expect![[r#"
998 Expr _id_ [0-27]: ArrayRepeat:
999 Expr _id_ [1-6]: Call:
1000 Expr _id_ [1-4]: Path: Path _id_ [1-4] (Ident _id_ [1-4] "Foo")
1001 Expr _id_ [4-6]: Unit
1002 Expr _id_ [15-26]: BinOp (Add):
1003 Expr _id_ [15-22]: Call:
1004 Expr _id_ [15-20]: Path: Path _id_ [15-20] (Ident _id_ [15-20] "Count")
1005 Expr _id_ [20-22]: Unit
1006 Expr _id_ [25-26]: Lit: Int(1)"#]],
1007 );
1008}
1009
1010#[test]
1011fn array_size_last_item() {
1012 check(
1013 expr,
1014 "[foo, size]",
1015 &expect![[r#"
1016 Expr _id_ [0-11]: Array:
1017 Expr _id_ [1-4]: Path: Path _id_ [1-4] (Ident _id_ [1-4] "foo")
1018 Expr _id_ [6-10]: Path: Path _id_ [6-10] (Ident _id_ [6-10] "size")"#]],
1019 );
1020}
1021
1022#[test]
1023fn array_size_middle_item() {
1024 check(
1025 expr,
1026 "[foo, size, bar]",
1027 &expect![[r#"
1028 Expr _id_ [0-16]: Array:
1029 Expr _id_ [1-4]: Path: Path _id_ [1-4] (Ident _id_ [1-4] "foo")
1030 Expr _id_ [6-10]: Path: Path _id_ [6-10] (Ident _id_ [6-10] "size")
1031 Expr _id_ [12-15]: Path: Path _id_ [12-15] (Ident _id_ [12-15] "bar")"#]],
1032 );
1033}
1034
1035#[test]
1036fn array_repeat_no_items() {
1037 check(
1038 expr,
1039 "[size = 3]",
1040 &expect![[r#"
1041 Error(
1042 Token(
1043 Close(
1044 Bracket,
1045 ),
1046 Eq,
1047 Span {
1048 lo: 6,
1049 hi: 7,
1050 },
1051 ),
1052 )
1053 "#]],
1054 );
1055}
1056
1057#[test]
1058fn array_repeat_two_items() {
1059 check(
1060 expr,
1061 "[1, 2, size = 3]",
1062 &expect![[r#"
1063 Error(
1064 Token(
1065 Close(
1066 Bracket,
1067 ),
1068 Eq,
1069 Span {
1070 lo: 12,
1071 hi: 13,
1072 },
1073 ),
1074 )
1075 "#]],
1076 );
1077}
1078
1079#[test]
1080fn array_concat() {
1081 check(
1082 expr,
1083 "[1, 2] + [3, 4]",
1084 &expect![[r#"
1085 Expr _id_ [0-15]: BinOp (Add):
1086 Expr _id_ [0-6]: Array:
1087 Expr _id_ [1-2]: Lit: Int(1)
1088 Expr _id_ [4-5]: Lit: Int(2)
1089 Expr _id_ [9-15]: Array:
1090 Expr _id_ [10-11]: Lit: Int(3)
1091 Expr _id_ [13-14]: Lit: Int(4)"#]],
1092 );
1093}
1094
1095#[test]
1096fn and_op() {
1097 check(
1098 expr,
1099 "x and y",
1100 &expect![[r#"
1101 Expr _id_ [0-7]: BinOp (AndL):
1102 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "x")
1103 Expr _id_ [6-7]: Path: Path _id_ [6-7] (Ident _id_ [6-7] "y")"#]],
1104 );
1105}
1106
1107#[test]
1108fn or_op() {
1109 check(
1110 expr,
1111 "x or y",
1112 &expect![[r#"
1113 Expr _id_ [0-6]: BinOp (OrL):
1114 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "x")
1115 Expr _id_ [5-6]: Path: Path _id_ [5-6] (Ident _id_ [5-6] "y")"#]],
1116 );
1117}
1118
1119#[test]
1120fn and_or_ops() {
1121 check(
1122 expr,
1123 "x or y and z",
1124 &expect![[r#"
1125 Expr _id_ [0-12]: BinOp (OrL):
1126 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "x")
1127 Expr _id_ [5-12]: BinOp (AndL):
1128 Expr _id_ [5-6]: Path: Path _id_ [5-6] (Ident _id_ [5-6] "y")
1129 Expr _id_ [11-12]: Path: Path _id_ [11-12] (Ident _id_ [11-12] "z")"#]],
1130 );
1131}
1132
1133#[test]
1134fn eq_op() {
1135 check(
1136 expr,
1137 "x == y",
1138 &expect![[r#"
1139 Expr _id_ [0-6]: BinOp (Eq):
1140 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "x")
1141 Expr _id_ [5-6]: Path: Path _id_ [5-6] (Ident _id_ [5-6] "y")"#]],
1142 );
1143}
1144
1145#[test]
1146fn ne_op() {
1147 check(
1148 expr,
1149 "x != y",
1150 &expect![[r#"
1151 Expr _id_ [0-6]: BinOp (Neq):
1152 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "x")
1153 Expr _id_ [5-6]: Path: Path _id_ [5-6] (Ident _id_ [5-6] "y")"#]],
1154 );
1155}
1156
1157#[test]
1158fn gt_op() {
1159 check(
1160 expr,
1161 "x > y",
1162 &expect![[r#"
1163 Expr _id_ [0-5]: BinOp (Gt):
1164 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "x")
1165 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "y")"#]],
1166 );
1167}
1168
1169#[test]
1170fn gte_op() {
1171 check(
1172 expr,
1173 "x >= y",
1174 &expect![[r#"
1175 Expr _id_ [0-6]: BinOp (Gte):
1176 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "x")
1177 Expr _id_ [5-6]: Path: Path _id_ [5-6] (Ident _id_ [5-6] "y")"#]],
1178 );
1179}
1180
1181#[test]
1182fn lt_op() {
1183 check(
1184 expr,
1185 "x < y",
1186 &expect![[r#"
1187 Expr _id_ [0-5]: BinOp (Lt):
1188 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "x")
1189 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "y")"#]],
1190 );
1191}
1192
1193#[test]
1194fn lte_op() {
1195 check(
1196 expr,
1197 "x <= y",
1198 &expect![[r#"
1199 Expr _id_ [0-6]: BinOp (Lte):
1200 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "x")
1201 Expr _id_ [5-6]: Path: Path _id_ [5-6] (Ident _id_ [5-6] "y")"#]],
1202 );
1203}
1204
1205#[test]
1206fn bitwise_and_op() {
1207 check(
1208 expr,
1209 "x &&& y",
1210 &expect![[r#"
1211 Expr _id_ [0-7]: BinOp (AndB):
1212 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "x")
1213 Expr _id_ [6-7]: Path: Path _id_ [6-7] (Ident _id_ [6-7] "y")"#]],
1214 );
1215}
1216
1217#[test]
1218fn bitwise_or_op() {
1219 check(
1220 expr,
1221 "x ||| y",
1222 &expect![[r#"
1223 Expr _id_ [0-7]: BinOp (OrB):
1224 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "x")
1225 Expr _id_ [6-7]: Path: Path _id_ [6-7] (Ident _id_ [6-7] "y")"#]],
1226 );
1227}
1228
1229#[test]
1230fn bitwise_and_or_op() {
1231 check(
1232 expr,
1233 "x ||| y &&& z",
1234 &expect![[r#"
1235 Expr _id_ [0-13]: BinOp (OrB):
1236 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "x")
1237 Expr _id_ [6-13]: BinOp (AndB):
1238 Expr _id_ [6-7]: Path: Path _id_ [6-7] (Ident _id_ [6-7] "y")
1239 Expr _id_ [12-13]: Path: Path _id_ [12-13] (Ident _id_ [12-13] "z")"#]],
1240 );
1241}
1242
1243#[test]
1244fn bitwise_xor_op() {
1245 check(
1246 expr,
1247 "x ^^^ y",
1248 &expect![[r#"
1249 Expr _id_ [0-7]: BinOp (XorB):
1250 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "x")
1251 Expr _id_ [6-7]: Path: Path _id_ [6-7] (Ident _id_ [6-7] "y")"#]],
1252 );
1253}
1254
1255#[test]
1256fn bitwise_or_xor_ops() {
1257 check(
1258 expr,
1259 "x ||| y ^^^ z",
1260 &expect![[r#"
1261 Expr _id_ [0-13]: BinOp (OrB):
1262 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "x")
1263 Expr _id_ [6-13]: BinOp (XorB):
1264 Expr _id_ [6-7]: Path: Path _id_ [6-7] (Ident _id_ [6-7] "y")
1265 Expr _id_ [12-13]: Path: Path _id_ [12-13] (Ident _id_ [12-13] "z")"#]],
1266 );
1267}
1268
1269#[test]
1270fn shl_op() {
1271 check(
1272 expr,
1273 "x <<< y",
1274 &expect![[r#"
1275 Expr _id_ [0-7]: BinOp (Shl):
1276 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "x")
1277 Expr _id_ [6-7]: Path: Path _id_ [6-7] (Ident _id_ [6-7] "y")"#]],
1278 );
1279}
1280
1281#[test]
1282fn shr_op() {
1283 check(
1284 expr,
1285 "x >>> y",
1286 &expect![[r#"
1287 Expr _id_ [0-7]: BinOp (Shr):
1288 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "x")
1289 Expr _id_ [6-7]: Path: Path _id_ [6-7] (Ident _id_ [6-7] "y")"#]],
1290 );
1291}
1292
1293#[test]
1294fn add_op() {
1295 check(
1296 expr,
1297 "x + y",
1298 &expect![[r#"
1299 Expr _id_ [0-5]: BinOp (Add):
1300 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "x")
1301 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "y")"#]],
1302 );
1303}
1304
1305#[test]
1306fn add_left_assoc() {
1307 check(
1308 expr,
1309 "x + y + z",
1310 &expect![[r#"
1311 Expr _id_ [0-9]: BinOp (Add):
1312 Expr _id_ [0-5]: BinOp (Add):
1313 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "x")
1314 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "y")
1315 Expr _id_ [8-9]: Path: Path _id_ [8-9] (Ident _id_ [8-9] "z")"#]],
1316 );
1317}
1318
1319#[test]
1320fn sub_op() {
1321 check(
1322 expr,
1323 "x - y",
1324 &expect![[r#"
1325 Expr _id_ [0-5]: BinOp (Sub):
1326 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "x")
1327 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "y")"#]],
1328 );
1329}
1330
1331#[test]
1332fn mul_op() {
1333 check(
1334 expr,
1335 "x * y",
1336 &expect![[r#"
1337 Expr _id_ [0-5]: BinOp (Mul):
1338 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "x")
1339 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "y")"#]],
1340 );
1341}
1342
1343#[test]
1344fn add_mul_ops() {
1345 check(
1346 expr,
1347 "x + y * z",
1348 &expect![[r#"
1349 Expr _id_ [0-9]: BinOp (Add):
1350 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "x")
1351 Expr _id_ [4-9]: BinOp (Mul):
1352 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "y")
1353 Expr _id_ [8-9]: Path: Path _id_ [8-9] (Ident _id_ [8-9] "z")"#]],
1354 );
1355}
1356
1357#[test]
1358fn div_op() {
1359 check(
1360 expr,
1361 "x / y",
1362 &expect![[r#"
1363 Expr _id_ [0-5]: BinOp (Div):
1364 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "x")
1365 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "y")"#]],
1366 );
1367}
1368
1369#[test]
1370fn mod_op() {
1371 check(
1372 expr,
1373 "x % y",
1374 &expect![[r#"
1375 Expr _id_ [0-5]: BinOp (Mod):
1376 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "x")
1377 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "y")"#]],
1378 );
1379}
1380
1381#[test]
1382fn two_plus_two_is_four() {
1383 check(
1384 expr,
1385 "2 + 2 == 4",
1386 &expect![[r#"
1387 Expr _id_ [0-10]: BinOp (Eq):
1388 Expr _id_ [0-5]: BinOp (Add):
1389 Expr _id_ [0-1]: Lit: Int(2)
1390 Expr _id_ [4-5]: Lit: Int(2)
1391 Expr _id_ [9-10]: Lit: Int(4)"#]],
1392 );
1393}
1394
1395#[test]
1396fn exp_op() {
1397 check(
1398 expr,
1399 "x ^ y",
1400 &expect![[r#"
1401 Expr _id_ [0-5]: BinOp (Exp):
1402 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "x")
1403 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "y")"#]],
1404 );
1405}
1406
1407#[test]
1408fn exp_right_assoc() {
1409 check(
1410 expr,
1411 "2 ^ 3 ^ 4",
1412 &expect![[r#"
1413 Expr _id_ [0-9]: BinOp (Exp):
1414 Expr _id_ [0-1]: Lit: Int(2)
1415 Expr _id_ [4-9]: BinOp (Exp):
1416 Expr _id_ [4-5]: Lit: Int(3)
1417 Expr _id_ [8-9]: Lit: Int(4)"#]],
1418 );
1419}
1420
1421#[test]
1422fn negate_exp() {
1423 check(
1424 expr,
1425 "-2^3",
1426 &expect![[r#"
1427 Expr _id_ [0-4]: UnOp (Neg):
1428 Expr _id_ [1-4]: BinOp (Exp):
1429 Expr _id_ [1-2]: Lit: Int(2)
1430 Expr _id_ [3-4]: Lit: Int(3)"#]],
1431 );
1432}
1433
1434#[test]
1435fn unwrap_op() {
1436 check(
1437 expr,
1438 "x!",
1439 &expect![[r#"
1440 Expr _id_ [0-2]: UnOp (Unwrap):
1441 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "x")"#]],
1442 );
1443}
1444
1445#[test]
1446fn logical_not_op() {
1447 check(
1448 expr,
1449 "not x",
1450 &expect![[r#"
1451 Expr _id_ [0-5]: UnOp (NotL):
1452 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "x")"#]],
1453 );
1454}
1455
1456#[test]
1457fn bitwise_not_op() {
1458 check(
1459 expr,
1460 "~~~x",
1461 &expect![[r#"
1462 Expr _id_ [0-4]: UnOp (NotB):
1463 Expr _id_ [3-4]: Path: Path _id_ [3-4] (Ident _id_ [3-4] "x")"#]],
1464 );
1465}
1466
1467#[test]
1468fn pos_op() {
1469 check(
1470 expr,
1471 "+x",
1472 &expect![[r#"
1473 Expr _id_ [0-2]: UnOp (Pos):
1474 Expr _id_ [1-2]: Path: Path _id_ [1-2] (Ident _id_ [1-2] "x")"#]],
1475 );
1476}
1477
1478#[test]
1479fn neg_op() {
1480 check(
1481 expr,
1482 "-x",
1483 &expect![[r#"
1484 Expr _id_ [0-2]: UnOp (Neg):
1485 Expr _id_ [1-2]: Path: Path _id_ [1-2] (Ident _id_ [1-2] "x")"#]],
1486 );
1487}
1488
1489#[test]
1490fn neg_minus_ops() {
1491 check(
1492 expr,
1493 "-x - y",
1494 &expect![[r#"
1495 Expr _id_ [0-6]: BinOp (Sub):
1496 Expr _id_ [0-2]: UnOp (Neg):
1497 Expr _id_ [1-2]: Path: Path _id_ [1-2] (Ident _id_ [1-2] "x")
1498 Expr _id_ [5-6]: Path: Path _id_ [5-6] (Ident _id_ [5-6] "y")"#]],
1499 );
1500}
1501
1502#[test]
1503fn adjoint_op() {
1504 check(
1505 expr,
1506 "Adjoint x",
1507 &expect![[r#"
1508 Expr _id_ [0-9]: UnOp (Functor Adj):
1509 Expr _id_ [8-9]: Path: Path _id_ [8-9] (Ident _id_ [8-9] "x")"#]],
1510 );
1511}
1512
1513#[test]
1514fn adjoint_call_ops() {
1515 check(
1516 expr,
1517 "Adjoint X(q)",
1518 &expect![[r#"
1519 Expr _id_ [0-12]: Call:
1520 Expr _id_ [0-9]: UnOp (Functor Adj):
1521 Expr _id_ [8-9]: Path: Path _id_ [8-9] (Ident _id_ [8-9] "X")
1522 Expr _id_ [9-12]: Paren: Expr _id_ [10-11]: Path: Path _id_ [10-11] (Ident _id_ [10-11] "q")"#]],
1523 );
1524}
1525
1526#[test]
1527fn adjoint_index_call_ops() {
1528 check(
1529 expr,
1530 "Adjoint ops[i](q)",
1531 &expect![[r#"
1532 Expr _id_ [0-17]: Call:
1533 Expr _id_ [0-14]: UnOp (Functor Adj):
1534 Expr _id_ [8-14]: Index:
1535 Expr _id_ [8-11]: Path: Path _id_ [8-11] (Ident _id_ [8-11] "ops")
1536 Expr _id_ [12-13]: Path: Path _id_ [12-13] (Ident _id_ [12-13] "i")
1537 Expr _id_ [14-17]: Paren: Expr _id_ [15-16]: Path: Path _id_ [15-16] (Ident _id_ [15-16] "q")"#]],
1538 );
1539}
1540
1541#[test]
1542fn controlled_op() {
1543 check(
1544 expr,
1545 "Controlled x",
1546 &expect![[r#"
1547 Expr _id_ [0-12]: UnOp (Functor Ctl):
1548 Expr _id_ [11-12]: Path: Path _id_ [11-12] (Ident _id_ [11-12] "x")"#]],
1549 );
1550}
1551
1552#[test]
1553fn controlled_call_ops() {
1554 check(
1555 expr,
1556 "Controlled X([q1], q2)",
1557 &expect![[r#"
1558 Expr _id_ [0-22]: Call:
1559 Expr _id_ [0-12]: UnOp (Functor Ctl):
1560 Expr _id_ [11-12]: Path: Path _id_ [11-12] (Ident _id_ [11-12] "X")
1561 Expr _id_ [12-22]: Tuple:
1562 Expr _id_ [13-17]: Array:
1563 Expr _id_ [14-16]: Path: Path _id_ [14-16] (Ident _id_ [14-16] "q1")
1564 Expr _id_ [19-21]: Path: Path _id_ [19-21] (Ident _id_ [19-21] "q2")"#]],
1565 );
1566}
1567
1568#[test]
1569fn controlled_index_call_ops() {
1570 check(
1571 expr,
1572 "Controlled ops[i]([q1], q2)",
1573 &expect![[r#"
1574 Expr _id_ [0-27]: Call:
1575 Expr _id_ [0-17]: UnOp (Functor Ctl):
1576 Expr _id_ [11-17]: Index:
1577 Expr _id_ [11-14]: Path: Path _id_ [11-14] (Ident _id_ [11-14] "ops")
1578 Expr _id_ [15-16]: Path: Path _id_ [15-16] (Ident _id_ [15-16] "i")
1579 Expr _id_ [17-27]: Tuple:
1580 Expr _id_ [18-22]: Array:
1581 Expr _id_ [19-21]: Path: Path _id_ [19-21] (Ident _id_ [19-21] "q1")
1582 Expr _id_ [24-26]: Path: Path _id_ [24-26] (Ident _id_ [24-26] "q2")"#]],
1583 );
1584}
1585
1586#[test]
1587fn update_op() {
1588 check(
1589 expr,
1590 "x w/ i <- v",
1591 &expect![[r#"
1592 Expr _id_ [0-11]: TernOp (Update):
1593 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "x")
1594 Expr _id_ [5-6]: Path: Path _id_ [5-6] (Ident _id_ [5-6] "i")
1595 Expr _id_ [10-11]: Path: Path _id_ [10-11] (Ident _id_ [10-11] "v")"#]],
1596 );
1597}
1598
1599#[test]
1600fn update_op_left_assoc() {
1601 check(
1602 expr,
1603 "x w/ i1 <- v1 w/ i2 <- v2",
1604 &expect![[r#"
1605 Expr _id_ [0-25]: TernOp (Update):
1606 Expr _id_ [0-13]: TernOp (Update):
1607 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "x")
1608 Expr _id_ [5-7]: Path: Path _id_ [5-7] (Ident _id_ [5-7] "i1")
1609 Expr _id_ [11-13]: Path: Path _id_ [11-13] (Ident _id_ [11-13] "v1")
1610 Expr _id_ [17-19]: Path: Path _id_ [17-19] (Ident _id_ [17-19] "i2")
1611 Expr _id_ [23-25]: Path: Path _id_ [23-25] (Ident _id_ [23-25] "v2")"#]],
1612 );
1613}
1614
1615#[test]
1616fn cond_op() {
1617 check(
1618 expr,
1619 "c ? a | b",
1620 &expect![[r#"
1621 Expr _id_ [0-9]: TernOp (Cond):
1622 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "c")
1623 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "a")
1624 Expr _id_ [8-9]: Path: Path _id_ [8-9] (Ident _id_ [8-9] "b")"#]],
1625 );
1626}
1627
1628#[test]
1629fn cond_op_right_assoc() {
1630 check(
1631 expr,
1632 "c1 ? a | c2 ? b | c",
1633 &expect![[r#"
1634 Expr _id_ [0-19]: TernOp (Cond):
1635 Expr _id_ [0-2]: Path: Path _id_ [0-2] (Ident _id_ [0-2] "c1")
1636 Expr _id_ [5-6]: Path: Path _id_ [5-6] (Ident _id_ [5-6] "a")
1637 Expr _id_ [9-19]: TernOp (Cond):
1638 Expr _id_ [9-11]: Path: Path _id_ [9-11] (Ident _id_ [9-11] "c2")
1639 Expr _id_ [14-15]: Path: Path _id_ [14-15] (Ident _id_ [14-15] "b")
1640 Expr _id_ [18-19]: Path: Path _id_ [18-19] (Ident _id_ [18-19] "c")"#]],
1641 );
1642}
1643
1644#[test]
1645fn field_op() {
1646 check(
1647 expr,
1648 "x::foo",
1649 &expect![[r#"
1650 Expr _id_ [0-6]: Field:
1651 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "x")
1652 Ident _id_ [3-6] "foo""#]],
1653 );
1654}
1655
1656#[test]
1657fn index_op() {
1658 check(
1659 expr,
1660 "x[i]",
1661 &expect![[r#"
1662 Expr _id_ [0-4]: Index:
1663 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "x")
1664 Expr _id_ [2-3]: Path: Path _id_ [2-3] (Ident _id_ [2-3] "i")"#]],
1665 );
1666}
1667
1668#[test]
1669fn call_op_unit() {
1670 check(
1671 expr,
1672 "Foo()",
1673 &expect![[r#"
1674 Expr _id_ [0-5]: Call:
1675 Expr _id_ [0-3]: Path: Path _id_ [0-3] (Ident _id_ [0-3] "Foo")
1676 Expr _id_ [3-5]: Unit"#]],
1677 );
1678}
1679
1680#[test]
1681fn call_op_one() {
1682 check(
1683 expr,
1684 "Foo(x)",
1685 &expect![[r#"
1686 Expr _id_ [0-6]: Call:
1687 Expr _id_ [0-3]: Path: Path _id_ [0-3] (Ident _id_ [0-3] "Foo")
1688 Expr _id_ [3-6]: Paren: Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "x")"#]],
1689 );
1690}
1691
1692#[test]
1693fn call_op_singleton_tuple() {
1694 check(
1695 expr,
1696 "Foo(x,)",
1697 &expect![[r#"
1698 Expr _id_ [0-7]: Call:
1699 Expr _id_ [0-3]: Path: Path _id_ [0-3] (Ident _id_ [0-3] "Foo")
1700 Expr _id_ [3-7]: Tuple:
1701 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "x")"#]],
1702 );
1703}
1704
1705#[test]
1706fn call_op_pair() {
1707 check(
1708 expr,
1709 "Foo(x, y)",
1710 &expect![[r#"
1711 Expr _id_ [0-9]: Call:
1712 Expr _id_ [0-3]: Path: Path _id_ [0-3] (Ident _id_ [0-3] "Foo")
1713 Expr _id_ [3-9]: Tuple:
1714 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "x")
1715 Expr _id_ [7-8]: Path: Path _id_ [7-8] (Ident _id_ [7-8] "y")"#]],
1716 );
1717}
1718
1719#[test]
1720fn call_with_array() {
1721 check(
1722 expr,
1723 "f([1, 2])",
1724 &expect![[r#"
1725 Expr _id_ [0-9]: Call:
1726 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "f")
1727 Expr _id_ [1-9]: Paren: Expr _id_ [2-8]: Array:
1728 Expr _id_ [3-4]: Lit: Int(1)
1729 Expr _id_ [6-7]: Lit: Int(2)"#]],
1730 );
1731}
1732
1733#[test]
1734fn call_partial_app() {
1735 check(
1736 expr,
1737 "Foo(1, _, 3)",
1738 &expect![[r#"
1739 Expr _id_ [0-12]: Call:
1740 Expr _id_ [0-3]: Path: Path _id_ [0-3] (Ident _id_ [0-3] "Foo")
1741 Expr _id_ [3-12]: Tuple:
1742 Expr _id_ [4-5]: Lit: Int(1)
1743 Expr _id_ [7-8]: Hole
1744 Expr _id_ [10-11]: Lit: Int(3)"#]],
1745 );
1746}
1747
1748#[test]
1749fn call_partial_app_nested() {
1750 check(
1751 expr,
1752 "Foo(1, _, (_, 4))",
1753 &expect![[r#"
1754 Expr _id_ [0-17]: Call:
1755 Expr _id_ [0-3]: Path: Path _id_ [0-3] (Ident _id_ [0-3] "Foo")
1756 Expr _id_ [3-17]: Tuple:
1757 Expr _id_ [4-5]: Lit: Int(1)
1758 Expr _id_ [7-8]: Hole
1759 Expr _id_ [10-16]: Tuple:
1760 Expr _id_ [11-12]: Hole
1761 Expr _id_ [14-15]: Lit: Int(4)"#]],
1762 );
1763}
1764
1765#[test]
1766fn call_index_ops() {
1767 check(
1768 expr,
1769 "f()[i]",
1770 &expect![[r#"
1771 Expr _id_ [0-6]: Index:
1772 Expr _id_ [0-3]: Call:
1773 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "f")
1774 Expr _id_ [1-3]: Unit
1775 Expr _id_ [4-5]: Path: Path _id_ [4-5] (Ident _id_ [4-5] "i")"#]],
1776 );
1777}
1778
1779#[test]
1780fn index_call_ops() {
1781 check(
1782 expr,
1783 "fs[i]()",
1784 &expect![[r#"
1785 Expr _id_ [0-7]: Call:
1786 Expr _id_ [0-5]: Index:
1787 Expr _id_ [0-2]: Path: Path _id_ [0-2] (Ident _id_ [0-2] "fs")
1788 Expr _id_ [3-4]: Path: Path _id_ [3-4] (Ident _id_ [3-4] "i")
1789 Expr _id_ [5-7]: Unit"#]],
1790 );
1791}
1792
1793#[test]
1794fn range_op() {
1795 check(
1796 expr,
1797 "x..y",
1798 &expect![[r#"
1799 Expr _id_ [0-4]: Range:
1800 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "x")
1801 <no step>
1802 Expr _id_ [3-4]: Path: Path _id_ [3-4] (Ident _id_ [3-4] "y")"#]],
1803 );
1804}
1805
1806#[test]
1807fn range_op_with_step() {
1808 check(
1809 expr,
1810 "x..y..z",
1811 &expect![[r#"
1812 Expr _id_ [0-7]: Range:
1813 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "x")
1814 Expr _id_ [3-4]: Path: Path _id_ [3-4] (Ident _id_ [3-4] "y")
1815 Expr _id_ [6-7]: Path: Path _id_ [6-7] (Ident _id_ [6-7] "z")"#]],
1816 );
1817}
1818
1819#[test]
1820fn range_complex_stop() {
1821 check(
1822 expr,
1823 "0..Length(xs) - 1",
1824 &expect![[r#"
1825 Expr _id_ [0-17]: Range:
1826 Expr _id_ [0-1]: Lit: Int(0)
1827 <no step>
1828 Expr _id_ [3-17]: BinOp (Sub):
1829 Expr _id_ [3-13]: Call:
1830 Expr _id_ [3-9]: Path: Path _id_ [3-9] (Ident _id_ [3-9] "Length")
1831 Expr _id_ [9-13]: Paren: Expr _id_ [10-12]: Path: Path _id_ [10-12] (Ident _id_ [10-12] "xs")
1832 Expr _id_ [16-17]: Lit: Int(1)"#]],
1833 );
1834}
1835
1836#[test]
1837fn range_complex_start() {
1838 check(
1839 expr,
1840 "i + 1..n",
1841 &expect![[r#"
1842 Expr _id_ [0-8]: Range:
1843 Expr _id_ [0-5]: BinOp (Add):
1844 Expr _id_ [0-1]: Path: Path _id_ [0-1] (Ident _id_ [0-1] "i")
1845 Expr _id_ [4-5]: Lit: Int(1)
1846 <no step>
1847 Expr _id_ [7-8]: Path: Path _id_ [7-8] (Ident _id_ [7-8] "n")"#]],
1848 );
1849}
1850
1851#[test]
1852fn range_complex_step() {
1853 check(
1854 expr,
1855 "0..s + 1..n",
1856 &expect![[r#"
1857 Expr _id_ [0-11]: Range:
1858 Expr _id_ [0-1]: Lit: Int(0)
1859 Expr _id_ [3-8]: BinOp (Add):
1860 Expr _id_ [3-4]: Path: Path _id_ [3-4] (Ident _id_ [3-4] "s")
1861 Expr _id_ [7-8]: Lit: Int(1)
1862 Expr _id_ [10-11]: Path: Path _id_ [10-11] (Ident _id_ [10-11] "n")"#]],
1863 );
1864}
1865
1866#[test]
1867fn range_start_open() {
1868 check(
1869 expr,
1870 "2...",
1871 &expect![[r#"
1872 Expr _id_ [0-4]: Range:
1873 Expr _id_ [0-1]: Lit: Int(2)
1874 <no step>
1875 <no end>"#]],
1876 );
1877}
1878
1879#[test]
1880fn range_start_step_open() {
1881 check(
1882 expr,
1883 "3..2...",
1884 &expect![[r#"
1885 Expr _id_ [0-7]: Range:
1886 Expr _id_ [0-1]: Lit: Int(3)
1887 Expr _id_ [3-4]: Lit: Int(2)
1888 <no end>"#]],
1889 );
1890}
1891
1892#[test]
1893fn range_open_stop() {
1894 check(
1895 expr,
1896 "...2",
1897 &expect![[r#"
1898 Expr _id_ [0-4]: Range:
1899 <no start>
1900 <no step>
1901 Expr _id_ [3-4]: Lit: Int(2)"#]],
1902 );
1903}
1904
1905#[test]
1906fn range_open_step_stop() {
1907 check(
1908 expr,
1909 "...2..3",
1910 &expect![[r#"
1911 Expr _id_ [0-7]: Range:
1912 <no start>
1913 Expr _id_ [3-4]: Lit: Int(2)
1914 Expr _id_ [6-7]: Lit: Int(3)"#]],
1915 );
1916}
1917
1918#[test]
1919fn range_open_step_open() {
1920 check(
1921 expr,
1922 "...2...",
1923 &expect![[r#"
1924 Expr _id_ [0-7]: Range:
1925 <no start>
1926 Expr _id_ [3-4]: Lit: Int(2)
1927 <no end>"#]],
1928 );
1929}
1930
1931#[test]
1932fn function_lambda() {
1933 check(
1934 expr,
1935 "x -> x + 1",
1936 &expect![[r#"
1937 Expr _id_ [0-10]: Lambda (Function):
1938 Pat _id_ [0-1]: Bind:
1939 Ident _id_ [0-1] "x"
1940 Expr _id_ [5-10]: BinOp (Add):
1941 Expr _id_ [5-6]: Path: Path _id_ [5-6] (Ident _id_ [5-6] "x")
1942 Expr _id_ [9-10]: Lit: Int(1)"#]],
1943 );
1944}
1945
1946#[test]
1947fn operation_lambda() {
1948 check(
1949 expr,
1950 "q => X(q)",
1951 &expect![[r#"
1952 Expr _id_ [0-9]: Lambda (Operation):
1953 Pat _id_ [0-1]: Bind:
1954 Ident _id_ [0-1] "q"
1955 Expr _id_ [5-9]: Call:
1956 Expr _id_ [5-6]: Path: Path _id_ [5-6] (Ident _id_ [5-6] "X")
1957 Expr _id_ [6-9]: Paren: Expr _id_ [7-8]: Path: Path _id_ [7-8] (Ident _id_ [7-8] "q")"#]],
1958 );
1959}
1960
1961#[test]
1962fn lambda_tuple_input() {
1963 check(
1964 expr,
1965 "(x, y) -> x + y",
1966 &expect![[r#"
1967 Expr _id_ [0-15]: Lambda (Function):
1968 Pat _id_ [0-6]: Tuple:
1969 Pat _id_ [1-2]: Bind:
1970 Ident _id_ [1-2] "x"
1971 Pat _id_ [4-5]: Bind:
1972 Ident _id_ [4-5] "y"
1973 Expr _id_ [10-15]: BinOp (Add):
1974 Expr _id_ [10-11]: Path: Path _id_ [10-11] (Ident _id_ [10-11] "x")
1975 Expr _id_ [14-15]: Path: Path _id_ [14-15] (Ident _id_ [14-15] "y")"#]],
1976 );
1977}
1978
1979#[test]
1980fn lambda_invalid_input() {
1981 check(
1982 expr,
1983 "x + 1 -> x",
1984 &expect![[r#"
1985 Error(
1986 Convert(
1987 "pattern",
1988 "expression",
1989 Span {
1990 lo: 0,
1991 hi: 5,
1992 },
1993 ),
1994 )
1995 "#]],
1996 );
1997}
1998
1999#[test]
2000fn lambda_invalid_tuple_input() {
2001 check(
2002 expr,
2003 "(x, y + 1) -> x + y",
2004 &expect![[r#"
2005 Error(
2006 Convert(
2007 "pattern",
2008 "expression",
2009 Span {
2010 lo: 4,
2011 hi: 9,
2012 },
2013 ),
2014 )
2015 "#]],
2016 );
2017}
2018
2019#[test]
2020fn interpolated_string_missing_ending() {
2021 check(
2022 expr,
2023 r#"$"string"#,
2024 &expect![[r#"
2025 Error(
2026 Rule(
2027 "expression",
2028 Eof,
2029 Span {
2030 lo: 8,
2031 hi: 8,
2032 },
2033 ),
2034 )
2035
2036 [
2037 Error(
2038 Lex(
2039 UnterminatedString(
2040 Span {
2041 lo: 0,
2042 hi: 0,
2043 },
2044 ),
2045 ),
2046 ),
2047 ]"#]],
2048 );
2049}
2050
2051#[test]
2052fn interpolated_string() {
2053 check(
2054 expr,
2055 r#"$"string""#,
2056 &expect![[r#"
2057 Expr _id_ [0-9]: Interpolate:
2058 Lit: "string""#]],
2059 );
2060}
2061
2062#[test]
2063fn interpolated_string_braced() {
2064 check(
2065 expr,
2066 r#"$"{x}""#,
2067 &expect![[r#"
2068 Expr _id_ [0-6]: Interpolate:
2069 Expr: Expr _id_ [3-4]: Path: Path _id_ [3-4] (Ident _id_ [3-4] "x")"#]],
2070 );
2071}
2072
2073#[test]
2074fn interpolated_string_escape_brace() {
2075 check(
2076 expr,
2077 r#"$"\{""#,
2078 &expect![[r#"
2079 Expr _id_ [0-5]: Interpolate:
2080 Lit: "\\{""#]],
2081 );
2082}
2083
2084#[test]
2085fn interpolated_string_unclosed_brace() {
2086 check(
2087 expr,
2088 r#"$"{"#,
2089 &expect![[r#"
2090 Error(
2091 Rule(
2092 "expression",
2093 Eof,
2094 Span {
2095 lo: 3,
2096 hi: 3,
2097 },
2098 ),
2099 )
2100 "#]],
2101 );
2102}
2103
2104#[test]
2105fn interpolated_string_unclosed_brace_quote() {
2106 check(
2107 expr,
2108 r#"$"{""#,
2109 &expect![[r#"
2110 Error(
2111 Rule(
2112 "expression",
2113 Eof,
2114 Span {
2115 lo: 4,
2116 hi: 4,
2117 },
2118 ),
2119 )
2120
2121 [
2122 Error(
2123 Lex(
2124 UnterminatedString(
2125 Span {
2126 lo: 3,
2127 hi: 3,
2128 },
2129 ),
2130 ),
2131 ),
2132 ]"#]],
2133 );
2134}
2135
2136#[test]
2137fn interpolated_string_unopened_brace() {
2138 check(
2139 expr,
2140 r#"$"}"#,
2141 &expect![[r#"
2142 Error(
2143 Rule(
2144 "expression",
2145 Eof,
2146 Span {
2147 lo: 3,
2148 hi: 3,
2149 },
2150 ),
2151 )
2152
2153 [
2154 Error(
2155 Lex(
2156 UnterminatedString(
2157 Span {
2158 lo: 0,
2159 hi: 0,
2160 },
2161 ),
2162 ),
2163 ),
2164 ]"#]],
2165 );
2166}
2167
2168#[test]
2169fn interpolated_string_unopened_brace_quote() {
2170 check(
2171 expr,
2172 r#"$"}""#,
2173 &expect![[r#"
2174 Expr _id_ [0-4]: Interpolate:
2175 Lit: "}""#]],
2176 );
2177}
2178
2179#[test]
2180fn interpolated_string_braced_index() {
2181 check(
2182 expr,
2183 r#"$"{xs[0]}""#,
2184 &expect![[r#"
2185 Expr _id_ [0-10]: Interpolate:
2186 Expr: Expr _id_ [3-8]: Index:
2187 Expr _id_ [3-5]: Path: Path _id_ [3-5] (Ident _id_ [3-5] "xs")
2188 Expr _id_ [6-7]: Lit: Int(0)"#]],
2189 );
2190}
2191
2192#[test]
2193fn interpolated_string_two_braced() {
2194 check(
2195 expr,
2196 r#"$"{x} {y}""#,
2197 &expect![[r#"
2198 Expr _id_ [0-10]: Interpolate:
2199 Expr: Expr _id_ [3-4]: Path: Path _id_ [3-4] (Ident _id_ [3-4] "x")
2200 Lit: " "
2201 Expr: Expr _id_ [7-8]: Path: Path _id_ [7-8] (Ident _id_ [7-8] "y")"#]],
2202 );
2203}
2204
2205#[test]
2206fn interpolated_string_braced_normal_string() {
2207 check(
2208 expr,
2209 r#"$"{"{}"}""#,
2210 &expect![[r#"
2211 Expr _id_ [0-9]: Interpolate:
2212 Expr: Expr _id_ [3-7]: Lit: String("{}")"#]],
2213 );
2214}
2215
2216#[test]
2217fn nested_interpolated_string() {
2218 check(
2219 expr,
2220 r#"$"{$"{x}"}""#,
2221 &expect![[r#"
2222 Expr _id_ [0-11]: Interpolate:
2223 Expr: Expr _id_ [3-9]: Interpolate:
2224 Expr: Expr _id_ [6-7]: Path: Path _id_ [6-7] (Ident _id_ [6-7] "x")"#]],
2225 );
2226}
2227
2228#[test]
2229fn nested_interpolated_string_with_exprs() {
2230 check(
2231 expr,
2232 r#"$"foo {x + $"bar {y}"} baz""#,
2233 &expect![[r#"
2234 Expr _id_ [0-27]: Interpolate:
2235 Lit: "foo "
2236 Expr: Expr _id_ [7-21]: BinOp (Add):
2237 Expr _id_ [7-8]: Path: Path _id_ [7-8] (Ident _id_ [7-8] "x")
2238 Expr _id_ [11-21]: Interpolate:
2239 Lit: "bar "
2240 Expr: Expr _id_ [18-19]: Path: Path _id_ [18-19] (Ident _id_ [18-19] "y")
2241 Lit: " baz""#]],
2242 );
2243}
2244
2245#[test]
2246fn duplicate_commas_in_tuple() {
2247 check(
2248 expr,
2249 "(x,, y)",
2250 &expect![[r#"
2251 Expr _id_ [0-7]: Tuple:
2252 Expr _id_ [1-2]: Path: Path _id_ [1-2] (Ident _id_ [1-2] "x")
2253 Expr _id_ [3-3]: Err
2254 Expr _id_ [5-6]: Path: Path _id_ [5-6] (Ident _id_ [5-6] "y")
2255
2256 [
2257 Error(
2258 MissingSeqEntry(
2259 Span {
2260 lo: 3,
2261 hi: 3,
2262 },
2263 ),
2264 ),
2265 ]"#]],
2266 );
2267}
2268
2269#[test]
2270fn many_duplicate_commas_in_tuple() {
2271 check(
2272 expr,
2273 "(x,,,, y)",
2274 &expect![[r#"
2275 Expr _id_ [0-9]: Tuple:
2276 Expr _id_ [1-2]: Path: Path _id_ [1-2] (Ident _id_ [1-2] "x")
2277 Expr _id_ [3-3]: Err
2278 Expr _id_ [4-4]: Err
2279 Expr _id_ [5-5]: Err
2280 Expr _id_ [7-8]: Path: Path _id_ [7-8] (Ident _id_ [7-8] "y")
2281
2282 [
2283 Error(
2284 MissingSeqEntry(
2285 Span {
2286 lo: 3,
2287 hi: 3,
2288 },
2289 ),
2290 ),
2291 Error(
2292 MissingSeqEntry(
2293 Span {
2294 lo: 4,
2295 hi: 4,
2296 },
2297 ),
2298 ),
2299 Error(
2300 MissingSeqEntry(
2301 Span {
2302 lo: 5,
2303 hi: 5,
2304 },
2305 ),
2306 ),
2307 ]"#]],
2308 );
2309}
2310
2311#[test]
2312fn invalid_initial_comma_in_tuple() {
2313 check(
2314 expr,
2315 "(, x)",
2316 &expect![[r#"
2317 Expr _id_ [0-5]: Tuple:
2318 Expr _id_ [1-1]: Err
2319 Expr _id_ [3-4]: Path: Path _id_ [3-4] (Ident _id_ [3-4] "x")
2320
2321 [
2322 Error(
2323 MissingSeqEntry(
2324 Span {
2325 lo: 1,
2326 hi: 1,
2327 },
2328 ),
2329 ),
2330 ]"#]],
2331 );
2332}
2333
2334#[test]
2335fn many_invalid_initial_commas_in_tuple() {
2336 check(
2337 expr,
2338 "(,,,, x)",
2339 &expect![[r#"
2340 Expr _id_ [0-8]: Tuple:
2341 Expr _id_ [1-1]: Err
2342 Expr _id_ [2-2]: Err
2343 Expr _id_ [3-3]: Err
2344 Expr _id_ [4-4]: Err
2345 Expr _id_ [6-7]: Path: Path _id_ [6-7] (Ident _id_ [6-7] "x")
2346
2347 [
2348 Error(
2349 MissingSeqEntry(
2350 Span {
2351 lo: 1,
2352 hi: 1,
2353 },
2354 ),
2355 ),
2356 Error(
2357 MissingSeqEntry(
2358 Span {
2359 lo: 2,
2360 hi: 2,
2361 },
2362 ),
2363 ),
2364 Error(
2365 MissingSeqEntry(
2366 Span {
2367 lo: 3,
2368 hi: 3,
2369 },
2370 ),
2371 ),
2372 Error(
2373 MissingSeqEntry(
2374 Span {
2375 lo: 4,
2376 hi: 4,
2377 },
2378 ),
2379 ),
2380 ]"#]],
2381 );
2382}
2383
2384#[test]
2385fn duplicate_commas_in_pattern() {
2386 check(
2387 expr,
2388 "set (x,, y) = (1, 2)",
2389 &expect![[r#"
2390 Expr _id_ [0-20]: Assign:
2391 Expr _id_ [4-11]: Tuple:
2392 Expr _id_ [5-6]: Path: Path _id_ [5-6] (Ident _id_ [5-6] "x")
2393 Expr _id_ [7-7]: Err
2394 Expr _id_ [9-10]: Path: Path _id_ [9-10] (Ident _id_ [9-10] "y")
2395 Expr _id_ [14-20]: Tuple:
2396 Expr _id_ [15-16]: Lit: Int(1)
2397 Expr _id_ [18-19]: Lit: Int(2)
2398
2399 [
2400 Error(
2401 MissingSeqEntry(
2402 Span {
2403 lo: 7,
2404 hi: 7,
2405 },
2406 ),
2407 ),
2408 ]"#]],
2409 );
2410}
2411
2412#[test]
2413fn invalid_initial_commas_in_pattern() {
2414 check(
2415 expr,
2416 "set (, x) = (1, 2)",
2417 &expect![[r#"
2418 Expr _id_ [0-18]: Assign:
2419 Expr _id_ [4-9]: Tuple:
2420 Expr _id_ [5-5]: Err
2421 Expr _id_ [7-8]: Path: Path _id_ [7-8] (Ident _id_ [7-8] "x")
2422 Expr _id_ [12-18]: Tuple:
2423 Expr _id_ [13-14]: Lit: Int(1)
2424 Expr _id_ [16-17]: Lit: Int(2)
2425
2426 [
2427 Error(
2428 MissingSeqEntry(
2429 Span {
2430 lo: 5,
2431 hi: 5,
2432 },
2433 ),
2434 ),
2435 ]"#]],
2436 );
2437}
2438