microsoft/qdk

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.1.3

Branches

Tags

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

Clone

HTTPS

Download ZIP

compiler/qsc_parse/src/item/tests.rs

1495lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4use super::{parse, parse_attr, parse_namespaces, parse_spec_decl};
5use crate::tests::{check, check_vec};
6use expect_test::expect;
7
8#[test]
9fn body_intrinsic() {
10 check(
11 parse_spec_decl,
12 "body intrinsic;",
13 &expect!["SpecDecl _id_ [0-15] (Body): Gen: Intrinsic"],
14 );
15}
16
17#[test]
18fn adjoint_self() {
19 check(
20 parse_spec_decl,
21 "adjoint self;",
22 &expect!["SpecDecl _id_ [0-13] (Adj): Gen: Slf"],
23 );
24}
25
26#[test]
27fn adjoint_invert() {
28 check(
29 parse_spec_decl,
30 "adjoint invert;",
31 &expect!["SpecDecl _id_ [0-15] (Adj): Gen: Invert"],
32 );
33}
34
35#[test]
36fn controlled_distribute() {
37 check(
38 parse_spec_decl,
39 "controlled distribute;",
40 &expect!["SpecDecl _id_ [0-22] (Ctl): Gen: Distribute"],
41 );
42}
43
44#[test]
45fn controlled_adjoint_auto() {
46 check(
47 parse_spec_decl,
48 "controlled adjoint auto;",
49 &expect!["SpecDecl _id_ [0-24] (CtlAdj): Gen: Auto"],
50 );
51}
52
53#[test]
54fn spec_gen_missing_semi() {
55 check(
56 parse_spec_decl,
57 "body intrinsic",
58 &expect![[r#"
59 Error(
60 Token(
61 Semi,
62 Eof,
63 Span {
64 lo: 14,
65 hi: 14,
66 },
67 ),
68 )
69 "#]],
70 );
71}
72
73#[test]
74fn spec_invalid_gen() {
75 check(
76 parse_spec_decl,
77 "adjoint foo;",
78 &expect![[r#"
79 Error(
80 Token(
81 Open(
82 Brace,
83 ),
84 Semi,
85 Span {
86 lo: 11,
87 hi: 12,
88 },
89 ),
90 )
91 "#]],
92 );
93}
94
95#[test]
96fn open_no_alias() {
97 check(
98 parse,
99 "open Foo.Bar.Baz;",
100 &expect![[r#"
101 Item _id_ [0-17]:
102 Open (Ident _id_ [5-16] "Foo.Bar.Baz")"#]],
103 );
104}
105
106#[test]
107fn open_alias() {
108 check(
109 parse,
110 "open Foo.Bar.Baz as Baz;",
111 &expect![[r#"
112 Item _id_ [0-24]:
113 Open (Ident _id_ [5-16] "Foo.Bar.Baz") (Ident _id_ [20-23] "Baz")"#]],
114 );
115}
116
117#[test]
118fn open_alias_dot() {
119 check(
120 parse,
121 "open Foo.Bar.Baz as Bar.Baz;",
122 &expect![[r#"
123 Item _id_ [0-28]:
124 Open (Ident _id_ [5-16] "Foo.Bar.Baz") (Ident _id_ [20-27] "Bar.Baz")"#]],
125 );
126}
127
128#[test]
129fn ty_decl() {
130 check(
131 parse,
132 "newtype Foo = Unit;",
133 &expect![[r#"
134 Item _id_ [0-19]:
135 New Type (Ident _id_ [8-11] "Foo"): TyDef _id_ [14-18]: Field:
136 Type _id_ [14-18]: Path: Path _id_ [14-18] (Ident _id_ [14-18] "Unit")"#]],
137 );
138}
139
140#[test]
141fn ty_decl_field_name() {
142 check(
143 parse,
144 "newtype Foo = Bar : Int;",
145 &expect![[r#"
146 Item _id_ [0-24]:
147 New Type (Ident _id_ [8-11] "Foo"): TyDef _id_ [14-23]: Field:
148 Ident _id_ [14-17] "Bar"
149 Type _id_ [20-23]: Path: Path _id_ [20-23] (Ident _id_ [20-23] "Int")"#]],
150 );
151}
152
153#[test]
154fn ty_decl_doc() {
155 check(
156 parse,
157 "/// This is a
158 /// doc comment.
159 newtype Foo = Int;",
160 &expect![[r#"
161 Item _id_ [0-65]:
162 doc:
163 This is a
164 doc comment.
165 New Type (Ident _id_ [55-58] "Foo"): TyDef _id_ [61-64]: Field:
166 Type _id_ [61-64]: Path: Path _id_ [61-64] (Ident _id_ [61-64] "Int")"#]],
167 );
168}
169
170#[test]
171fn udt_item_doc() {
172 check(
173 parse,
174 "newtype Foo = (
175 /// doc-string for arg1
176 arg1 : Int,
177 /// doc-string for arg2
178 arg2 : Int
179 );",
180 &expect![[r#"
181 Item _id_ [0-125]:
182 New Type (Ident _id_ [8-11] "Foo"): TyDef _id_ [14-124]: Tuple:
183 TyDef _id_ [56-66]: Field:
184 Ident _id_ [56-60] "arg1"
185 Type _id_ [63-66]: Path: Path _id_ [63-66] (Ident _id_ [63-66] "Int")
186 TyDef _id_ [108-118]: Field:
187 Ident _id_ [108-112] "arg2"
188 Type _id_ [115-118]: Path: Path _id_ [115-118] (Ident _id_ [115-118] "Int")"#]],
189 );
190}
191#[test]
192fn callable_param_doc() {
193 check(
194 parse,
195 "
196 operation Foo(
197 /// the input
198 input: Int): Unit {}
199 ",
200 &expect![[r#"
201 Item _id_ [9-76]:
202 Callable _id_ [9-76] (Operation):
203 name: Ident _id_ [19-22] "Foo"
204 input: Pat _id_ [22-67]: Paren:
205 Pat _id_ [56-66]: Bind:
206 Ident _id_ [56-61] "input"
207 Type _id_ [63-66]: Path: Path _id_ [63-66] (Ident _id_ [63-66] "Int")
208 output: Type _id_ [69-73]: Path: Path _id_ [69-73] (Ident _id_ [69-73] "Unit")
209 body: Block: Block _id_ [74-76]: <empty>"#]],
210 );
211}
212#[test]
213fn callable_return_doc() {
214 check(
215 parse,
216 "
217 operation Foo(input: Int):
218 /// the return type
219 Unit {}
220 ",
221 &expect![[r#"
222 Item _id_ [9-79]:
223 Callable _id_ [9-79] (Operation):
224 name: Ident _id_ [19-22] "Foo"
225 input: Pat _id_ [22-34]: Paren:
226 Pat _id_ [23-33]: Bind:
227 Ident _id_ [23-28] "input"
228 Type _id_ [30-33]: Path: Path _id_ [30-33] (Ident _id_ [30-33] "Int")
229 output: Type _id_ [72-76]: Path: Path _id_ [72-76] (Ident _id_ [72-76] "Unit")
230 body: Block: Block _id_ [77-79]: <empty>"#]],
231 );
232}
233
234#[test]
235fn nested_udt_item_doc() {
236 check(
237 parse,
238 "newtype Nested = (Double,
239 (
240 /// Doc comment 1
241 ItemName : Int,
242 /// Doc comment 2
243 String,
244 (
245 /// Doc comment 3
246 ItemName: String
247 )
248 )
249 );",
250 &expect![[r#"
251 Item _id_ [0-299]:
252 New Type (Ident _id_ [8-14] "Nested"): TyDef _id_ [17-298]: Tuple:
253 TyDef _id_ [18-24]: Field:
254 Type _id_ [18-24]: Path: Path _id_ [18-24] (Ident _id_ [18-24] "Double")
255 TyDef _id_ [38-288]: Tuple:
256 TyDef _id_ [90-104]: Field:
257 Ident _id_ [90-98] "ItemName"
258 Type _id_ [101-104]: Path: Path _id_ [101-104] (Ident _id_ [101-104] "Int")
259 TyDef _id_ [156-162]: Field:
260 Type _id_ [156-162]: Path: Path _id_ [156-162] (Ident _id_ [156-162] "String")
261 TyDef _id_ [180-274]: Paren:
262 TyDef _id_ [240-256]: Field:
263 Ident _id_ [240-248] "ItemName"
264 Type _id_ [250-256]: Path: Path _id_ [250-256] (Ident _id_ [250-256] "String")"#]],
265 );
266}
267
268#[test]
269fn allow_docstring_basic_type() {
270 check(
271 parse,
272 "newtype Nested = (Double,
273 (
274 ItemName:
275 /// Doc comment
276 String
277 )
278 );",
279 &expect![[r#"
280 Item _id_ [0-141]:
281 New Type (Ident _id_ [8-14] "Nested"): TyDef _id_ [17-140]: Tuple:
282 TyDef _id_ [18-24]: Field:
283 Type _id_ [18-24]: Path: Path _id_ [18-24] (Ident _id_ [18-24] "Double")
284 TyDef _id_ [38-130]: Paren:
285 TyDef _id_ [52-116]: Field:
286 Ident _id_ [52-60] "ItemName"
287 Type _id_ [110-116]: Path: Path _id_ [110-116] (Ident _id_ [110-116] "String")"#]],
288 );
289}
290
291#[test]
292fn ty_def_invalid_field_name() {
293 check(
294 parse,
295 "newtype Foo = Bar.Baz : Int[];",
296 &expect![[r#"
297 Error(
298 Convert(
299 "identifier",
300 "type",
301 Span {
302 lo: 14,
303 hi: 21,
304 },
305 ),
306 )
307 "#]],
308 );
309}
310
311#[test]
312fn ty_def_tuple() {
313 check(
314 parse,
315 "newtype Foo = (Int, Int);",
316 &expect![[r#"
317 Item _id_ [0-25]:
318 New Type (Ident _id_ [8-11] "Foo"): TyDef _id_ [14-24]: Field:
319 Type _id_ [14-24]: Tuple:
320 Type _id_ [15-18]: Path: Path _id_ [15-18] (Ident _id_ [15-18] "Int")
321 Type _id_ [20-23]: Path: Path _id_ [20-23] (Ident _id_ [20-23] "Int")"#]],
322 );
323}
324
325#[test]
326fn ty_def_tuple_one_named() {
327 check(
328 parse,
329 "newtype Foo = (X : Int, Int);",
330 &expect![[r#"
331 Item _id_ [0-29]:
332 New Type (Ident _id_ [8-11] "Foo"): TyDef _id_ [14-28]: Tuple:
333 TyDef _id_ [15-22]: Field:
334 Ident _id_ [15-16] "X"
335 Type _id_ [19-22]: Path: Path _id_ [19-22] (Ident _id_ [19-22] "Int")
336 TyDef _id_ [24-27]: Field:
337 Type _id_ [24-27]: Path: Path _id_ [24-27] (Ident _id_ [24-27] "Int")"#]],
338 );
339}
340
341#[test]
342fn ty_def_tuple_both_named() {
343 check(
344 parse,
345 "newtype Foo = (X : Int, Y : Int);",
346 &expect![[r#"
347 Item _id_ [0-33]:
348 New Type (Ident _id_ [8-11] "Foo"): TyDef _id_ [14-32]: Tuple:
349 TyDef _id_ [15-22]: Field:
350 Ident _id_ [15-16] "X"
351 Type _id_ [19-22]: Path: Path _id_ [19-22] (Ident _id_ [19-22] "Int")
352 TyDef _id_ [24-31]: Field:
353 Ident _id_ [24-25] "Y"
354 Type _id_ [28-31]: Path: Path _id_ [28-31] (Ident _id_ [28-31] "Int")"#]],
355 );
356}
357
358#[test]
359fn ty_def_nested_tuple() {
360 check(
361 parse,
362 "newtype Foo = ((X : Int, Y : Int), Z : Int);",
363 &expect![[r#"
364 Item _id_ [0-44]:
365 New Type (Ident _id_ [8-11] "Foo"): TyDef _id_ [14-43]: Tuple:
366 TyDef _id_ [15-33]: Tuple:
367 TyDef _id_ [16-23]: Field:
368 Ident _id_ [16-17] "X"
369 Type _id_ [20-23]: Path: Path _id_ [20-23] (Ident _id_ [20-23] "Int")
370 TyDef _id_ [25-32]: Field:
371 Ident _id_ [25-26] "Y"
372 Type _id_ [29-32]: Path: Path _id_ [29-32] (Ident _id_ [29-32] "Int")
373 TyDef _id_ [35-42]: Field:
374 Ident _id_ [35-36] "Z"
375 Type _id_ [39-42]: Path: Path _id_ [39-42] (Ident _id_ [39-42] "Int")"#]],
376 );
377}
378
379#[test]
380fn ty_def_tuple_with_name() {
381 check(
382 parse,
383 "newtype Foo = Pair : (Int, Int);",
384 &expect![[r#"
385 Item _id_ [0-32]:
386 New Type (Ident _id_ [8-11] "Foo"): TyDef _id_ [14-31]: Field:
387 Ident _id_ [14-18] "Pair"
388 Type _id_ [21-31]: Tuple:
389 Type _id_ [22-25]: Path: Path _id_ [22-25] (Ident _id_ [22-25] "Int")
390 Type _id_ [27-30]: Path: Path _id_ [27-30] (Ident _id_ [27-30] "Int")"#]],
391 );
392}
393
394#[test]
395fn ty_def_tuple_array() {
396 check(
397 parse,
398 "newtype Foo = (Int, Int)[];",
399 &expect![[r#"
400 Item _id_ [0-27]:
401 New Type (Ident _id_ [8-11] "Foo"): TyDef _id_ [14-26]: Field:
402 Type _id_ [14-26]: Array: Type _id_ [14-24]: Tuple:
403 Type _id_ [15-18]: Path: Path _id_ [15-18] (Ident _id_ [15-18] "Int")
404 Type _id_ [20-23]: Path: Path _id_ [20-23] (Ident _id_ [20-23] "Int")"#]],
405 );
406}
407
408#[test]
409fn ty_def_tuple_lambda_args() {
410 check(
411 parse,
412 "newtype Foo = (Int, Int) -> Int;",
413 &expect![[r#"
414 Item _id_ [0-32]:
415 New Type (Ident _id_ [8-11] "Foo"): TyDef _id_ [14-31]: Field:
416 Type _id_ [14-31]: Arrow (Function):
417 param: Type _id_ [14-24]: Tuple:
418 Type _id_ [15-18]: Path: Path _id_ [15-18] (Ident _id_ [15-18] "Int")
419 Type _id_ [20-23]: Path: Path _id_ [20-23] (Ident _id_ [20-23] "Int")
420 return: Type _id_ [28-31]: Path: Path _id_ [28-31] (Ident _id_ [28-31] "Int")"#]],
421 );
422}
423
424#[test]
425fn ty_def_duplicate_comma() {
426 check(
427 parse,
428 "newtype Foo = (Int,, Int);",
429 &expect![[r#"
430 Item _id_ [0-26]:
431 New Type (Ident _id_ [8-11] "Foo"): TyDef _id_ [14-25]: Tuple:
432 TyDef _id_ [15-18]: Field:
433 Type _id_ [15-18]: Path: Path _id_ [15-18] (Ident _id_ [15-18] "Int")
434 TyDef _id_ [19-19]: Err
435 TyDef _id_ [21-24]: Field:
436 Type _id_ [21-24]: Path: Path _id_ [21-24] (Ident _id_ [21-24] "Int")
437
438 [
439 Error(
440 MissingSeqEntry(
441 Span {
442 lo: 19,
443 hi: 19,
444 },
445 ),
446 ),
447 ]"#]],
448 );
449}
450
451#[test]
452fn ty_def_initial_comma() {
453 check(
454 parse,
455 "newtype Foo = (, Int);",
456 &expect![[r#"
457 Item _id_ [0-22]:
458 New Type (Ident _id_ [8-11] "Foo"): TyDef _id_ [14-21]: Tuple:
459 TyDef _id_ [15-15]: Err
460 TyDef _id_ [17-20]: Field:
461 Type _id_ [17-20]: Path: Path _id_ [17-20] (Ident _id_ [17-20] "Int")
462
463 [
464 Error(
465 MissingSeqEntry(
466 Span {
467 lo: 15,
468 hi: 15,
469 },
470 ),
471 ),
472 ]"#]],
473 );
474}
475
476#[test]
477fn ty_def_named_duplicate_comma() {
478 check(
479 parse,
480 "newtype Foo = (X : Int,, Int);",
481 &expect![[r#"
482 Item _id_ [0-30]:
483 New Type (Ident _id_ [8-11] "Foo"): TyDef _id_ [14-29]: Tuple:
484 TyDef _id_ [15-22]: Field:
485 Ident _id_ [15-16] "X"
486 Type _id_ [19-22]: Path: Path _id_ [19-22] (Ident _id_ [19-22] "Int")
487 TyDef _id_ [23-23]: Err
488 TyDef _id_ [25-28]: Field:
489 Type _id_ [25-28]: Path: Path _id_ [25-28] (Ident _id_ [25-28] "Int")
490
491 [
492 Error(
493 MissingSeqEntry(
494 Span {
495 lo: 23,
496 hi: 23,
497 },
498 ),
499 ),
500 ]"#]],
501 );
502}
503
504#[test]
505fn function_decl() {
506 check(
507 parse,
508 "function Foo() : Unit { body intrinsic; }",
509 &expect![[r#"
510 Item _id_ [0-41]:
511 Callable _id_ [0-41] (Function):
512 name: Ident _id_ [9-12] "Foo"
513 input: Pat _id_ [12-14]: Unit
514 output: Type _id_ [17-21]: Path: Path _id_ [17-21] (Ident _id_ [17-21] "Unit")
515 body: Specializations:
516 SpecDecl _id_ [24-39] (Body): Gen: Intrinsic"#]],
517 );
518}
519
520#[test]
521fn function_decl_doc() {
522 check(
523 parse,
524 "/// This is a
525 /// doc comment.
526 function Foo() : () {}",
527 &expect![[r#"
528 Item _id_ [0-69]:
529 doc:
530 This is a
531 doc comment.
532 Callable _id_ [47-69] (Function):
533 name: Ident _id_ [56-59] "Foo"
534 input: Pat _id_ [59-61]: Unit
535 output: Type _id_ [64-66]: Unit
536 body: Block: Block _id_ [67-69]: <empty>"#]],
537 );
538}
539
540#[test]
541fn operation_decl() {
542 check(
543 parse,
544 "operation Foo() : Unit { body intrinsic; }",
545 &expect![[r#"
546 Item _id_ [0-42]:
547 Callable _id_ [0-42] (Operation):
548 name: Ident _id_ [10-13] "Foo"
549 input: Pat _id_ [13-15]: Unit
550 output: Type _id_ [18-22]: Path: Path _id_ [18-22] (Ident _id_ [18-22] "Unit")
551 body: Specializations:
552 SpecDecl _id_ [25-40] (Body): Gen: Intrinsic"#]],
553 );
554}
555
556#[test]
557fn operation_decl_doc() {
558 check(
559 parse,
560 "/// This is a
561 /// doc comment.
562 operation Foo() : () {}",
563 &expect![[r#"
564 Item _id_ [0-70]:
565 doc:
566 This is a
567 doc comment.
568 Callable _id_ [47-70] (Operation):
569 name: Ident _id_ [57-60] "Foo"
570 input: Pat _id_ [60-62]: Unit
571 output: Type _id_ [65-67]: Unit
572 body: Block: Block _id_ [68-70]: <empty>"#]],
573 );
574}
575
576#[test]
577fn function_one_param() {
578 check(
579 parse,
580 "function Foo(x : Int) : Unit { body intrinsic; }",
581 &expect![[r#"
582 Item _id_ [0-48]:
583 Callable _id_ [0-48] (Function):
584 name: Ident _id_ [9-12] "Foo"
585 input: Pat _id_ [12-21]: Paren:
586 Pat _id_ [13-20]: Bind:
587 Ident _id_ [13-14] "x"
588 Type _id_ [17-20]: Path: Path _id_ [17-20] (Ident _id_ [17-20] "Int")
589 output: Type _id_ [24-28]: Path: Path _id_ [24-28] (Ident _id_ [24-28] "Unit")
590 body: Specializations:
591 SpecDecl _id_ [31-46] (Body): Gen: Intrinsic"#]],
592 );
593}
594
595#[test]
596fn function_two_params() {
597 check(
598 parse,
599 "function Foo(x : Int, y : Int) : Unit { body intrinsic; }",
600 &expect![[r#"
601 Item _id_ [0-57]:
602 Callable _id_ [0-57] (Function):
603 name: Ident _id_ [9-12] "Foo"
604 input: Pat _id_ [12-30]: Tuple:
605 Pat _id_ [13-20]: Bind:
606 Ident _id_ [13-14] "x"
607 Type _id_ [17-20]: Path: Path _id_ [17-20] (Ident _id_ [17-20] "Int")
608 Pat _id_ [22-29]: Bind:
609 Ident _id_ [22-23] "y"
610 Type _id_ [26-29]: Path: Path _id_ [26-29] (Ident _id_ [26-29] "Int")
611 output: Type _id_ [33-37]: Path: Path _id_ [33-37] (Ident _id_ [33-37] "Unit")
612 body: Specializations:
613 SpecDecl _id_ [40-55] (Body): Gen: Intrinsic"#]],
614 );
615}
616
617#[test]
618fn function_one_ty_param() {
619 check(
620 parse,
621 "function Foo<'T>() : Unit { body intrinsic; }",
622 &expect![[r#"
623 Item _id_ [0-45]:
624 Callable _id_ [0-45] (Function):
625 name: Ident _id_ [9-12] "Foo"
626 generics:
627 Ident _id_ [13-15] "'T"
628 input: Pat _id_ [16-18]: Unit
629 output: Type _id_ [21-25]: Path: Path _id_ [21-25] (Ident _id_ [21-25] "Unit")
630 body: Specializations:
631 SpecDecl _id_ [28-43] (Body): Gen: Intrinsic"#]],
632 );
633}
634
635#[test]
636fn function_two_ty_params() {
637 check(
638 parse,
639 "function Foo<'T, 'U>() : Unit { body intrinsic; }",
640 &expect![[r#"
641 Item _id_ [0-49]:
642 Callable _id_ [0-49] (Function):
643 name: Ident _id_ [9-12] "Foo"
644 generics:
645 Ident _id_ [13-15] "'T"
646 Ident _id_ [17-19] "'U"
647 input: Pat _id_ [20-22]: Unit
648 output: Type _id_ [25-29]: Path: Path _id_ [25-29] (Ident _id_ [25-29] "Unit")
649 body: Specializations:
650 SpecDecl _id_ [32-47] (Body): Gen: Intrinsic"#]],
651 );
652}
653
654#[test]
655fn function_duplicate_comma_in_ty_param() {
656 check(
657 parse,
658 "function Foo<'T,,>() : Unit { body intrinsic; }",
659 &expect![[r#"
660 Item _id_ [0-47]:
661 Callable _id_ [0-47] (Function):
662 name: Ident _id_ [9-12] "Foo"
663 generics:
664 Ident _id_ [13-15] "'T"
665 Ident _id_ [16-16] ""
666 input: Pat _id_ [18-20]: Unit
667 output: Type _id_ [23-27]: Path: Path _id_ [23-27] (Ident _id_ [23-27] "Unit")
668 body: Specializations:
669 SpecDecl _id_ [30-45] (Body): Gen: Intrinsic
670
671 [
672 Error(
673 MissingSeqEntry(
674 Span {
675 lo: 16,
676 hi: 16,
677 },
678 ),
679 ),
680 ]"#]],
681 );
682}
683
684#[test]
685fn function_single_impl() {
686 check(
687 parse,
688 "function Foo(x : Int) : Int { let y = x; y }",
689 &expect![[r#"
690 Item _id_ [0-44]:
691 Callable _id_ [0-44] (Function):
692 name: Ident _id_ [9-12] "Foo"
693 input: Pat _id_ [12-21]: Paren:
694 Pat _id_ [13-20]: Bind:
695 Ident _id_ [13-14] "x"
696 Type _id_ [17-20]: Path: Path _id_ [17-20] (Ident _id_ [17-20] "Int")
697 output: Type _id_ [24-27]: Path: Path _id_ [24-27] (Ident _id_ [24-27] "Int")
698 body: Block: Block _id_ [28-44]:
699 Stmt _id_ [30-40]: Local (Immutable):
700 Pat _id_ [34-35]: Bind:
701 Ident _id_ [34-35] "y"
702 Expr _id_ [38-39]: Path: Path _id_ [38-39] (Ident _id_ [38-39] "x")
703 Stmt _id_ [41-42]: Expr: Expr _id_ [41-42]: Path: Path _id_ [41-42] (Ident _id_ [41-42] "y")"#]],
704 );
705}
706
707#[test]
708fn function_body_missing_semi_between_stmts() {
709 check(
710 parse,
711 "function Foo() : () { f(x) g(y) }",
712 &expect![[r#"
713 Item _id_ [0-33]:
714 Callable _id_ [0-33] (Function):
715 name: Ident _id_ [9-12] "Foo"
716 input: Pat _id_ [12-14]: Unit
717 output: Type _id_ [17-19]: Unit
718 body: Block: Block _id_ [20-33]:
719 Stmt _id_ [22-26]: Expr: Expr _id_ [22-26]: Call:
720 Expr _id_ [22-23]: Path: Path _id_ [22-23] (Ident _id_ [22-23] "f")
721 Expr _id_ [23-26]: Paren: Expr _id_ [24-25]: Path: Path _id_ [24-25] (Ident _id_ [24-25] "x")
722 Stmt _id_ [27-31]: Expr: Expr _id_ [27-31]: Call:
723 Expr _id_ [27-28]: Path: Path _id_ [27-28] (Ident _id_ [27-28] "g")
724 Expr _id_ [28-31]: Paren: Expr _id_ [29-30]: Path: Path _id_ [29-30] (Ident _id_ [29-30] "y")
725
726 [
727 Error(
728 MissingSemi(
729 Span {
730 lo: 26,
731 hi: 26,
732 },
733 ),
734 ),
735 ]"#]],
736 );
737}
738
739#[test]
740fn operation_body_impl() {
741 check(
742 parse,
743 "operation Foo() : Unit { body (...) { x } }",
744 &expect![[r#"
745 Item _id_ [0-43]:
746 Callable _id_ [0-43] (Operation):
747 name: Ident _id_ [10-13] "Foo"
748 input: Pat _id_ [13-15]: Unit
749 output: Type _id_ [18-22]: Path: Path _id_ [18-22] (Ident _id_ [18-22] "Unit")
750 body: Specializations:
751 SpecDecl _id_ [25-41] (Body): Impl:
752 Pat _id_ [30-35]: Paren:
753 Pat _id_ [31-34]: Elided
754 Block _id_ [36-41]:
755 Stmt _id_ [38-39]: Expr: Expr _id_ [38-39]: Path: Path _id_ [38-39] (Ident _id_ [38-39] "x")"#]],
756 );
757}
758
759#[test]
760fn operation_body_ctl_impl() {
761 check(
762 parse,
763 "operation Foo() : Unit { body (...) { x } controlled (cs, ...) { y } }",
764 &expect![[r#"
765 Item _id_ [0-70]:
766 Callable _id_ [0-70] (Operation):
767 name: Ident _id_ [10-13] "Foo"
768 input: Pat _id_ [13-15]: Unit
769 output: Type _id_ [18-22]: Path: Path _id_ [18-22] (Ident _id_ [18-22] "Unit")
770 body: Specializations:
771 SpecDecl _id_ [25-41] (Body): Impl:
772 Pat _id_ [30-35]: Paren:
773 Pat _id_ [31-34]: Elided
774 Block _id_ [36-41]:
775 Stmt _id_ [38-39]: Expr: Expr _id_ [38-39]: Path: Path _id_ [38-39] (Ident _id_ [38-39] "x")
776 SpecDecl _id_ [42-68] (Ctl): Impl:
777 Pat _id_ [53-62]: Tuple:
778 Pat _id_ [54-56]: Bind:
779 Ident _id_ [54-56] "cs"
780 Pat _id_ [58-61]: Elided
781 Block _id_ [63-68]:
782 Stmt _id_ [65-66]: Expr: Expr _id_ [65-66]: Path: Path _id_ [65-66] (Ident _id_ [65-66] "y")"#]],
783 );
784}
785
786#[test]
787fn operation_impl_and_gen() {
788 check(
789 parse,
790 "operation Foo() : Unit { body (...) { x } adjoint self; }",
791 &expect![[r#"
792 Item _id_ [0-57]:
793 Callable _id_ [0-57] (Operation):
794 name: Ident _id_ [10-13] "Foo"
795 input: Pat _id_ [13-15]: Unit
796 output: Type _id_ [18-22]: Path: Path _id_ [18-22] (Ident _id_ [18-22] "Unit")
797 body: Specializations:
798 SpecDecl _id_ [25-41] (Body): Impl:
799 Pat _id_ [30-35]: Paren:
800 Pat _id_ [31-34]: Elided
801 Block _id_ [36-41]:
802 Stmt _id_ [38-39]: Expr: Expr _id_ [38-39]: Path: Path _id_ [38-39] (Ident _id_ [38-39] "x")
803 SpecDecl _id_ [42-55] (Adj): Gen: Slf"#]],
804 );
805}
806
807#[test]
808fn operation_is_adj() {
809 check(
810 parse,
811 "operation Foo() : Unit is Adj {}",
812 &expect![[r#"
813 Item _id_ [0-32]:
814 Callable _id_ [0-32] (Operation):
815 name: Ident _id_ [10-13] "Foo"
816 input: Pat _id_ [13-15]: Unit
817 output: Type _id_ [18-22]: Path: Path _id_ [18-22] (Ident _id_ [18-22] "Unit")
818 functors: Functor Expr _id_ [26-29]: Adj
819 body: Block: Block _id_ [30-32]: <empty>"#]],
820 );
821}
822
823#[test]
824fn operation_is_adj_ctl() {
825 check(
826 parse,
827 "operation Foo() : Unit is Adj + Ctl {}",
828 &expect![[r#"
829 Item _id_ [0-38]:
830 Callable _id_ [0-38] (Operation):
831 name: Ident _id_ [10-13] "Foo"
832 input: Pat _id_ [13-15]: Unit
833 output: Type _id_ [18-22]: Path: Path _id_ [18-22] (Ident _id_ [18-22] "Unit")
834 functors: Functor Expr _id_ [26-35]: BinOp Union: (Functor Expr _id_ [26-29]: Adj) (Functor Expr _id_ [32-35]: Ctl)
835 body: Block: Block _id_ [36-38]: <empty>"#]],
836 );
837}
838
839#[test]
840fn function_missing_output_ty() {
841 check(
842 parse,
843 "function Foo() { body intrinsic; }",
844 &expect![[r#"
845 Error(
846 Token(
847 Colon,
848 Open(
849 Brace,
850 ),
851 Span {
852 lo: 15,
853 hi: 16,
854 },
855 ),
856 )
857 "#]],
858 );
859}
860
861#[test]
862fn internal_ty() {
863 check(
864 parse,
865 "internal newtype Foo = Unit;",
866 &expect![[r#"
867 Item _id_ [0-28]:
868 Visibility _id_ [0-8] (Internal)
869 New Type (Ident _id_ [17-20] "Foo"): TyDef _id_ [23-27]: Field:
870 Type _id_ [23-27]: Path: Path _id_ [23-27] (Ident _id_ [23-27] "Unit")"#]],
871 );
872}
873
874#[test]
875fn internal_function() {
876 check(
877 parse,
878 "internal function Foo() : Unit {}",
879 &expect![[r#"
880 Item _id_ [0-33]:
881 Visibility _id_ [0-8] (Internal)
882 Callable _id_ [9-33] (Function):
883 name: Ident _id_ [18-21] "Foo"
884 input: Pat _id_ [21-23]: Unit
885 output: Type _id_ [26-30]: Path: Path _id_ [26-30] (Ident _id_ [26-30] "Unit")
886 body: Block: Block _id_ [31-33]: <empty>"#]],
887 );
888}
889
890#[test]
891fn internal_function_doc() {
892 check(
893 parse,
894 "/// This is a
895 /// doc comment.
896 internal function Foo() : () {}",
897 &expect![[r#"
898 Item _id_ [0-78]:
899 doc:
900 This is a
901 doc comment.
902 Visibility _id_ [47-55] (Internal)
903 Callable _id_ [56-78] (Function):
904 name: Ident _id_ [65-68] "Foo"
905 input: Pat _id_ [68-70]: Unit
906 output: Type _id_ [73-75]: Unit
907 body: Block: Block _id_ [76-78]: <empty>"#]],
908 );
909}
910
911#[test]
912fn internal_operation() {
913 check(
914 parse,
915 "internal operation Foo() : Unit {}",
916 &expect![[r#"
917 Item _id_ [0-34]:
918 Visibility _id_ [0-8] (Internal)
919 Callable _id_ [9-34] (Operation):
920 name: Ident _id_ [19-22] "Foo"
921 input: Pat _id_ [22-24]: Unit
922 output: Type _id_ [27-31]: Path: Path _id_ [27-31] (Ident _id_ [27-31] "Unit")
923 body: Block: Block _id_ [32-34]: <empty>"#]],
924 );
925}
926
927#[test]
928fn attr_no_args() {
929 check(
930 parse_attr,
931 "@Foo()",
932 &expect![[r#"
933 Attr _id_ [0-6] (Ident _id_ [1-4] "Foo"):
934 Expr _id_ [4-6]: Unit"#]],
935 );
936}
937
938#[test]
939fn attr_single_arg() {
940 check(
941 parse_attr,
942 "@Foo(123)",
943 &expect![[r#"
944 Attr _id_ [0-9] (Ident _id_ [1-4] "Foo"):
945 Expr _id_ [4-9]: Paren: Expr _id_ [5-8]: Lit: Int(123)"#]],
946 );
947}
948
949#[test]
950fn attr_two_args() {
951 check(
952 parse_attr,
953 "@Foo(123, \"bar\")",
954 &expect![[r#"
955 Attr _id_ [0-16] (Ident _id_ [1-4] "Foo"):
956 Expr _id_ [4-16]: Tuple:
957 Expr _id_ [5-8]: Lit: Int(123)
958 Expr _id_ [10-15]: Lit: String("bar")"#]],
959 );
960}
961
962#[test]
963fn open_attr() {
964 check(
965 parse,
966 "@Foo() open Bar;",
967 &expect![[r#"
968 Item _id_ [0-16]:
969 Attr _id_ [0-6] (Ident _id_ [1-4] "Foo"):
970 Expr _id_ [4-6]: Unit
971 Open (Ident _id_ [12-15] "Bar")"#]],
972 );
973}
974
975#[test]
976fn newtype_attr() {
977 check(
978 parse,
979 "@Foo() newtype Bar = Unit;",
980 &expect![[r#"
981 Item _id_ [0-26]:
982 Attr _id_ [0-6] (Ident _id_ [1-4] "Foo"):
983 Expr _id_ [4-6]: Unit
984 New Type (Ident _id_ [15-18] "Bar"): TyDef _id_ [21-25]: Field:
985 Type _id_ [21-25]: Path: Path _id_ [21-25] (Ident _id_ [21-25] "Unit")"#]],
986 );
987}
988
989#[test]
990fn operation_one_attr() {
991 check(
992 parse,
993 "@Foo() operation Bar() : Unit {}",
994 &expect![[r#"
995 Item _id_ [0-32]:
996 Attr _id_ [0-6] (Ident _id_ [1-4] "Foo"):
997 Expr _id_ [4-6]: Unit
998 Callable _id_ [7-32] (Operation):
999 name: Ident _id_ [17-20] "Bar"
1000 input: Pat _id_ [20-22]: Unit
1001 output: Type _id_ [25-29]: Path: Path _id_ [25-29] (Ident _id_ [25-29] "Unit")
1002 body: Block: Block _id_ [30-32]: <empty>"#]],
1003 );
1004}
1005
1006#[test]
1007fn operation_two_attrs() {
1008 check(
1009 parse,
1010 "@Foo() @Bar() operation Baz() : Unit {}",
1011 &expect![[r#"
1012 Item _id_ [0-39]:
1013 Attr _id_ [0-6] (Ident _id_ [1-4] "Foo"):
1014 Expr _id_ [4-6]: Unit
1015 Attr _id_ [7-13] (Ident _id_ [8-11] "Bar"):
1016 Expr _id_ [11-13]: Unit
1017 Callable _id_ [14-39] (Operation):
1018 name: Ident _id_ [24-27] "Baz"
1019 input: Pat _id_ [27-29]: Unit
1020 output: Type _id_ [32-36]: Path: Path _id_ [32-36] (Ident _id_ [32-36] "Unit")
1021 body: Block: Block _id_ [37-39]: <empty>"#]],
1022 );
1023}
1024
1025#[test]
1026fn operation_attr_doc() {
1027 check(
1028 parse,
1029 "/// This is a
1030 /// doc comment.
1031 @Foo()
1032 operation Bar() : () {}",
1033 &expect![[r#"
1034 Item _id_ [0-85]:
1035 doc:
1036 This is a
1037 doc comment.
1038 Attr _id_ [47-53] (Ident _id_ [48-51] "Foo"):
1039 Expr _id_ [51-53]: Unit
1040 Callable _id_ [62-85] (Operation):
1041 name: Ident _id_ [72-75] "Bar"
1042 input: Pat _id_ [75-77]: Unit
1043 output: Type _id_ [80-82]: Unit
1044 body: Block: Block _id_ [83-85]: <empty>"#]],
1045 );
1046}
1047
1048#[test]
1049fn namespace_function() {
1050 check_vec(
1051 parse_namespaces,
1052 "namespace A { function Foo() : Unit { body intrinsic; } }",
1053 &expect![[r#"
1054 Namespace _id_ [0-57] (Ident _id_ [10-11] "A"):
1055 Item _id_ [14-55]:
1056 Callable _id_ [14-55] (Function):
1057 name: Ident _id_ [23-26] "Foo"
1058 input: Pat _id_ [26-28]: Unit
1059 output: Type _id_ [31-35]: Path: Path _id_ [31-35] (Ident _id_ [31-35] "Unit")
1060 body: Specializations:
1061 SpecDecl _id_ [38-53] (Body): Gen: Intrinsic"#]],
1062 );
1063}
1064
1065#[test]
1066fn namespace_doc() {
1067 check_vec(
1068 parse_namespaces,
1069 "/// This is a
1070 /// doc comment.
1071 namespace A {
1072 function Foo() : () {}
1073 }",
1074 &expect![[r#"
1075 Namespace _id_ [0-105] (Ident _id_ [57-58] "A"):
1076 doc:
1077 This is a
1078 doc comment.
1079 Item _id_ [73-95]:
1080 Callable _id_ [73-95] (Function):
1081 name: Ident _id_ [82-85] "Foo"
1082 input: Pat _id_ [85-87]: Unit
1083 output: Type _id_ [90-92]: Unit
1084 body: Block: Block _id_ [93-95]: <empty>"#]],
1085 );
1086}
1087
1088#[test]
1089fn floating_doc_comments_in_namespace() {
1090 check_vec(
1091 parse_namespaces,
1092 "namespace MyQuantumProgram {
1093 @EntryPoint()
1094 function Main() : Unit {}
1095 /// hi
1096 /// another doc comment
1097}
1098",
1099 &expect![[r#"
1100 Namespace _id_ [0-117] (Ident _id_ [10-26] "MyQuantumProgram"):
1101 Item _id_ [33-76]:
1102 Attr _id_ [33-46] (Ident _id_ [34-44] "EntryPoint"):
1103 Expr _id_ [44-46]: Unit
1104 Callable _id_ [51-76] (Function):
1105 name: Ident _id_ [60-64] "Main"
1106 input: Pat _id_ [64-66]: Unit
1107 output: Type _id_ [69-73]: Path: Path _id_ [69-73] (Ident _id_ [69-73] "Unit")
1108 body: Block: Block _id_ [74-76]: <empty>
1109 Item _id_ [81-115]:
1110 Err
1111
1112 [
1113 Error(
1114 FloatingDocComment(
1115 Span {
1116 lo: 81,
1117 hi: 115,
1118 },
1119 ),
1120 ),
1121 ]"#]],
1122 );
1123}
1124
1125#[test]
1126fn floating_attr_in_namespace() {
1127 check_vec(
1128 parse_namespaces,
1129 "namespace MyQuantumProgram { @EntryPoint() }",
1130 &expect![[r#"
1131 Namespace _id_ [0-44] (Ident _id_ [10-26] "MyQuantumProgram"):
1132 Item _id_ [29-42]:
1133 Err
1134
1135 [
1136 Error(
1137 FloatingAttr(
1138 Span {
1139 lo: 29,
1140 hi: 42,
1141 },
1142 ),
1143 ),
1144 ]"#]],
1145 );
1146}
1147
1148#[test]
1149fn floating_visibility_in_namespace() {
1150 check_vec(
1151 parse_namespaces,
1152 "namespace MyQuantumProgram { internal }",
1153 &expect![[r#"
1154 Namespace _id_ [0-39] (Ident _id_ [10-26] "MyQuantumProgram"):
1155 Item _id_ [29-37]:
1156 Err
1157
1158 [
1159 Error(
1160 FloatingVisibility(
1161 Span {
1162 lo: 29,
1163 hi: 37,
1164 },
1165 ),
1166 ),
1167 ]"#]],
1168 );
1169}
1170
1171#[test]
1172fn two_namespaces() {
1173 check_vec(
1174 parse_namespaces,
1175 "namespace A {} namespace B {}",
1176 &expect![[r#"
1177 Namespace _id_ [0-14] (Ident _id_ [10-11] "A"):,
1178 Namespace _id_ [15-29] (Ident _id_ [25-26] "B"):"#]],
1179 );
1180}
1181
1182#[test]
1183fn two_namespaces_docs() {
1184 check_vec(
1185 parse_namespaces,
1186 "/// This is the first namespace.
1187 namespace A {}
1188 /// This is the second namespace.
1189 namespace B {}",
1190 &expect![[r#"
1191 Namespace _id_ [0-55] (Ident _id_ [51-52] "A"):
1192 doc:
1193 This is the first namespace.,
1194 Namespace _id_ [64-120] (Ident _id_ [116-117] "B"):
1195 doc:
1196 This is the second namespace."#]],
1197 );
1198}
1199
1200#[test]
1201fn two_open_items() {
1202 check_vec(
1203 parse_namespaces,
1204 "namespace A { open B; open C; }",
1205 &expect![[r#"
1206 Namespace _id_ [0-31] (Ident _id_ [10-11] "A"):
1207 Item _id_ [14-21]:
1208 Open (Ident _id_ [19-20] "B")
1209 Item _id_ [22-29]:
1210 Open (Ident _id_ [27-28] "C")"#]],
1211 );
1212}
1213
1214#[test]
1215fn two_ty_items() {
1216 check_vec(
1217 parse_namespaces,
1218 "namespace A { newtype B = Unit; newtype C = Unit; }",
1219 &expect![[r#"
1220 Namespace _id_ [0-51] (Ident _id_ [10-11] "A"):
1221 Item _id_ [14-31]:
1222 New Type (Ident _id_ [22-23] "B"): TyDef _id_ [26-30]: Field:
1223 Type _id_ [26-30]: Path: Path _id_ [26-30] (Ident _id_ [26-30] "Unit")
1224 Item _id_ [32-49]:
1225 New Type (Ident _id_ [40-41] "C"): TyDef _id_ [44-48]: Field:
1226 Type _id_ [44-48]: Path: Path _id_ [44-48] (Ident _id_ [44-48] "Unit")"#]],
1227 );
1228}
1229
1230#[test]
1231fn two_callable_items() {
1232 check_vec(
1233 parse_namespaces,
1234 "namespace A { operation B() : Unit {} function C() : Unit {} }",
1235 &expect![[r#"
1236 Namespace _id_ [0-62] (Ident _id_ [10-11] "A"):
1237 Item _id_ [14-37]:
1238 Callable _id_ [14-37] (Operation):
1239 name: Ident _id_ [24-25] "B"
1240 input: Pat _id_ [25-27]: Unit
1241 output: Type _id_ [30-34]: Path: Path _id_ [30-34] (Ident _id_ [30-34] "Unit")
1242 body: Block: Block _id_ [35-37]: <empty>
1243 Item _id_ [38-60]:
1244 Callable _id_ [38-60] (Function):
1245 name: Ident _id_ [47-48] "C"
1246 input: Pat _id_ [48-50]: Unit
1247 output: Type _id_ [53-57]: Path: Path _id_ [53-57] (Ident _id_ [53-57] "Unit")
1248 body: Block: Block _id_ [58-60]: <empty>"#]],
1249 );
1250}
1251
1252#[test]
1253fn two_callable_items_docs() {
1254 check_vec(
1255 parse_namespaces,
1256 "namespace A {
1257 /// This is the first callable.
1258 function Foo() : () {}
1259 /// This is the second callable.
1260 operation Foo() : () {}
1261 }",
1262 &expect![[r#"
1263 Namespace _id_ [0-183] (Ident _id_ [10-11] "A"):
1264 Item _id_ [26-92]:
1265 doc:
1266 This is the first callable.
1267 Callable _id_ [70-92] (Function):
1268 name: Ident _id_ [79-82] "Foo"
1269 input: Pat _id_ [82-84]: Unit
1270 output: Type _id_ [87-89]: Unit
1271 body: Block: Block _id_ [90-92]: <empty>
1272 Item _id_ [105-173]:
1273 doc:
1274 This is the second callable.
1275 Callable _id_ [150-173] (Operation):
1276 name: Ident _id_ [160-163] "Foo"
1277 input: Pat _id_ [163-165]: Unit
1278 output: Type _id_ [168-170]: Unit
1279 body: Block: Block _id_ [171-173]: <empty>"#]],
1280 );
1281}
1282
1283#[test]
1284fn doc_without_item() {
1285 check_vec(
1286 parse_namespaces,
1287 "namespace A {
1288 /// This is a doc comment.
1289 }",
1290 &expect![[r#"
1291 Namespace _id_ [0-62] (Ident _id_ [10-11] "A"):
1292 Item _id_ [26-52]:
1293 Err
1294
1295 [
1296 Error(
1297 FloatingDocComment(
1298 Span {
1299 lo: 26,
1300 hi: 52,
1301 },
1302 ),
1303 ),
1304 ]"#]],
1305 );
1306}
1307
1308#[test]
1309fn recover_callable_item() {
1310 check_vec(
1311 parse_namespaces,
1312 "namespace A {
1313 function Foo() : Int { 5 }
1314 function Bar() { 10 }
1315 operation Baz() : Double { 2.0 }
1316 }",
1317 &expect![[r#"
1318 Namespace _id_ [0-141] (Ident _id_ [10-11] "A"):
1319 Item _id_ [26-52]:
1320 Callable _id_ [26-52] (Function):
1321 name: Ident _id_ [35-38] "Foo"
1322 input: Pat _id_ [38-40]: Unit
1323 output: Type _id_ [43-46]: Path: Path _id_ [43-46] (Ident _id_ [43-46] "Int")
1324 body: Block: Block _id_ [47-52]:
1325 Stmt _id_ [49-50]: Expr: Expr _id_ [49-50]: Lit: Int(5)
1326 Item _id_ [65-86]:
1327 Err
1328 Item _id_ [99-131]:
1329 Callable _id_ [99-131] (Operation):
1330 name: Ident _id_ [109-112] "Baz"
1331 input: Pat _id_ [112-114]: Unit
1332 output: Type _id_ [117-123]: Path: Path _id_ [117-123] (Ident _id_ [117-123] "Double")
1333 body: Block: Block _id_ [124-131]:
1334 Stmt _id_ [126-129]: Expr: Expr _id_ [126-129]: Lit: Double(2)
1335
1336 [
1337 Error(
1338 Token(
1339 Colon,
1340 Open(
1341 Brace,
1342 ),
1343 Span {
1344 lo: 80,
1345 hi: 81,
1346 },
1347 ),
1348 ),
1349 ]"#]],
1350 );
1351}
1352
1353#[test]
1354fn recover_unclosed_callable_item() {
1355 check_vec(
1356 parse_namespaces,
1357 "namespace A {
1358 function Foo() : Int {",
1359 &expect![[r#"
1360 Namespace _id_ [0-48] (Ident _id_ [10-11] "A"):
1361 Item _id_ [26-48]:
1362 Callable _id_ [26-48] (Function):
1363 name: Ident _id_ [35-38] "Foo"
1364 input: Pat _id_ [38-40]: Unit
1365 output: Type _id_ [43-46]: Path: Path _id_ [43-46] (Ident _id_ [43-46] "Int")
1366 body: Block: Block _id_ [47-48]: <empty>
1367
1368 [
1369 Error(
1370 Token(
1371 Close(
1372 Brace,
1373 ),
1374 Eof,
1375 Span {
1376 lo: 48,
1377 hi: 48,
1378 },
1379 ),
1380 ),
1381 ]"#]],
1382 );
1383}
1384
1385#[test]
1386fn recover_unclosed_namespace() {
1387 check_vec(
1388 parse_namespaces,
1389 "namespace A {
1390 function Foo() : Int { 2 }",
1391 &expect![[r#"
1392 Namespace _id_ [0-52] (Ident _id_ [10-11] "A"):
1393 Item _id_ [26-52]:
1394 Callable _id_ [26-52] (Function):
1395 name: Ident _id_ [35-38] "Foo"
1396 input: Pat _id_ [38-40]: Unit
1397 output: Type _id_ [43-46]: Path: Path _id_ [43-46] (Ident _id_ [43-46] "Int")
1398 body: Block: Block _id_ [47-52]:
1399 Stmt _id_ [49-50]: Expr: Expr _id_ [49-50]: Lit: Int(2)
1400
1401 [
1402 Error(
1403 Token(
1404 Close(
1405 Brace,
1406 ),
1407 Eof,
1408 Span {
1409 lo: 52,
1410 hi: 52,
1411 },
1412 ),
1413 ),
1414 ]"#]],
1415 );
1416}
1417
1418#[test]
1419fn callable_missing_parens() {
1420 check_vec(
1421 parse_namespaces,
1422 "namespace A {
1423 function Foo x : Int : Int { x }
1424 }",
1425 &expect![[r#"
1426 Namespace _id_ [0-64] (Ident _id_ [10-11] "A"):
1427 Item _id_ [22-54]:
1428 Err
1429
1430 [
1431 Error(
1432 MissingParens(
1433 Span {
1434 lo: 35,
1435 hi: 42,
1436 },
1437 ),
1438 ),
1439 ]"#]],
1440 )
1441}
1442
1443#[test]
1444fn callable_missing_close_parens() {
1445 check_vec(
1446 parse_namespaces,
1447 "namespace A {
1448 function Foo (x : Int : Int { x }
1449 }",
1450 &expect![[r#"
1451 Namespace _id_ [0-65] (Ident _id_ [10-11] "A"):
1452 Item _id_ [22-55]:
1453 Err
1454
1455 [
1456 Error(
1457 Token(
1458 Close(
1459 Paren,
1460 ),
1461 Colon,
1462 Span {
1463 lo: 44,
1464 hi: 45,
1465 },
1466 ),
1467 ),
1468 ]"#]],
1469 )
1470}
1471
1472#[test]
1473fn callable_missing_open_parens() {
1474 check_vec(
1475 parse_namespaces,
1476 "namespace A {
1477 function Foo x : Int) : Int { x }
1478 }",
1479 &expect![[r#"
1480 Namespace _id_ [0-65] (Ident _id_ [10-11] "A"):
1481 Item _id_ [22-55]:
1482 Err
1483
1484 [
1485 Error(
1486 MissingParens(
1487 Span {
1488 lo: 35,
1489 hi: 42,
1490 },
1491 ),
1492 ),
1493 ]"#]],
1494 )
1495}