-
Notifications
You must be signed in to change notification settings - Fork 307
/
Copy pathIgnoreInModuleQuickFixTests.cs
204 lines (179 loc) · 5.95 KB
/
IgnoreInModuleQuickFixTests.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
using System.Collections.Generic;
using NUnit.Framework;
using Rubberduck.CodeAnalysis.Inspections;
using Rubberduck.CodeAnalysis.Inspections.Concrete;
using Rubberduck.CodeAnalysis.QuickFixes;
using Rubberduck.CodeAnalysis.QuickFixes.Concrete;
using Rubberduck.Parsing.VBA;
using Rubberduck.VBEditor.SafeComWrappers;
using RubberduckTests.Mocks;
namespace RubberduckTests.QuickFixes
{
[TestFixture]
public class IgnoreInModuleQuickFixTests : QuickFixTestBase
{
[Test]
[Category("QuickFixes")]
public void NoIgnoreModule_AddsNewOne()
{
var inputCode =
@"
Public Sub DoSomething()
Dim value As Long
Dim bar As Long
value = 42
bar = 23
Debug.Print 42
End Sub";
var expectedCode =
@"'@IgnoreModule VariableNotUsed
Public Sub DoSomething()
Dim value As Long
Dim bar As Long
value = 42
bar = 23
Debug.Print 42
End Sub";
var actualCode = ApplyQuickFixToFirstInspectionResult(inputCode, state => new VariableNotUsedInspection(state));
Assert.AreEqual(expectedCode, actualCode);
}
[Test]
[Category("QuickFixes")]
public void IgnoreModuleAlreadyThere_InspectionNotIgnoredYet_AddsNewArgument()
{
var inputCode =
@"'@IgnoreModule AssignmentNotUsed
Public Sub DoSomething()
Dim value As Long
Dim bar As Long
value = 42
bar = 23
Debug.Print 42
End Sub";
var expectedCode =
@"'@IgnoreModule VariableNotUsed, AssignmentNotUsed
Public Sub DoSomething()
Dim value As Long
Dim bar As Long
value = 42
bar = 23
Debug.Print 42
End Sub";
var actualCode = ApplyQuickFixToFirstInspectionResult(inputCode, state => new VariableNotUsedInspection(state));
Assert.AreEqual(expectedCode, actualCode);
}
[Test]
[Category("QuickFixes")]
public void IgnoreModuleMultiple_AddsOneAnnotation_NoIgnoreModuleYet()
{
var inputCode =
@"
Public Sub DoSomething()
Dim value As Long
Dim bar As Long
value = 42
bar = 23
Debug.Print 42
End Sub";
var expectedCode =
@"'@IgnoreModule VariableNotUsed
Public Sub DoSomething()
Dim value As Long
Dim bar As Long
value = 42
bar = 23
Debug.Print 42
End Sub";
var actualCode = ApplyQuickFixToAllInspectionResults(inputCode, state => new VariableNotUsedInspection(state));
Assert.AreEqual(expectedCode, actualCode);
}
[Test]
[Category("QuickFixes")]
public void IgnoreModuleMultiple_AddsOneAnnotation_IgnoreModuleAlreadyThere()
{
var inputCode =
@"'@IgnoreModule AssignmentNotUsed
Public Sub DoSomething()
Dim value As Long
Dim bar As Long
value = 42
bar = 23
Debug.Print 42
End Sub";
var expectedCode =
@"'@IgnoreModule VariableNotUsed, AssignmentNotUsed
Public Sub DoSomething()
Dim value As Long
Dim bar As Long
value = 42
bar = 23
Debug.Print 42
End Sub";
var actualCode = ApplyQuickFixToAllInspectionResults(inputCode, state => new VariableNotUsedInspection(state));
Assert.AreEqual(expectedCode, actualCode);
}
[Test]
[Category("QuickFixes")]
public void IgnoreModuleMultiple_IdentifierInspection_DeclarationInOtherModule_AnnotationInReferenceModule()
{
var classCode =
@"
'@Obsolete(""no longer use this"")
Public Sub Foo()
End Sub";
var moduleCode =
@"Public Bar As Class1";
var inputCode =
@"
Public Sub DoSomething()
Module1.Bar.Foo
End Sub";
var expectedCode =
@"'@IgnoreModule ObsoleteMemberUsage
Public Sub DoSomething()
Module1.Bar.Foo
End Sub";
var vbe = new MockVbeBuilder().ProjectBuilder("TestProject1", ProjectProtection.Unprotected)
.AddComponent("Class1", ComponentType.ClassModule, classCode)
.AddComponent("Module1", ComponentType.StandardModule, moduleCode)
.AddComponent("TestModule", ComponentType.StandardModule, inputCode)
.AddProjectToVbeBuilder()
.Build()
.Object;
var actualCode = ApplyQuickFixToFirstInspectionResult(vbe, "TestModule", state => new ObsoleteMemberUsageInspection(state));
Assert.AreEqual(expectedCode, actualCode);
}
[Test]
[Category("QuickFixes")]
public void IgnoreMcoduleMultiple_IdentifierInspection_DeclarationInOtherModule_LeavesDeclarationModuleAsIs()
{
var classCode =
@"
'@Obsolete(""no longer use this"")
Public Sub Foo()
End Sub";
var moduleCode =
@"Public Bar As Class1";
var inputCode =
@"
Public Sub DoSomething()
Module1.Bar.Foo
End Sub";
var vbe = new MockVbeBuilder().ProjectBuilder("TestProject1", ProjectProtection.Unprotected)
.AddComponent("Class1", ComponentType.ClassModule, classCode)
.AddComponent("Module1", ComponentType.StandardModule, moduleCode)
.AddComponent("TestModule", ComponentType.StandardModule, inputCode)
.AddProjectToVbeBuilder()
.Build()
.Object;
var actualCode = ApplyQuickFixToFirstInspectionResult(vbe, "Class1", state => new ObsoleteMemberUsageInspection(state));
Assert.AreEqual(classCode, actualCode);
}
protected override IQuickFix QuickFix(RubberduckParserState state)
{
var annotationUpdater = new AnnotationUpdater(state);
var inspections = new List<IInspection> {new VariableNotUsedInspection(state)};
return new IgnoreInModuleQuickFix(annotationUpdater, state, inspections);
}
}
}