-
Notifications
You must be signed in to change notification settings - Fork 307
/
Copy pathReplaceIfElseWithConditionalStatementQuickFixTests.cs
112 lines (98 loc) · 2.8 KB
/
ReplaceIfElseWithConditionalStatementQuickFixTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using NUnit.Framework;
using Rubberduck.CodeAnalysis.Inspections.Concrete;
using Rubberduck.CodeAnalysis.QuickFixes;
using Rubberduck.CodeAnalysis.QuickFixes.Concrete;
using Rubberduck.Parsing.VBA;
namespace RubberduckTests.QuickFixes
{
[TestFixture]
public class ReplaceIfElseWithConditionalStatementQuickFixTests : QuickFixTestBase
{
[Test]
[Category("QuickFixes")]
public void Simple()
{
const string inputCode =
@"Sub Foo()
Dim d As Boolean
If True Then
d = True
Else
d = False
EndIf
End Sub";
const string expectedCode =
@"Sub Foo()
Dim d As Boolean
d = True
End Sub";
var actualCode = ApplyQuickFixToFirstInspectionResult(inputCode, state => new BooleanAssignedInIfElseInspection(state));
Assert.AreEqual(expectedCode, actualCode);
}
[Test]
[Category("QuickFixes")]
public void ComplexCondition()
{
const string inputCode =
@"Sub Foo()
Dim d As Boolean
If True Or False And False Xor True Then
d = True
Else
d = False
EndIf
End Sub";
const string expectedCode =
@"Sub Foo()
Dim d As Boolean
d = True Or False And False Xor True
End Sub";
var actualCode = ApplyQuickFixToFirstInspectionResult(inputCode, state => new BooleanAssignedInIfElseInspection(state));
Assert.AreEqual(expectedCode, actualCode);
}
[Test]
[Category("QuickFixes")]
public void InvertedCondition()
{
const string inputCode =
@"Sub Foo()
Dim d As Boolean
If True Then
d = False
Else
d = True
EndIf
End Sub";
const string expectedCode =
@"Sub Foo()
Dim d As Boolean
d = Not (True)
End Sub";
var actualCode = ApplyQuickFixToFirstInspectionResult(inputCode, state => new BooleanAssignedInIfElseInspection(state));
Assert.AreEqual(expectedCode, actualCode);
}
[Test]
[Category("QuickFixes")]
public void QualifiedName()
{
const string inputCode =
@"Sub Foo()
If True Then
Fizz.Buzz = True
Else
Fizz.Buzz = False
EndIf
End Sub";
const string expectedCode =
@"Sub Foo()
Fizz.Buzz = True
End Sub";
var actualCode = ApplyQuickFixToFirstInspectionResult(inputCode, state => new BooleanAssignedInIfElseInspection(state));
Assert.AreEqual(expectedCode, actualCode);
}
protected override IQuickFix QuickFix(RubberduckParserState state)
{
return new ReplaceIfElseWithConditionalStatementQuickFix();
}
}
}