Skip to content

Commit 2373066

Browse files
authored
Merge pull request #2366 from comintern/next
Fix variables starting w. Sub or Function in indenter.
2 parents 3480934 + 05cdb97 commit 2373066

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

Rubberduck.SmartIndenter/AbsoluteCodeLine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ internal class AbsoluteCodeLine
1414
private static readonly Regex StringReplaceRegex = new Regex(StringPlaceholder);
1515
private static readonly Regex LineNumberRegex = new Regex(@"^(?<number>\d+)\s+(?<code>.*)", RegexOptions.ExplicitCapture);
1616
private static readonly Regex EndOfLineCommentRegex = new Regex(@"^(?!(Rem\s)|('))(?<code>.*)(\s(?<comment>'.*))$", RegexOptions.ExplicitCapture);
17-
private static readonly Regex ProcedureStartRegex = new Regex(@"^(Public\s|Private\s|Friend\s)?(Static\s)?(Sub|Function|Property\s(Let|Get|Set))");
17+
private static readonly Regex ProcedureStartRegex = new Regex(@"^(Public\s|Private\s|Friend\s)?(Static\s)?(Sub|Function|Property\s(Let|Get|Set))\s");
1818
private static readonly Regex ProcedureStartIgnoreRegex = new Regex(@"^[LR]?Set\s|^Let\s|^(Public|Private)\sDeclare\s(Function|Sub)");
1919
private static readonly Regex ProcedureEndRegex = new Regex(@"^End\s(Sub|Function|Property)");
2020
private static readonly Regex TypeEnumStartRegex = new Regex(@"^(Public\s|Private\s)?(Enum\s|Type\s)");

RubberduckTests/SmartIndenter/MiscAndCornerCaseTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,5 +435,33 @@ public void OverIndentationLeftAligns()
435435
var actual = indenter.Indent(code, string.Empty);
436436
Assert.IsTrue(expected.SequenceEqual(actual));
437437
}
438+
439+
//http://chat.stackexchange.com/transcript/message/33575758#33575758
440+
[TestMethod]
441+
[TestCategory("Indenter")]
442+
public void SubFooTokenIsNotInterpretedAsProcedureStart()
443+
{
444+
var code = new[]
445+
{
446+
"Public Sub Test()",
447+
"If Subject = 0 Then",
448+
"Subject = 1",
449+
"End If",
450+
"End Sub"
451+
};
452+
453+
var expected = new[]
454+
{
455+
"Public Sub Test()",
456+
" If Subject = 0 Then",
457+
" Subject = 1",
458+
" End If",
459+
"End Sub"
460+
};
461+
462+
var indenter = new Indenter(null, () => IndenterSettingsTests.GetMockIndenterSettings());
463+
var actual = indenter.Indent(code, string.Empty);
464+
Assert.IsTrue(expected.SequenceEqual(actual));
465+
}
438466
}
439467
}

0 commit comments

Comments
 (0)