@@ -532,7 +532,217 @@ Dim sht As WorkSheet
532
532
Assert . AreEqual ( expected , actual ) ;
533
533
}
534
534
535
- private ( Declaration specifiedDeclaration , Declaration selectedDeclaration ) DeclarationsFromParse (
535
+ [ Category ( "Resolver" ) ]
536
+ [ Test ]
537
+ public void SelectionInsideConstantDeclaration_ConstantSelected ( )
538
+ {
539
+ const string code = @"
540
+ Private Const myConst As Long = 42
541
+
542
+ Private myModuleVariable As Long
543
+
544
+
545
+ Public Sub DoIt()
546
+ Dim myLocalVariable As Long
547
+
548
+ myModuleVariable = myLocalVariable
549
+ End Sub" ;
550
+ var vbe = new MockVbeBuilder ( )
551
+ . ProjectBuilder ( "TestProject" , ProjectProtection . Unprotected )
552
+ . AddComponent ( "TestModule" , ComponentType . StandardModule , code , new Selection ( 2 , 2 ) )
553
+ . AddProjectToVbeBuilder ( )
554
+ . Build ( ) ;
555
+
556
+ var ( expected , actual ) = DeclarationsFromParse ( vbe . Object , DeclarationType . Constant , "myConst" ) ;
557
+
558
+ Assert . AreEqual ( expected , actual ) ;
559
+ }
560
+
561
+ [ Category ( "Resolver" ) ]
562
+ [ Test ]
563
+ [ TestCase ( 4 , 2 , "myModuleVariable" ) ]
564
+ [ TestCase ( 8 , 6 , "myLocalVariable" ) ]
565
+ public void SelectionInsideVariableDeclaration_VariableSelected ( int selectedLine , int selectedColumn , string expectedVariableName )
566
+ {
567
+ const string code = @"
568
+ Private Const myConst As Long = 42
569
+
570
+ Private myModuleVariable As Long
571
+
572
+
573
+ Public Sub DoIt()
574
+ Dim myLocalVariable As Long
575
+
576
+ myModuleVariable = myLocalVariable
577
+ End Sub" ;
578
+ var vbe = new MockVbeBuilder ( )
579
+ . ProjectBuilder ( "TestProject" , ProjectProtection . Unprotected )
580
+ . AddComponent ( "TestModule" , ComponentType . StandardModule , code , new Selection ( selectedLine , selectedColumn ) )
581
+ . AddProjectToVbeBuilder ( )
582
+ . Build ( ) ;
583
+
584
+ var ( expected , actual ) = DeclarationsFromParse ( vbe . Object , DeclarationType . Variable , expectedVariableName ) ;
585
+
586
+ Assert . AreEqual ( expected , actual ) ;
587
+ }
588
+
589
+ [ Category ( "Resolver" ) ]
590
+ [ Test ]
591
+ public void SelectionInsideModuleBodyElementAndOnNothingElse_ModuleBodyElementSelected ( )
592
+ {
593
+ const string code = @"
594
+ Private Const myConst As Long = 42
595
+
596
+ Private myModuleVariable As Long
597
+
598
+
599
+ Public Sub DoIt()
600
+ Dim myLocalVariable As Long
601
+
602
+ myModuleVariable = myLocalVariable
603
+ End Sub" ;
604
+ var vbe = new MockVbeBuilder ( )
605
+ . ProjectBuilder ( "TestProject" , ProjectProtection . Unprotected )
606
+ . AddComponent ( "TestModule" , ComponentType . StandardModule , code , new Selection ( 9 , 5 ) )
607
+ . AddProjectToVbeBuilder ( )
608
+ . Build ( ) ;
609
+
610
+ var ( expected , actual ) = DeclarationsFromParse ( vbe . Object , DeclarationType . Procedure , "DoIt" ) ;
611
+
612
+ Assert . AreEqual ( expected , actual ) ;
613
+ }
614
+
615
+ [ Category ( "Resolver" ) ]
616
+ [ Test ]
617
+ public void SelectionInsideVariableDeclaringReDimButNotOnIdentifier_ContainingModuleBodyElementSelected ( )
618
+ {
619
+ const string code = @"
620
+ Private Const myConst As Long = 42
621
+
622
+ Private myModuleVariable As Long
623
+
624
+
625
+ Public Sub DoIt()
626
+ ReDim arr(23 To 42) As Long
627
+
628
+ myModuleVariable = arr(33)
629
+ End Sub" ;
630
+ var vbe = new MockVbeBuilder ( )
631
+ . ProjectBuilder ( "TestProject" , ProjectProtection . Unprotected )
632
+ . AddComponent ( "TestModule" , ComponentType . StandardModule , code , new Selection ( 8 , 7 ) )
633
+ . AddProjectToVbeBuilder ( )
634
+ . Build ( ) ;
635
+
636
+ var ( expected , actual ) = DeclarationsFromParse ( vbe . Object , DeclarationType . Procedure , "DoIt" ) ;
637
+
638
+ Assert . AreEqual ( expected , actual ) ;
639
+ }
640
+
641
+ [ Category ( "Resolver" ) ]
642
+ [ Test ]
643
+ public void SelectionInsideVariableDeclarationStatementForMultipleLocalVariables_ContainingModuleBodyElementSelected ( )
644
+ {
645
+ const string code = @"
646
+ Private Const myConst As Long = 42
647
+
648
+ Private myModuleVariable As Long
649
+
650
+
651
+ Public Sub DoIt()
652
+ Dim myLocalVariable As Long, myOtherLocalVariable As String
653
+
654
+ myModuleVariable = myLocalVariable
655
+ End Sub" ;
656
+ var vbe = new MockVbeBuilder ( )
657
+ . ProjectBuilder ( "TestProject" , ProjectProtection . Unprotected )
658
+ . AddComponent ( "TestModule" , ComponentType . StandardModule , code , new Selection ( 8 , 6 ) )
659
+ . AddProjectToVbeBuilder ( )
660
+ . Build ( ) ;
661
+
662
+ var ( expected , actual ) = DeclarationsFromParse ( vbe . Object , DeclarationType . Procedure , "DoIt" ) ;
663
+
664
+ Assert . AreEqual ( expected , actual ) ;
665
+ }
666
+
667
+ [ Category ( "Resolver" ) ]
668
+ [ Test ]
669
+ public void SelectionOutsideModuleBodyElementAndOnNothingElse_ModuleSelected ( )
670
+ {
671
+ const string code = @"
672
+ Private Const myConst As Long = 42
673
+
674
+ Private myModuleVariable As Long
675
+
676
+
677
+ Public Sub DoIt()
678
+ Dim myLocalVariable As Long
679
+
680
+ myModuleVariable = myLocalVariable
681
+ End Sub" ;
682
+ var vbe = new MockVbeBuilder ( )
683
+ . ProjectBuilder ( "TestProject" , ProjectProtection . Unprotected )
684
+ . AddComponent ( "TestModule" , ComponentType . StandardModule , code , new Selection ( 6 , 1 ) )
685
+ . AddProjectToVbeBuilder ( )
686
+ . Build ( ) ;
687
+
688
+ var ( expected , actual ) = DeclarationsFromParse ( vbe . Object , DeclarationType . ProceduralModule , "TestModule" ) ;
689
+
690
+ Assert . AreEqual ( expected , actual ) ;
691
+ }
692
+
693
+ [ Category ( "Resolver" ) ]
694
+ [ Test ]
695
+ public void SelectionInsideVariableDeclarationStatementForMultipleModuleVariables_ModuleSelected ( )
696
+ {
697
+ const string code = @"
698
+ Private Const myConst As Long = 42
699
+
700
+ Private myModuleVariable As Long, myOtherModuleVariable As String
701
+
702
+
703
+ Public Sub DoIt()
704
+ Dim myLocalVariable As Long
705
+
706
+ myModuleVariable = myLocalVariable
707
+ End Sub" ;
708
+ var vbe = new MockVbeBuilder ( )
709
+ . ProjectBuilder ( "TestProject" , ProjectProtection . Unprotected )
710
+ . AddComponent ( "TestModule" , ComponentType . StandardModule , code , new Selection ( 4 , 2 ) )
711
+ . AddProjectToVbeBuilder ( )
712
+ . Build ( ) ;
713
+
714
+ var ( expected , actual ) = DeclarationsFromParse ( vbe . Object , DeclarationType . ProceduralModule , "TestModule" ) ;
715
+
716
+ Assert . AreEqual ( expected , actual ) ;
717
+ }
718
+
719
+ [ Category ( "Resolver" ) ]
720
+ [ Test ]
721
+ public void SelectionInsideConstantDeclarationStatementForMultipleModuleConstants_ModuleSelected ( )
722
+ {
723
+ const string code = @"
724
+ Private Const myConst As Long = 42, myOtherConstant As Long = 23
725
+
726
+ Private myModuleVariable As Long
727
+
728
+
729
+ Public Sub DoIt()
730
+ Dim myLocalVariable As Long
731
+
732
+ myModuleVariable = myLocalVariable
733
+ End Sub" ;
734
+ var vbe = new MockVbeBuilder ( )
735
+ . ProjectBuilder ( "TestProject" , ProjectProtection . Unprotected )
736
+ . AddComponent ( "TestModule" , ComponentType . StandardModule , code , new Selection ( 2 , 2 ) )
737
+ . AddProjectToVbeBuilder ( )
738
+ . Build ( ) ;
739
+
740
+ var ( expected , actual ) = DeclarationsFromParse ( vbe . Object , DeclarationType . ProceduralModule , "TestModule" ) ;
741
+
742
+ Assert . AreEqual ( expected , actual ) ;
743
+ }
744
+
745
+ private static ( Declaration specifiedDeclaration , Declaration selectedDeclaration ) DeclarationsFromParse (
536
746
IVBE vbe ,
537
747
DeclarationType declarationType ,
538
748
string declarationName ,
0 commit comments