Example #1
0
        public void Selection_Not_Contains_LastToken()
        {
            const string inputCode = @"
Option Explicit

Public Sub foo(Bar As Long, Baz As Long)

If Bar > Baz Then
  Debug.Print ""Yeah!""
Else
  Debug.Print ""Boo!""
End If

If Baz > Bar Then
  Debug.Print ""Boo!""
Else
  Debug.Print ""Yeah!""
End If

End Sub : 'Lame comment!
";

            var vbe       = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out var component);
            var pane      = component.CodeModule.CodePane;
            var state     = MockParser.CreateAndParse(vbe.Object);
            var tree      = state.GetParseTree(new QualifiedModuleName(component));
            var visitor   = new IfStmtContextElementCollectorVisitor();
            var context   = visitor.Visit(tree).Last();
            var token     = context.Stop;
            var selection = new Selection(12, 1, 14, 1);

            Assert.IsFalse(selection.Contains(token));
        }
Example #2
0
        public void Context_In_Selection_SecondBlock_OneBased()
        {
            const string inputCode = @"
Option Explicit

Public Sub foo(Bar As Long, Baz As Long)

If Bar > Baz Then
  Debug.Print ""Yeah!""
Else
  Debug.Print ""Boo!""
End If

If Baz > Bar Then
  Debug.Print ""Boo!""
Else
  Debug.Print ""Yeah!""
End If

End Sub : 'Lame comment!
";

            var vbe       = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out var component);
            var pane      = component.CodeModule.CodePane;
            var state     = MockParser.CreateAndParse(vbe.Object);
            var tree      = state.GetParseTree(new QualifiedModuleName(component));
            var visitor   = new IfStmtContextElementCollectorVisitor();
            var contexts  = visitor.Visit(tree);
            var selection = new Selection(12, 1, 16, 7);

            Assert.IsFalse(selection.Contains(contexts.ElementAt(0)));  // first If block
            Assert.IsTrue(selection.Contains(contexts.ElementAt(1)));   // second If block
        }
Example #3
0
        public void Selection_Not_Contained_In_Neither_Nested_Context()
        {
            const string inputCode = @"
Option Explicit

Public Sub foo(Bar As Long, Baz As Long, FooBar As Long)

If Bar > Baz Then
  Debug.Print ""Yeah!""
  If FooBar Then
     Debug.Print ""Foo bar!""
  End If
Else
  Debug.Print ""Boo!""
End If

If Baz > Bar Then
  Debug.Print ""Boo!""
Else
  Debug.Print ""Yeah!""
End If

End Sub : 'Lame comment!
";

            var vbe  = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out var component);
            var pane = component.CodeModule.CodePane;

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var tree      = state.GetParseTree(new QualifiedModuleName(component));
                var visitor   = new IfStmtContextElementCollectorVisitor();
                var contexts  = visitor.Visit(tree); //returns innermost statement first then topmost consecutively
                var token     = contexts.ElementAt(0).Stop;
                var selection = new Selection(15, 1, 19, 7);

                Assert.IsFalse(selection.Contains(token));                  // last token in innermost If block
                Assert.IsFalse(selection.Contains(contexts.ElementAt(0)));  // innermost If block
                Assert.IsFalse(selection.Contains(contexts.ElementAt(1)));  // first outer if block
                Assert.IsTrue(selection.Contains(contexts.ElementAt(2)));   // second outer If block
            }
        }