public void VerticalSpacing_InsertBlankLinesWorksWithTypes()
        {
            var code = new[]
            {
                "Type Foo",
                "End Type",
                "Function TestFunction() As Long",
                "End Function",
                "Sub TestSub()",
                "End Sub"
            };

            var expected = new[]
            {
                "Type Foo",
                "End Type",
                "",
                "Function TestFunction() As Long",
                "End Function",
                "",
                "Sub TestSub()",
                "End Sub"
            };

            var indenter = new Indenter(null, () =>
            {
                var s = IndenterSettingsTests.GetMockIndenterSettings();
                s.VerticallySpaceProcedures = true;
                s.LinesBetweenProcedures    = 1;
                return(s);
            });
            var actual = indenter.Indent(code);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
예제 #2
0
        public void VerticalSpacing_DoesNotChangeSpacingInEnumsOrTypes()
        {
            var code = new[]
            {
                "Enum Foo",
                "",
                "    Bar",
                "    Baz",
                "",
                "",
                "End Enum",
                "",
                "Type Test",
                "",
                "    MemberOne As String",
                "    MemberTwo As Long",
                "",
                "",
                "",
                "End Type",
                "Sub TestSub()",
                "End Sub"
            };

            var expected = new[]
            {
                "Enum Foo",
                "",
                "    Bar",
                "    Baz",
                "",
                "",
                "End Enum",
                "",
                "Type Test",
                "",
                "    MemberOne As String",
                "    MemberTwo As Long",
                "",
                "",
                "",
                "End Type",
                "",
                "Sub TestSub()",
                "End Sub"
            };

            var indenter = new Indenter(null, () =>
            {
                var s = IndenterSettingsTests.GetMockIndenterSettings();
                s.VerticallySpaceProcedures = true;
                s.LinesBetweenProcedures    = 1;
                return(s);
            });
            var actual = indenter.Indent(code);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
        public void ContinuationsInProcedureDeclarationsNoCommentAlignWorks()
        {
            var code = new[]
            {
                "Sub MySub()",
                "Dim x1 As Integer",
                "Dim _",
                "x2 _",
                "As Integer",
                "Dim x3 As _",
                "Integer",
                "Dim x4 _",
                "As _",
                "Integer",
                "Dim x5 As Integer: _",
                "Dim x6 As _",
                "Integer",
                "Dim x7 As Integer _",
                "'Comment _",
                "as _",
                "integer",
                "End Sub"
            };

            //TODO: Not sure if this is what should be expected...
            var expected = new[]
            {
                "Sub MySub()",
                "    Dim x1 As Integer",
                "    Dim _",
                "    x2 _",
                "    As Integer",
                "    Dim x3 As _",
                "    Integer",
                "    Dim x4 _",
                "    As _",
                "    Integer",
                "    Dim x5 As Integer: _",
                "    Dim x6 As _",
                "    Integer",
                "    Dim x7 As Integer _",
                "'Comment _",
                "as _",
                "integer",
                "End Sub"
            };

            var indenter = new Indenter(null, () =>
            {
                var s = IndenterSettingsTests.GetMockIndenterSettings();
                s.AlignCommentsWithCode       = false;
                s.IndentFirstDeclarationBlock = true;
                return(s);
            });
            var actual = indenter.Indent(code, string.Empty);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
예제 #4
0
        public void ContinuationsInProcedureDeclarationsWorks()
        {
            var code = new[]
            {
                "Sub MySub()",
                "Dim x1 As Integer",
                "Dim _",
                "x2 _",
                "As Integer",
                "Dim x3 As _",
                "Integer",
                "Dim x4 _",
                "As _",
                "Integer",
                "Dim x5 As Integer: _",
                "Dim x6 As _",
                "Integer",
                "Dim x7 As Integer _",
                "'Comment _",
                "as _",
                "integer",
                "End Sub"
            };

            var expected = new[]
            {
                "Sub MySub()",
                "    Dim x1 As Integer",
                "    Dim _",
                "    x2 _",
                "    As Integer",
                "    Dim x3 As _",
                "    Integer",
                "    Dim x4 _",
                "    As _",
                "    Integer",
                "    Dim x5 As Integer: _",
                "    Dim x6 As _",
                "    Integer",
                "    Dim x7 As Integer _",
                "        'Comment _",
                "        as _",
                "        integer",
                "End Sub"
            };

            var indenter = new Indenter(null, () =>
            {
                var s = IndenterSettingsTests.GetMockIndenterSettings();
                s.IndentFirstDeclarationBlock = true;
                return(s);
            });
            var actual = indenter.Indent(code);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
예제 #5
0
        public void ContinuationsInTypeDeclarationsWorks()
        {
            var code = new[]
            {
                "Private Type MyType",
                "x1 As Integer",
                "x2 _",
                "As Integer",
                "x3 As _",
                "Integer",
                "x4 _",
                "As _",
                "Integer",
                "x5 As Integer: _",
                "x6 As _",
                "Integer",
                "x7 As Integer _",
                "'Comment _",
                "as _",
                "integer",
                "End Type"
            };

            var expected = new[]
            {
                "Private Type MyType",
                "    x1 As Integer",
                "    x2 _",
                "    As Integer",
                "    x3 As _",
                "    Integer",
                "    x4 _",
                "    As _",
                "    Integer",
                "    x5 As Integer: _",
                "    x6 As _",
                "    Integer",
                "    x7 As Integer _",
                "    'Comment _",
                "    as _",
                "    integer",
                "End Type"
            };

            var indenter = new Indenter(null, () =>
            {
                var s = IndenterSettingsTests.GetMockIndenterSettings();
                s.AlignCommentsWithCode = true;
                return(s);
            });
            var actual = indenter.Indent(code);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
예제 #6
0
        public void BracketedIdentifiersWork()
        {
            var code = new[]
            {
                "Sub test()",
                "Dim _",
                "s _",
                "( _",
                "[Option _ Explicit] _",
                "+ _",
                "1 _",
                "To _",
                "( _",
                "[Evil : \"\" Comment \" 'here] _",
                ") _",
                "+ _",
                "[End _ Sub] _",
                ") _",
                "As _",
                "String _",
                "* _",
                "25",
                "End Sub"
            };

            var expected = new[]
            {
                "Sub test()",
                "    Dim _",
                "    s _",
                "    ( _",
                "    [Option _ Explicit] _",
                "    + _",
                "    1 _",
                "    To _",
                "    ( _",
                "    [Evil : \"\" Comment \" 'here] _",
                "    ) _",
                "    + _",
                "    [End _ Sub] _",
                "    ) _",
                "    As _",
                "    String _",
                "    * _",
                "    25",
                "End Sub"
            };

            var indenter = new Indenter(null, () => IndenterSettingsTests.GetMockIndenterSettings());
            var actual   = indenter.Indent(code);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
        public void VerticalSpacing_GroupMultipleProperties()
        {
            var code = new[]
            {
                "Function TestFunction() As Long",
                "End Function",
                "Public Property Get TestProperty() As Long",
                "End Property",
                "Public Property Let TestProperty(ByVal foo As Long)",
                "End Property",
                "Public Property Get TestProperty2() As Variant",
                "End Property",
                "Public Property Let TestProperty2(ByVal foo As Variant)",
                "End Property",
                "Public Property Set TestProperty2(ByVal foo As Variant)",
                "End Property",
                "Sub TestSub()",
                "End Sub"
            };

            var expected = new[]
            {
                "Function TestFunction() As Long",
                "End Function",
                "",
                "Public Property Get TestProperty() As Long",
                "End Property",
                "Public Property Let TestProperty(ByVal foo As Long)",
                "End Property",
                "",
                "Public Property Get TestProperty2() As Variant",
                "End Property",
                "Public Property Let TestProperty2(ByVal foo As Variant)",
                "End Property",
                "Public Property Set TestProperty2(ByVal foo As Variant)",
                "End Property",
                "",
                "Sub TestSub()",
                "End Sub"
            };

            var indenter = new Indenter(null, () =>
            {
                var s = IndenterSettingsTests.GetMockIndenterSettings();
                s.VerticallySpaceProcedures = true;
                s.LinesBetweenProcedures    = 1;
                s.GroupRelatedProperties    = true;
                return(s);
            });
            var actual = indenter.Indent(code);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
        public void SingleLineTypesNotIndented()
        {
            var code = new[]
            {
                "Public Type Foo: X As Integer: End Type",
                "Public Enum Bar: X = 1: Y = 2: End Enum"
            };

            var indenter = new Indenter(null, () => IndenterSettingsTests.GetMockIndenterSettings());
            var actual   = indenter.Indent(code, string.Empty);

            Assert.IsTrue(code.SequenceEqual(actual));
        }
        public void SingleLineFunctionsNotIndented()
        {
            var code = new[]
            {
                "Private Function Foo(): Foo = 42: End Function",
                "Private Sub Bar(): Debug.Assert Foo = 42: End Sub"
            };

            var indenter = new Indenter(null, () => IndenterSettingsTests.GetMockIndenterSettings());
            var actual   = indenter.Indent(code, string.Empty);

            Assert.IsTrue(code.SequenceEqual(actual));
        }
예제 #10
0
 public void Dump(Indenter stream)
 {
     // display the nodes in reverse order of creation as we create the tree bottom-up so the last are the topmost nodes
     for (int i = _count - 1; i >= 0; i--)
     {
         Node node = _index[i];
         stream.WriteLine("{0,4:D4} {1} {2}:", node.Id, node.ToString(), node.Position.ToString());
         stream.Indent();
         node.DumpFields(stream);
         stream.Dedent();
         stream.WriteLine();
     }
 }
예제 #11
0
파일: Node.cs 프로젝트: bencz/Beryl
 public void Dump(Indenter stream)
 {
     // display the nodes in reverse order of creation as we create the tree bottom-up so the last are the topmost nodes
     for (int i = _count - 1; i >= 0; i--)
     {
         Node node = _index[i];
         stream.WriteLine("{0,4:D4} {1} {2}:", node.Id, node.ToString(), node.Position.ToString());
         stream.Indent();
         node.DumpFields(stream);
         stream.Dedent();
         stream.WriteLine();
     }
 }
예제 #12
0
        public void DeclareFunctionsDoNotIndentNextLine()
        {
            var code = new[]
            {
                @"Public Declare Function Foo Lib ""bar.dll"" (X As Any) As Variant",
                @"Public Declare Sub Bar Lib ""bar.dll"" (Y As Integer)"
            };

            var indenter = new Indenter(null, () => IndenterSettingsTests.GetMockIndenterSettings());
            var actual   = indenter.Indent(code);

            Assert.IsTrue(code.SequenceEqual(actual));
        }
예제 #13
0
        public void UnmatchedEnumsNotIndent()
        {
            var code = new[]
            {
                "Public Enum Foo: X = 1: Y = 2: End Enum: Public Enum Bar",
                "X = 1: Y = 2: End Enum"
            };

            var indenter = new Indenter(null, () => IndenterSettingsTests.GetMockIndenterSettings());
            var actual   = indenter.Indent(code);

            Assert.IsTrue(code.SequenceEqual(actual));
        }
예제 #14
0
        public void VerticalSpacing_RemoveExtraLinesWorks()
        {
            var code = new[]
            {
                "Private Sub TestOne()",
                "End Sub",
                "",
                "",
                "",
                "Private Sub TestTwo()",
                "End Sub",
                "",
                "",
                "",
                "Private Function TestThree()",
                "End Function",
                "",
                "",
                "",
                "Private Function TestFour()",
                "End Function"
            };

            var expected = new[]
            {
                "Private Sub TestOne()",
                "End Sub",
                "",
                "Private Sub TestTwo()",
                "End Sub",
                "",
                "Private Function TestThree()",
                "End Function",
                "",
                "Private Function TestFour()",
                "End Function"
            };

            var indenter = new Indenter(null, () =>
            {
                var s = IndenterSettingsTests.GetMockIndenterSettings();
                s.VerticallySpaceProcedures = true;
                s.LinesBetweenProcedures    = 1;
                return(s);
            });
            var actual = indenter.Indent(code);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
예제 #15
0
        public void RemsWithLineContinuationsWork()
        {
            var code = new[]
            {
                "'Private Sub Test()",
                "Rem Long multiline comment _",
                "Rem blah blah blah, etc. _",
                "Rem etc.",
                "'End Sub"
            };

            var indenter = new Indenter(null, () => IndenterSettingsTests.GetMockIndenterSettings());
            var actual   = indenter.Indent(code);

            Assert.IsTrue(code.SequenceEqual(actual));
        }
예제 #16
0
        public void SingleLineFunctionsNotIndented()
        {
            var code = new[]
            {
                "Private Function Foo(): Foo = 42: End Function",
                "Private Sub Bar(): Debug.Assert Foo = 42: End Sub"
            };

            var indenter = new Indenter(null, () =>
            {
                var s = IndenterSettingsTests.GetMockIndenterSettings();
                s.VerticallySpaceProcedures = false;
                return(s);
            });
            var actual = indenter.Indent(code);

            Assert.IsTrue(code.SequenceEqual(actual));
        }
예제 #17
0
        public void SingleLineTypesNotIndented()
        {
            var code = new[]
            {
                "Public Type Foo: X As Integer: End Type",
                "Public Enum Bar: X = 1: Y = 2: End Enum"
            };

            var indenter = new Indenter(null, () =>
            {
                var s = IndenterSettingsTests.GetMockIndenterSettings();
                s.VerticallySpaceProcedures = false;
                return(s);
            });
            var actual = indenter.Indent(code);

            Assert.IsTrue(code.SequenceEqual(actual));
        }
예제 #18
0
        public void DeclarationLineAlignsCorrectly()
        {
            var code = new[]
            {
                @"Public Declare Sub Foo Lib ""bar.dll"" (x As Long, _",
                "y As Long)"
            };

            var expected = new[]
            {
                @"Public Declare Sub Foo Lib ""bar.dll"" (x As Long, _",
                "                                      y As Long)"
            };

            var indenter = new Indenter(null, () => IndenterSettingsTests.GetMockIndenterSettings());
            var actual   = indenter.Indent(code);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
예제 #19
0
        public void FunctionParametersAlignCorrectly()
        {
            var code = new[]
            {
                "Private Sub Test(x As Integer, y As Integer, _",
                "z As Long, abcde As Integer)"
            };

            var expected = new[]
            {
                "Private Sub Test(x As Integer, y As Integer, _",
                "                 z As Long, abcde As Integer)"
            };

            var indenter = new Indenter(null, () => IndenterSettingsTests.GetMockIndenterSettings());
            var actual   = indenter.Indent(code);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
예제 #20
0
        public void TrailingMultiLineCommentSecondNoAlignWorks()
        {
            var code = new[]
            {
                "Sub MySub2()",
                "Dim x7 As Integer _",
                "'Comment foo _",
                "foo",
                "End Sub",
                "",
                "Sub MySub1()",
                "Dim x7 As Integer _",
                "'Comment foo _",
                "",
                "End Sub"
            };

            var expected = new[]
            {
                "Sub MySub2()",
                "    Dim x7 As Integer _",
                "    'Comment foo _",
                "    foo",
                "End Sub",
                "",
                "Sub MySub1()",
                "    Dim x7 As Integer _",
                "    'Comment foo _",
                "",
                "End Sub"
            };

            var indenter = new Indenter(null, () =>
            {
                var s = IndenterSettingsTests.GetMockIndenterSettings();
                s.AlignContinuations = false;
                return(s);
            });
            var actual = indenter.Indent(code);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
예제 #21
0
        public void VerticalSpacing_DoesNotChangeSpacingInProcedures()
        {
            var code = new[]
            {
                "Function TestFunction() As Long",
                "",
                "",
                "TestFunction = 42",
                "End Function",
                "Sub TestSub()",
                "Debug.Print TestFunction",
                "",
                "",
                "End Sub"
            };

            var expected = new[]
            {
                "Function TestFunction() As Long",
                "",
                "",
                "    TestFunction = 42",
                "End Function",
                "",
                "Sub TestSub()",
                "    Debug.Print TestFunction",
                "",
                "",
                "End Sub"
            };

            var indenter = new Indenter(null, () =>
            {
                var s = IndenterSettingsTests.GetMockIndenterSettings();
                s.VerticallySpaceProcedures = true;
                s.LinesBetweenProcedures    = 1;
                return(s);
            });
            var actual = indenter.Indent(code);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
예제 #22
0
        public void ReplacementPatternsInStringLiteralWorks()
        {
            var code = new[]
            {
                "Public Sub Test()",
                "Debug.Print \"a*${test}b\"",
                "End Sub"
            };

            var expected = new[]
            {
                "Public Sub Test()",
                "    Debug.Print \"a*${test}b\"",
                "End Sub"
            };

            var indenter = new Indenter(null, () => IndenterSettingsTests.GetMockIndenterSettings());
            var actual   = indenter.Indent(code);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
예제 #23
0
        public void BracketsInEndOfLineCommentsWork()
        {
            var code = new[]
            {
                "Public Sub Test()",
                "Debug.Print \"foo\" \'update [foo].[bar] in the frob.",
                "End Sub"
            };

            var expected = new[]
            {
                "Public Sub Test()",
                "    Debug.Print \"foo\"                            'update [foo].[bar] in the frob.",
                "End Sub"
            };

            var indenter = new Indenter(null, () => IndenterSettingsTests.GetMockIndenterSettings());
            var actual   = indenter.Indent(code);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
예제 #24
0
        public void QuotesInsideStringLiteralsWork()
        {
            var code = new[]
            {
                "Public Sub Test()",
                "Debug.Print \"This is a \"\" in the middle of a string.\"",
                "End Sub"
            };

            var expected = new[]
            {
                "Public Sub Test()",
                "    Debug.Print \"This is a \"\" in the middle of a string.\"",
                "End Sub"
            };

            var indenter = new Indenter(null, () => IndenterSettingsTests.GetMockIndenterSettings());
            var actual   = indenter.Indent(code);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
예제 #25
0
        public void SingleQuoteInEndOfLineCommentWorks()
        {
            var code = new[]
            {
                "Public Sub Test()",
                "Debug.Print Chr$(34) 'Prints a single '\"' character.",
                "End Sub"
            };

            var expected = new[]
            {
                "Public Sub Test()",
                "    Debug.Print Chr$(34)                         'Prints a single '\"' character.",
                "End Sub"
            };

            var indenter = new Indenter(null, () => IndenterSettingsTests.GetMockIndenterSettings());
            var actual   = indenter.Indent(code);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
        public ActionResult Preview(IndenterSettingsModel model)
        {
            var code = model.Code;

            if (string.IsNullOrEmpty(code))
            {
                return(View(model));
            }

            var indenter = new Indenter(null, () => model);
            var lines    = code.Split(new[] { Environment.NewLine }, StringSplitOptions.None);

            lines = indenter.Indent(lines, false).ToArray();
            var result = string.Join(Environment.NewLine, lines);

            // Required to update Code textarea
            // Otherwise it reloads the POSTed data
            ModelState.Clear();

            model.Code = result + Environment.NewLine;
            return(View(model));
        }
        public void IndentFirstCommentBlockOffIgnoreEmptyOnlyOnFirst()
        {
            var code = new[]
            {
                "Public Function Test() As String",
                "'Comment block",
                "",
                "'Comment block",
                "Dim Foo As Long",
                "Dim Bar As Long",
                @"Test = ""Passed!""",
                "'Not in comment block",
                "End Function"
            };

            var expected = new[]
            {
                "Public Function Test() As String",
                "'Comment block",
                "",
                "'Comment block",
                "    Dim Foo As Long",
                "    Dim Bar As Long",
                @"    Test = ""Passed!""",
                "    'Not in comment block",
                "End Function"
            };

            var indenter = new Indenter(null, () =>
            {
                var s = IndenterSettingsTests.GetMockIndenterSettings();
                s.IndentFirstCommentBlock       = false;
                s.IgnoreEmptyLinesInFirstBlocks = true;
                return(s);
            });
            var actual = indenter.Indent(code);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
예제 #28
0
        public void MultiLineDimWithCommasDontIndentFirstBlockWorks()
        {
            var code = new[]
            {
                "Public Sub FooBar()",
                "Dim foo As Boolean, bar As String _",
                ", baz As String _",
                ", somethingElse As String",
                "Dim x As Integer",
                "If Not foo Then",
                "x = 1",
                "End If",
                "End Sub"
            };

            var expected = new[]
            {
                "Public Sub FooBar()",
                "Dim foo As Boolean, bar As String _",
                ", baz As String _",
                ", somethingElse As String",
                "Dim x As Integer",
                "    If Not foo Then",
                "        x = 1",
                "    End If",
                "End Sub"
            };

            var indenter = new Indenter(null, () =>
            {
                var s = IndenterSettingsTests.GetMockIndenterSettings();
                s.IndentFirstDeclarationBlock = false;
                return(s);
            });
            var actual = indenter.Indent(code);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
예제 #29
0
        public void SplitNamedParameterAlignsCorrectly()
        {
            var code = new[]
            {
                "Sub Foo()",
                "Debug.Print WorksheetFunction.Sum(arg1:=1, arg2:=2, arg3 _",
                ":=3)",
                "End Sub"
            };

            var expected = new[]
            {
                "Sub Foo()",
                "    Debug.Print WorksheetFunction.Sum(arg1:=1, arg2:=2, arg3 _",
                "                                      :=3)",
                "End Sub"
            };

            var indenter = new Indenter(null, () => IndenterSettingsTests.GetMockIndenterSettings());
            var actual   = indenter.Indent(code);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
예제 #30
0
        public void NamedParametersAlignCorrectly()
        {
            var code = new[]
            {
                "Private Sub Foo()",
                "Test X:=1, Y:=2, _",
                "Z:=3, Foobar:=4",
                "End Sub"
            };

            var expected = new[]
            {
                "Private Sub Foo()",
                "    Test X:=1, Y:=2, _",
                "         Z:=3, Foobar:=4",
                "End Sub"
            };

            var indenter = new Indenter(null, () => IndenterSettingsTests.GetMockIndenterSettings());
            var actual   = indenter.Indent(code);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
예제 #31
0
        public void ContinuedNestedFunctionWorks()
        {
            var code = new[]
            {
                "Public Sub Test()",
                "Debug.Print Foo(X, Bar(A, B, _",
                "C), Z)",
                "End Sub"
            };

            var expected = new[]
            {
                "Public Sub Test()",
                "    Debug.Print Foo(X, Bar(A, B, _",
                "                           C), Z)",
                "End Sub"
            };

            var indenter = new Indenter(null, () => IndenterSettingsTests.GetMockIndenterSettings());
            var actual   = indenter.Indent(code);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }