Skip to content

Commit d6ef047

Browse files
committed
Fixed bad tests for #1858, closes #2233. Added ToString overrides for easier use of locals window.
1 parent 8e5f58e commit d6ef047

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

Rubberduck.SmartIndenter/AbsoluteCodeLine.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ internal class AbsoluteCodeLine
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)");
2121
private static readonly Regex TypeEnumEndRegex = new Regex(@"^End\s(Enum|Type)");
22-
private static readonly Regex InProcedureInRegex = new Regex(@"^(Else)?If\s.*\sThen$|^(Else)?If\s.*\sThen\s.*\sElse$|^Else$|^Case\s|^With|^For\s|^Do$|^Do\s|^While$|^While\s|^Select Case");
23-
private static readonly Regex InProcedureOutRegex = new Regex(@"^(Else)?If\s.*\sThen\s.*(?<!\sElse)$|^Else$|ElseIf\s.*\sThen$|^Case\s|^End With|^Next\s|^Next$|^Loop$|^Loop\s|^Wend$|^End If$|^End Select");
22+
private static readonly Regex InProcedureInRegex = new Regex(@"^(Else)?If\s.*\sThen$|^Else$|^Case\s|^With|^For\s|^Do$|^Do\s|^While$|^While\s|^Select Case");
23+
private static readonly Regex InProcedureOutRegex = new Regex(@"^Else(If)?|^Case\s|^End With|^Next\s|^Next$|^Loop$|^Loop\s|^Wend$|^End If$|^End Select");
2424
private static readonly Regex DeclarationRegex = new Regex(@"^(Dim|Const|Static|Public|Private)\s.*\sAs\s");
2525
private static readonly Regex PrecompilerInRegex = new Regex(@"^#(Else)?If\s.+Then$|^#Else$");
2626
private static readonly Regex PrecompilerOutRegex = new Regex(@"^#ElseIf\s.+Then|^#Else$|#End\sIf$");
27-
private static readonly Regex SingleLineIfRegex = new Regex(@"^If\s.*\sThen\s.*(?<!\sElse)$");
28-
private static readonly Regex SingleLineElseIfRegex = new Regex(@"^ElseIf\s.*\sThen\s.*(?<!\sElse)$");
27+
private static readonly Regex SingleLineElseIfRegex = new Regex(@"^ElseIf\s.*\sThen\s.*");
2928

3029
private readonly IIndenterSettings _settings;
3130
private uint _lineNumber;
@@ -181,7 +180,6 @@ public int Outdents
181180
var outs = _segments.Count(s => InProcedureOutRegex.IsMatch(s.Trim())) + (IsProcedureEnd && _settings.IndentEntireProcedureBody ? 1 : 0) + adjust;
182181

183182
outs -= MultipleCaseAdjustment();
184-
outs -= _segments.Count(s => SingleLineIfRegex.IsMatch(s));
185183

186184
if (_settings.IndentCompilerDirectives && PrecompilerOutRegex.IsMatch(_segments[0].Trim()))
187185
{
@@ -246,6 +244,11 @@ public string Indent(int indents, bool atProcStart, bool absolute = false)
246244
}
247245
}
248246

247+
public override string ToString()
248+
{
249+
return Original;
250+
}
251+
249252
private void AlignDims(int postition)
250253
{
251254
if (!DeclarationRegex.IsMatch(_segments[0]) || IsProcedureStart) return;

Rubberduck.SmartIndenter/LogicalCodeLine.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ public string Indented()
145145
return string.Join(Environment.NewLine, output);
146146
}
147147

148+
public override string ToString()
149+
{
150+
return _lines.Aggregate(string.Empty, (x, y) => x + y.ToString());
151+
}
152+
148153
private static readonly Regex StartIgnoreRegex = new Regex(@"^(\d*\s)?\s*[LR]?Set\s|^(\d*\s)?\s*Let\s|^(\d*\s)?\s*(Public|Private)\sDeclare\s(Function|Sub)|^(\d*\s+)");
149154
private readonly Stack<AlignmentToken> _alignment = new Stack<AlignmentToken>();
150155

RubberduckTests/SmartIndenter/MiscAndCornerCaseTests.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,25 +122,24 @@ public void MultipleElseIfStatementWorks()
122122
}
123123

124124
//https://github.com/rubberduck-vba/Rubberduck/issues/1858
125+
//https://github.com/rubberduck-vba/Rubberduck/issues/2233
125126
[TestMethod]
126127
[TestCategory("Indenter")]
127-
public void IfThenElseStatementWorks()
128+
public void IfThenBareElseStatementWorks()
128129
{
129130
var code = new[]
130131
{
131132
"Public Sub Test()",
132133
"If Foo And Bar Then Foobar Else",
133134
"Baz",
134-
"End If",
135135
"End Sub"
136136
};
137137

138138
var expected = new[]
139139
{
140140
"Public Sub Test()",
141141
" If Foo And Bar Then Foobar Else",
142-
" Baz",
143-
" End If",
142+
" Baz",
144143
"End Sub"
145144
};
146145

@@ -152,13 +151,15 @@ public void IfThenElseStatementWorks()
152151
//https://github.com/rubberduck-vba/Rubberduck/issues/1858
153152
[TestMethod]
154153
[TestCategory("Indenter")]
155-
public void ElseIfThenElseStatementWorks()
154+
public void SingleLineElseIfElseStatementWorks()
156155
{
157156
var code = new[]
158157
{
159158
"Public Sub Test()",
160-
"If Foo Then NotFoobar",
161-
"ElseIf Foo And Bar Then Foobar Else",
159+
"If x Then",
160+
"NotFoobar",
161+
"ElseIf Foo And Bar Then Foobar",
162+
"Else",
162163
"Baz",
163164
"End If",
164165
"End Sub"
@@ -167,8 +168,10 @@ public void ElseIfThenElseStatementWorks()
167168
var expected = new[]
168169
{
169170
"Public Sub Test()",
170-
" If Foo Then NotFoobar",
171-
" ElseIf Foo And Bar Then Foobar Else",
171+
" If x Then",
172+
" NotFoobar",
173+
" ElseIf Foo And Bar Then Foobar",
174+
" Else",
172175
" Baz",
173176
" End If",
174177
"End Sub"

0 commit comments

Comments
 (0)