microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.0.33

Branches

Tags

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

Clone

HTTPS

Download ZIP

compiler/qsc_parse/src/expr/tests.rs

2435lines · modecode

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