microsoft/qdk

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.23.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

source/language_service/src/references/tests.rs

1278lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4use super::get_references;
5use crate::{
6 Encoding,
7 test_utils::{compile_notebook_with_markers, compile_with_markers},
8};
9use expect_test::{Expect, expect};
10use indoc::indoc;
11
12/// Asserts that the reference locations given at the cursor position matches the expected reference locations.
13/// The cursor position is indicated by a `↘` marker in the source text.
14fn check_with_std(source_with_markers: &str, expect: &Expect) {
15 let (compilation, cursor_position, _) = compile_with_markers(source_with_markers, true);
16 let actual = get_references(
17 &compilation,
18 "<source>",
19 cursor_position,
20 Encoding::Utf8,
21 true,
22 );
23 expect.assert_debug_eq(&actual);
24}
25
26/// Asserts that the reference locations given at the cursor position matches the expected reference locations.
27/// The cursor position is indicated by a `↘` marker in the source text.
28/// The expected reference location ranges are indicated by `◉` markers in the source text.
29fn check(source_with_markers: &str, include_declaration: bool) {
30 let (compilation, cursor_position, target_spans) =
31 compile_with_markers(source_with_markers, true);
32 let actual = get_references(
33 &compilation,
34 "<source>",
35 cursor_position,
36 Encoding::Utf8,
37 include_declaration,
38 )
39 .into_iter()
40 .map(|l| l.range)
41 .collect::<Vec<_>>();
42 for target in &target_spans {
43 assert!(
44 actual.contains(target),
45 "expected {actual:?} to contain {target:?}"
46 );
47 }
48 assert!(target_spans.len() == actual.len());
49}
50
51fn check_include_decl(source_with_markers: &str) {
52 check(source_with_markers, true);
53}
54
55fn check_exclude_decl(source_with_markers: &str) {
56 check(source_with_markers, false);
57}
58
59fn check_notebook_exclude_decl(cells_with_markers: &[(&str, &str)]) {
60 let (compilation, cell_uri, position, target_spans) =
61 compile_notebook_with_markers(cells_with_markers);
62
63 let actual = get_references(&compilation, &cell_uri, position, Encoding::Utf8, false)
64 .into_iter()
65 .collect::<Vec<_>>();
66 for target in &target_spans {
67 assert!(
68 actual.contains(target),
69 "expected {actual:?} to contain {target:?}"
70 );
71 }
72 assert!(target_spans.len() == actual.len());
73}
74
75#[test]
76fn std_callable_ref() {
77 check_with_std(
78 indoc! {r#"
79 namespace Test {
80 open FakeStdLib;
81 operation Foo() : Unit {
82 Fa↘ke();
83 let x = 3;
84 Fake();
85 }
86 }
87 "#},
88 &expect![[r#"
89 [
90 Location {
91 source: "qsharp-library-source:<std>",
92 range: Range {
93 start: Position {
94 line: 2,
95 column: 18,
96 },
97 end: Position {
98 line: 2,
99 column: 22,
100 },
101 },
102 },
103 Location {
104 source: "<source>",
105 range: Range {
106 start: Position {
107 line: 3,
108 column: 8,
109 },
110 end: Position {
111 line: 3,
112 column: 12,
113 },
114 },
115 },
116 Location {
117 source: "<source>",
118 range: Range {
119 start: Position {
120 line: 5,
121 column: 8,
122 },
123 end: Position {
124 line: 5,
125 column: 12,
126 },
127 },
128 },
129 ]
130 "#]],
131 );
132}
133
134#[test]
135fn callable_def() {
136 check_include_decl(
137 r#"
138 namespace Test {
139 operation ◉F↘oo◉() : Unit {
140 ◉Foo◉();
141 ◉Foo◉();
142 }
143 }
144 "#,
145 );
146}
147
148#[test]
149fn callable_ref() {
150 check_include_decl(
151 r#"
152 namespace Test {
153 operation ◉Foo◉() : Unit {
154 ◉Fo↘o◉();
155 ◉Foo◉();
156 }
157 }
158 "#,
159 );
160}
161
162#[test]
163fn callable_exclude_def() {
164 check_exclude_decl(
165 r#"
166 namespace Test {
167 operation Foo() : Unit {
168 ◉Fo↘o◉();
169 ◉Foo◉();
170 }
171 }
172 "#,
173 );
174}
175
176#[test]
177fn udt_def() {
178 check_include_decl(
179 r#"
180 namespace Test {
181 newtype ◉B↘ar◉ = (fst : Int, snd : Int);
182 operation Foo(x : ◉Bar◉) : Unit {
183 let bar = ◉Bar◉(1, 2);
184 let baz = bar::fst;
185 }
186 }
187 "#,
188 );
189}
190
191#[test]
192fn udt_ref() {
193 check_include_decl(
194 r#"
195 namespace Test {
196 newtype ◉Bar◉ = (fst : Int, snd : Int);
197 operation Foo(x : ◉B↘ar◉) : Unit {
198 let bar = ◉Bar◉(1, 2);
199 let baz = bar::fst;
200 }
201 }
202 "#,
203 );
204}
205
206#[test]
207fn udt_ref_constructor() {
208 check_include_decl(
209 r#"
210 namespace Test {
211 newtype ◉Bar◉ = (fst : Int, snd : Int);
212 operation Foo(x : ◉Bar◉) : Unit {
213 let bar = ◉B↘ar◉(1, 2);
214 let baz = bar::fst;
215 }
216 }
217 "#,
218 );
219}
220
221#[test]
222fn udt_exclude_def() {
223 check_exclude_decl(
224 r#"
225 namespace Test {
226 newtype Bar = (fst : Int, snd : Int);
227 operation Foo(x : ◉B↘ar◉) : Unit {
228 let bar = ◉Bar◉(1, 2);
229 let baz = bar::fst;
230 }
231 }
232 "#,
233 );
234}
235
236#[test]
237fn std_udt_ref() {
238 check_with_std(
239 indoc! {r#"
240 namespace Test {
241 open FakeStdLib;
242 operation Foo(x : U↘dt) : Unit {}
243 }
244 "#},
245 &expect![[r#"
246 [
247 Location {
248 source: "qsharp-library-source:<std>",
249 range: Range {
250 start: Position {
251 line: 5,
252 column: 16,
253 },
254 end: Position {
255 line: 5,
256 column: 19,
257 },
258 },
259 },
260 Location {
261 source: "<source>",
262 range: Range {
263 start: Position {
264 line: 2,
265 column: 22,
266 },
267 end: Position {
268 line: 2,
269 column: 25,
270 },
271 },
272 },
273 ]
274 "#]],
275 );
276}
277
278#[test]
279fn field_def() {
280 check_include_decl(
281 r#"
282 namespace Test {
283 newtype Bar = (◉f↘st◉ : Int, snd : Int);
284 operation Foo() : Unit {
285 let bar = Bar(1, 2);
286 let baz = bar::◉fst◉;
287 }
288 }
289 "#,
290 );
291}
292
293#[test]
294fn field_ref() {
295 check_include_decl(
296 r#"
297 namespace Test {
298 newtype Bar = (◉fst◉ : Int, snd : Int);
299 operation Foo() : Unit {
300 let bar = Bar(1, 2);
301 let baz = bar::◉f↘st◉;
302 }
303 }
304 "#,
305 );
306}
307
308#[test]
309fn field_exclude_def() {
310 check_exclude_decl(
311 r#"
312 namespace Test {
313 newtype Bar = (fst : Int, snd : Int);
314 operation Foo() : Unit {
315 let bar = Bar(1, 2);
316 let baz = bar::◉f↘st◉;
317 }
318 }
319 "#,
320 );
321}
322
323#[test]
324fn std_field_ref() {
325 check_with_std(
326 indoc! {r#"
327 namespace Test {
328 open FakeStdLib;
329 operation Foo() : Unit {
330 let bar = Udt(1, 2);
331 let baz = bar::↘x;
332 }
333 }
334 "#},
335 &expect![[r#"
336 [
337 Location {
338 source: "qsharp-library-source:<std>",
339 range: Range {
340 start: Position {
341 line: 5,
342 column: 23,
343 },
344 end: Position {
345 line: 5,
346 column: 24,
347 },
348 },
349 },
350 Location {
351 source: "<source>",
352 range: Range {
353 start: Position {
354 line: 4,
355 column: 23,
356 },
357 end: Position {
358 line: 4,
359 column: 24,
360 },
361 },
362 },
363 ]
364 "#]],
365 );
366}
367
368#[test]
369fn struct_def() {
370 check_include_decl(
371 r#"
372 namespace Test {
373 struct ◉B↘ar◉ { fst : Int, snd : Int }
374 operation Foo(x : ◉Bar◉) : Unit {
375 let bar = ◉Bar◉(1, 2);
376 let bar = new ◉Bar◉ { fst = 1, snd = 2 };
377 let baz = bar::fst;
378 }
379 }
380 "#,
381 );
382}
383
384#[test]
385fn struct_ref() {
386 check_include_decl(
387 r#"
388 namespace Test {
389 struct ◉Bar◉ { fst : Int, snd : Int }
390 operation Foo(x : ◉B↘ar◉) : Unit {
391 let bar = ◉Bar◉(1, 2);
392 let bar = new ◉Bar◉ { fst = 1, snd = 2 };
393 let baz = bar::fst;
394 }
395 }
396 "#,
397 );
398}
399
400#[test]
401fn struct_ref_fn_constructor() {
402 check_include_decl(
403 r#"
404 namespace Test {
405 struct ◉Bar◉ { fst : Int, snd : Int }
406 operation Foo(x : ◉Bar◉) : Unit {
407 let bar = ◉B↘ar◉(1, 2);
408 let bar = new ◉Bar◉ { fst = 1, snd = 2 };
409 let baz = bar::fst;
410 }
411 }
412 "#,
413 );
414}
415
416#[test]
417fn struct_exclude_def() {
418 check_exclude_decl(
419 r#"
420 namespace Test {
421 struct Bar { fst : Int, snd : Int }
422 operation Foo(x : ◉B↘ar◉) : Unit {
423 let bar = ◉Bar◉(1, 2);
424 let bar = new ◉Bar◉ { fst = 1, snd = 2 };
425 let baz = bar::fst;
426 }
427 }
428 "#,
429 );
430}
431
432#[test]
433fn std_struct_ref() {
434 check_with_std(
435 indoc! {r#"
436 namespace Test {
437 open FakeStdLib;
438 operation Foo(x : Fak↘eStruct) : Unit {}
439 }
440 "#},
441 &expect![[r#"
442 [
443 Location {
444 source: "qsharp-library-source:<std>",
445 range: Range {
446 start: Position {
447 line: 17,
448 column: 15,
449 },
450 end: Position {
451 line: 17,
452 column: 25,
453 },
454 },
455 },
456 Location {
457 source: "<source>",
458 range: Range {
459 start: Position {
460 line: 2,
461 column: 22,
462 },
463 end: Position {
464 line: 2,
465 column: 32,
466 },
467 },
468 },
469 ]
470 "#]],
471 );
472}
473
474#[test]
475fn struct_field_def() {
476 check_include_decl(
477 r#"
478 namespace Test {
479 struct Bar { ◉f↘st◉ : Int, snd : Int }
480 operation Foo() : Unit {
481 let bar = new Bar { ◉fst◉ = 1, snd = 2 };
482 let baz = bar::◉fst◉;
483 }
484 }
485 "#,
486 );
487}
488
489#[test]
490fn struct_field_ref() {
491 check_include_decl(
492 r#"
493 namespace Test {
494 struct Bar { ◉fst◉ : Int, snd : Int }
495 operation Foo() : Unit {
496 let bar = new Bar { ◉fst◉ = 1, snd = 2 };
497 let baz = bar::◉f↘st◉;
498 }
499 }
500 "#,
501 );
502}
503
504#[test]
505fn struct_field_ref_cons() {
506 check_include_decl(
507 r#"
508 namespace Test {
509 struct Bar { ◉fst◉ : Int, snd : Int }
510 operation Foo() : Unit {
511 let bar = new Bar { ◉f↘st◉ = 1, snd = 2 };
512 let baz = bar::◉fst◉;
513 }
514 }
515 "#,
516 );
517}
518
519#[test]
520fn struct_field_exclude_def() {
521 check_exclude_decl(
522 r#"
523 namespace Test {
524 struct Bar { fst : Int, snd : Int }
525 operation Foo() : Unit {
526 let bar = new Bar { ◉fst◉ = 1, snd = 2 };
527 let baz = bar::◉f↘st◉;
528 }
529 }
530 "#,
531 );
532}
533
534#[test]
535fn std_struct_field_ref() {
536 check_with_std(
537 indoc! {r#"
538 namespace Test {
539 open FakeStdLib;
540 operation Foo() : Unit {
541 let bar = new FakeStruct { x = 1, y = 2 };
542 let baz = bar::↘x;
543 }
544 }
545 "#},
546 &expect![[r#"
547 [
548 Location {
549 source: "qsharp-library-source:<std>",
550 range: Range {
551 start: Position {
552 line: 17,
553 column: 28,
554 },
555 end: Position {
556 line: 17,
557 column: 29,
558 },
559 },
560 },
561 Location {
562 source: "<source>",
563 range: Range {
564 start: Position {
565 line: 3,
566 column: 35,
567 },
568 end: Position {
569 line: 3,
570 column: 36,
571 },
572 },
573 },
574 Location {
575 source: "<source>",
576 range: Range {
577 start: Position {
578 line: 4,
579 column: 23,
580 },
581 end: Position {
582 line: 4,
583 column: 24,
584 },
585 },
586 },
587 ]
588 "#]],
589 );
590}
591
592#[test]
593fn struct_field_path_def() {
594 check_include_decl(
595 r#"
596 namespace Test {
597 struct A { b : B }
598 struct B { ◉c◉ : C }
599 struct C { i : Int }
600 operation Foo(a : A) : Unit {
601 let x = { a.b.◉c◉ }.i;
602 let y = a.b.◉↘c◉.i;
603 }
604 }
605 "#,
606 );
607}
608
609#[test]
610fn struct_field_path_ref() {
611 check_include_decl(
612 r#"
613 namespace Test {
614 struct A { b : B }
615 struct B { ◉c◉ : C }
616 struct C { i : Int }
617 operation Foo(a : A) : Unit {
618 let x = { a.b.◉c◉ }.i;
619 let y = a.b.◉↘c◉.i;
620 }
621 }
622 "#,
623 );
624}
625
626#[test]
627fn struct_field_path_ref_exclude_def() {
628 check_exclude_decl(
629 r#"
630 namespace Test {
631 struct A { b : B }
632 struct B { c : C }
633 struct C { i : Int }
634 operation Foo(a : A) : Unit {
635 let x = { a.b.◉c◉ }.i;
636 let y = a.b.◉↘c◉.i;
637 }
638 }
639 "#,
640 );
641}
642
643#[test]
644fn std_struct_field_path_ref() {
645 check_with_std(
646 indoc! {r#"
647 namespace Test {
648 open FakeStdLib;
649 operation Foo() : Unit {
650 let bar = new FakeStruct { x = 1, y = 2 };
651 let baz = bar.↘x;
652 }
653 }
654 "#},
655 &expect![[r#"
656 [
657 Location {
658 source: "qsharp-library-source:<std>",
659 range: Range {
660 start: Position {
661 line: 17,
662 column: 28,
663 },
664 end: Position {
665 line: 17,
666 column: 29,
667 },
668 },
669 },
670 Location {
671 source: "<source>",
672 range: Range {
673 start: Position {
674 line: 3,
675 column: 35,
676 },
677 end: Position {
678 line: 3,
679 column: 36,
680 },
681 },
682 },
683 Location {
684 source: "<source>",
685 range: Range {
686 start: Position {
687 line: 4,
688 column: 22,
689 },
690 end: Position {
691 line: 4,
692 column: 23,
693 },
694 },
695 },
696 ]
697 "#]],
698 );
699}
700
701#[test]
702fn std_struct_field_path_with_expr_ref() {
703 check_with_std(
704 indoc! {r#"
705 namespace Test {
706 open FakeStdLib;
707 operation Foo() : Unit {
708 let bar = new FakeStruct { x = 1, y = 2 };
709 let baz = { bar }.↘x;
710 }
711 }
712 "#},
713 &expect![[r#"
714 [
715 Location {
716 source: "qsharp-library-source:<std>",
717 range: Range {
718 start: Position {
719 line: 17,
720 column: 28,
721 },
722 end: Position {
723 line: 17,
724 column: 29,
725 },
726 },
727 },
728 Location {
729 source: "<source>",
730 range: Range {
731 start: Position {
732 line: 3,
733 column: 35,
734 },
735 end: Position {
736 line: 3,
737 column: 36,
738 },
739 },
740 },
741 Location {
742 source: "<source>",
743 range: Range {
744 start: Position {
745 line: 4,
746 column: 26,
747 },
748 end: Position {
749 line: 4,
750 column: 27,
751 },
752 },
753 },
754 ]
755 "#]],
756 );
757}
758
759#[test]
760fn local_def() {
761 check_include_decl(
762 r#"
763 namespace Test {
764 operation Foo() : Unit {
765 let ◉z↘ip◉ = 3;
766 let zap = ◉zip◉;
767 }
768 operation Bar() : Unit {
769 let zip = 3;
770 let zap = zip;
771 }
772 }
773 "#,
774 );
775}
776
777#[test]
778fn local_ref() {
779 check_include_decl(
780 r#"
781 namespace Test {
782 operation Foo() : Unit {
783 let ◉zip◉ = 3;
784 let zap = ◉z↘ip◉;
785 }
786 operation Bar() : Unit {
787 let zip = 3;
788 let zap = zip;
789 }
790 }
791 "#,
792 );
793}
794
795#[test]
796fn param_def() {
797 check_include_decl(
798 r#"
799 namespace Test {
800 operation Foo(◉b↘ar◉ : Int) : Unit {
801 let lambda = (bar, baz) => {
802 let zip = bar;
803 }
804 let zip = ◉bar◉;
805 }
806 }
807 "#,
808 );
809}
810
811#[test]
812fn param_ref() {
813 check_include_decl(
814 r#"
815 namespace Test {
816 operation Foo(bar : Int) : Unit {
817 let lambda = (◉bar◉, baz) => {
818 let zip = ◉b↘ar◉;
819 }
820 let zip = bar;
821 }
822 }
823 "#,
824 );
825}
826
827#[test]
828fn local_shadow_def() {
829 check_include_decl(
830 r#"
831 namespace Test {
832 operation Foo() : Unit {
833 let bar = 3;
834 {
835 let ◉b↘ar◉ = 2.0;
836 let baz = ◉bar◉;
837 }
838 let baz = bar;
839 }
840 }
841 "#,
842 );
843}
844
845#[test]
846fn local_shadow_ref() {
847 check_include_decl(
848 r#"
849 namespace Test {
850 operation Foo() : Unit {
851 let bar = 3;
852 {
853 let ◉bar◉ = 2.0;
854 let baz = ◉ba↘r◉;
855 }
856 let baz = bar;
857 }
858 }
859 "#,
860 );
861}
862
863#[test]
864fn local_exclude_def() {
865 check_exclude_decl(
866 r#"
867 namespace Test {
868 operation Foo() : Unit {
869 let b↘ar = 3;
870 let baz = ◉bar◉;
871 }
872 }
873 "#,
874 );
875}
876
877#[test]
878fn ty_param_def() {
879 check_include_decl(
880 r#"
881 namespace Test {
882 operation Foo<◉'↘T◉>(x : ◉'T◉) : ◉'T◉ { x }
883 }
884 "#,
885 );
886}
887
888#[test]
889fn ty_param_ref() {
890 check_include_decl(
891 r#"
892 namespace Test {
893 operation Foo<◉'T◉>(x : ◉'↘T◉) : ◉'T◉ { x }
894 }
895 "#,
896 );
897}
898
899#[test]
900fn notebook_across_cells() {
901 check_notebook_exclude_decl(&[
902 ("cell1", "operation Callee() : Unit {}"),
903 ("cell2", "◉C↘allee◉();"),
904 ("cell3", "◉Callee◉();"),
905 ]);
906}
907
908#[test]
909fn notebook_defined_in_later_cell() {
910 check_notebook_exclude_decl(&[
911 ("cell1", "C↘allee();"),
912 ("cell2", "operation Callee() : Unit {}"),
913 ]);
914}
915
916#[test]
917fn notebook_local_definition() {
918 check_notebook_exclude_decl(&[
919 ("cell1", "let ↘x = 3; let y = ◉x◉ + 1;"),
920 ("cell2", "let z = ◉x◉ + 2;"),
921 ]);
922}
923
924#[test]
925fn notebook_local_reference() {
926 check_notebook_exclude_decl(&[
927 ("cell1", "let x = 3; let y = ◉x◉ + 1;"),
928 ("cell2", "let z = ◉↘x◉ + 2;"),
929 ]);
930}
931
932#[test]
933fn on_item_declaration_finds_all_usages() {
934 check_include_decl(indoc! {"
935 namespace Base {
936 operation ◉b↘1◉() : Unit {}
937 export
938 ◉b1◉,
939 ◉b1◉ as ◉b2◉;
940 }
941 namespace Intermediate {
942 import
943 Base.◉b1◉,
944 Base.◉b1◉ as ◉i1◉,
945 Base.◉b2◉,
946 Base.◉b2◉ as ◉i2◉;
947 export
948 Base.◉b1◉,
949 Base.◉b2◉,
950 ◉i1◉,
951 ◉i2◉;
952 }
953 namespace Usage1 {
954 import
955 Base.◉b1◉,
956 Base.◉b1◉ as ◉u1◉,
957 Base.◉b2◉,
958 Base.◉b2◉ as ◉u2◉,
959 Intermediate.◉b1◉ as ◉u3◉,
960 Intermediate.◉b2◉ as ◉u4◉,
961 Intermediate.◉i1◉,
962 Intermediate.◉i1◉ as ◉u5◉,
963 Intermediate.◉i2◉,
964 Intermediate.◉i2◉ as ◉u6◉;
965 operation useOp() : Unit {
966 ◉b1◉();
967 ◉b2◉();
968 ◉i1◉();
969 ◉i2◉();
970 ◉u1◉();
971 ◉u2◉();
972 ◉u3◉();
973 ◉u4◉();
974 ◉u5◉();
975 ◉u6◉();
976 }
977 }
978 namespace Usage2 {
979 import
980 Intermediate.◉b1◉,
981 Intermediate.◉b2◉;
982 operation useOp() : Unit {
983 ◉b1◉();
984 ◉b2◉();
985 }
986 }
987 "});
988}
989
990#[test]
991fn on_item_export_path_finds_all_usages() {
992 check_include_decl(indoc! {"
993 namespace Base {
994 operation ◉b1◉() : Unit {}
995 export
996 ◉b↘1◉,
997 ◉b1◉ as ◉b2◉;
998 }
999 namespace Intermediate {
1000 import
1001 Base.◉b1◉,
1002 Base.◉b1◉ as ◉i1◉,
1003 Base.◉b2◉,
1004 Base.◉b2◉ as ◉i2◉;
1005 export
1006 Base.◉b1◉,
1007 Base.◉b2◉,
1008 ◉i1◉,
1009 ◉i2◉;
1010 }
1011 namespace Usage1 {
1012 import
1013 Base.◉b1◉,
1014 Base.◉b1◉ as ◉u1◉,
1015 Base.◉b2◉,
1016 Base.◉b2◉ as ◉u2◉,
1017 Intermediate.◉b1◉ as ◉u3◉,
1018 Intermediate.◉b2◉ as ◉u4◉,
1019 Intermediate.◉i1◉,
1020 Intermediate.◉i1◉ as ◉u5◉,
1021 Intermediate.◉i2◉,
1022 Intermediate.◉i2◉ as ◉u6◉;
1023 operation useOp() : Unit {
1024 ◉b1◉();
1025 ◉b2◉();
1026 ◉i1◉();
1027 ◉i2◉();
1028 ◉u1◉();
1029 ◉u2◉();
1030 ◉u3◉();
1031 ◉u4◉();
1032 ◉u5◉();
1033 ◉u6◉();
1034 }
1035 }
1036 namespace Usage2 {
1037 import
1038 Intermediate.◉b1◉,
1039 Intermediate.◉b2◉;
1040 operation useOp() : Unit {
1041 ◉b1◉();
1042 ◉b2◉();
1043 }
1044 }
1045 "});
1046}
1047
1048#[test]
1049fn on_item_export_alias_finds_all_usages() {
1050 check_include_decl(indoc! {"
1051 namespace Base {
1052 operation ◉b1◉() : Unit {}
1053 export
1054 ◉b1◉,
1055 ◉b1◉ as ◉b↘2◉;
1056 }
1057 namespace Intermediate {
1058 import
1059 Base.◉b1◉,
1060 Base.◉b1◉ as ◉i1◉,
1061 Base.◉b2◉,
1062 Base.◉b2◉ as ◉i2◉;
1063 export
1064 Base.◉b1◉,
1065 Base.◉b2◉,
1066 ◉i1◉,
1067 ◉i2◉;
1068 }
1069 namespace Usage1 {
1070 import
1071 Base.◉b1◉,
1072 Base.◉b1◉ as ◉u1◉,
1073 Base.◉b2◉,
1074 Base.◉b2◉ as ◉u2◉,
1075 Intermediate.◉b1◉ as ◉u3◉,
1076 Intermediate.◉b2◉ as ◉u4◉,
1077 Intermediate.◉i1◉,
1078 Intermediate.◉i1◉ as ◉u5◉,
1079 Intermediate.◉i2◉,
1080 Intermediate.◉i2◉ as ◉u6◉;
1081 operation useOp() : Unit {
1082 ◉b1◉();
1083 ◉b2◉();
1084 ◉i1◉();
1085 ◉i2◉();
1086 ◉u1◉();
1087 ◉u2◉();
1088 ◉u3◉();
1089 ◉u4◉();
1090 ◉u5◉();
1091 ◉u6◉();
1092 }
1093 }
1094 namespace Usage2 {
1095 import
1096 Intermediate.◉b1◉,
1097 Intermediate.◉b2◉;
1098 operation useOp() : Unit {
1099 ◉b1◉();
1100 ◉b2◉();
1101 }
1102 }
1103 "});
1104}
1105
1106#[test]
1107fn on_item_import_finds_all_usages() {
1108 check_include_decl(indoc! {"
1109 namespace Base {
1110 operation ◉b1◉() : Unit {}
1111 export
1112 ◉b1◉,
1113 ◉b1◉ as ◉b2◉;
1114 }
1115 namespace Intermediate {
1116 import
1117 Base.◉b↘1◉,
1118 Base.◉b1◉ as ◉i1◉,
1119 Base.◉b2◉,
1120 Base.◉b2◉ as ◉i2◉;
1121 export
1122 Base.◉b1◉,
1123 Base.◉b2◉,
1124 ◉i1◉,
1125 ◉i2◉;
1126 }
1127 namespace Usage1 {
1128 import
1129 Base.◉b1◉,
1130 Base.◉b1◉ as ◉u1◉,
1131 Base.◉b2◉,
1132 Base.◉b2◉ as ◉u2◉,
1133 Intermediate.◉b1◉ as ◉u3◉,
1134 Intermediate.◉b2◉ as ◉u4◉,
1135 Intermediate.◉i1◉,
1136 Intermediate.◉i1◉ as ◉u5◉,
1137 Intermediate.◉i2◉,
1138 Intermediate.◉i2◉ as ◉u6◉;
1139 operation useOp() : Unit {
1140 ◉b1◉();
1141 ◉b2◉();
1142 ◉i1◉();
1143 ◉i2◉();
1144 ◉u1◉();
1145 ◉u2◉();
1146 ◉u3◉();
1147 ◉u4◉();
1148 ◉u5◉();
1149 ◉u6◉();
1150 }
1151 }
1152 namespace Usage2 {
1153 import
1154 Intermediate.◉b1◉,
1155 Intermediate.◉b2◉;
1156 operation useOp() : Unit {
1157 ◉b1◉();
1158 ◉b2◉();
1159 }
1160 }
1161 "});
1162}
1163
1164#[test]
1165fn on_item_import_alias_finds_all_usages() {
1166 check_include_decl(indoc! {"
1167 namespace Base {
1168 operation ◉b1◉() : Unit {}
1169 export
1170 ◉b1◉,
1171 ◉b1◉ as ◉b2◉;
1172 }
1173 namespace Intermediate {
1174 import
1175 Base.◉b1◉,
1176 Base.◉b1◉ as ◉i↘1◉,
1177 Base.◉b2◉,
1178 Base.◉b2◉ as ◉i2◉;
1179 export
1180 Base.◉b1◉,
1181 Base.◉b2◉,
1182 ◉i1◉,
1183 ◉i2◉;
1184 }
1185 namespace Usage1 {
1186 import
1187 Base.◉b1◉,
1188 Base.◉b1◉ as ◉u1◉,
1189 Base.◉b2◉,
1190 Base.◉b2◉ as ◉u2◉,
1191 Intermediate.◉b1◉ as ◉u3◉,
1192 Intermediate.◉b2◉ as ◉u4◉,
1193 Intermediate.◉i1◉,
1194 Intermediate.◉i1◉ as ◉u5◉,
1195 Intermediate.◉i2◉,
1196 Intermediate.◉i2◉ as ◉u6◉;
1197 operation useOp() : Unit {
1198 ◉b1◉();
1199 ◉b2◉();
1200 ◉i1◉();
1201 ◉i2◉();
1202 ◉u1◉();
1203 ◉u2◉();
1204 ◉u3◉();
1205 ◉u4◉();
1206 ◉u5◉();
1207 ◉u6◉();
1208 }
1209 }
1210 namespace Usage2 {
1211 import
1212 Intermediate.◉b1◉,
1213 Intermediate.◉b2◉;
1214 operation useOp() : Unit {
1215 ◉b1◉();
1216 ◉b2◉();
1217 }
1218 }
1219 "});
1220}
1221
1222#[test]
1223fn on_item_import_usage_finds_all_usages() {
1224 check_include_decl(indoc! {"
1225 namespace Base {
1226 operation ◉b1◉() : Unit {}
1227 export
1228 ◉b1◉,
1229 ◉b1◉ as ◉b2◉;
1230 }
1231 namespace Intermediate {
1232 import
1233 Base.◉b1◉,
1234 Base.◉b1◉ as ◉i1◉,
1235 Base.◉b2◉,
1236 Base.◉b2◉ as ◉i2◉;
1237 export
1238 Base.◉b1◉,
1239 Base.◉b2◉,
1240 ◉i1◉,
1241 ◉i2◉;
1242 }
1243 namespace Usage1 {
1244 import
1245 Base.◉b1◉,
1246 Base.◉b1◉ as ◉u1◉,
1247 Base.◉b2◉,
1248 Base.◉b2◉ as ◉u2◉,
1249 Intermediate.◉b1◉ as ◉u3◉,
1250 Intermediate.◉b2◉ as ◉u4◉,
1251 Intermediate.◉i1◉,
1252 Intermediate.◉i1◉ as ◉u5◉,
1253 Intermediate.◉i2◉,
1254 Intermediate.◉i2◉ as ◉u6◉;
1255 operation useOp() : Unit {
1256 ◉b1◉();
1257 ◉b2◉();
1258 ◉i1◉();
1259 ◉i2◉();
1260 ◉u1◉();
1261 ◉u2◉();
1262 ◉u3◉();
1263 ◉u4◉();
1264 ◉u5◉();
1265 ◉u6◉();
1266 }
1267 }
1268 namespace Usage2 {
1269 import
1270 Intermediate.◉b1◉,
1271 Intermediate.◉b2◉;
1272 operation useOp() : Unit {
1273 ◉b↘1◉();
1274 ◉b2◉();
1275 }
1276 }
1277 "});
1278}
1279