Skip to content

Commit 290192b

Browse files
committed
Adjusted Tests and some 'small' bugs with the rewrite
1 parent 19594ae commit 290192b

File tree

6 files changed

+292
-36
lines changed

6 files changed

+292
-36
lines changed
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Rubberduck.Parsing;
22
using System.Collections.Generic;
3+
using System.Linq;
34

45
namespace Rubberduck.Inspections
56
{
@@ -10,9 +11,17 @@ internal interface IParseTreeInspection : IInspection
1011

1112
public sealed class ParseTreeResults
1213
{
13-
public IList<QualifiedContext> ObsoleteCallContexts;
14-
public IList<QualifiedContext> ObsoleteLetContexts;
15-
public IList<QualifiedContext> ArgListsWithOneByRefParam;
16-
public IList<QualifiedContext> EmptyStringLiterals;
14+
public ParseTreeResults()
15+
{
16+
ObsoleteCallContexts = Enumerable.Empty<QualifiedContext>();
17+
ObsoleteLetContexts = Enumerable.Empty<QualifiedContext>();
18+
ArgListsWithOneByRefParam = Enumerable.Empty<QualifiedContext>();
19+
EmptyStringLiterals = Enumerable.Empty<QualifiedContext>();
20+
}
21+
22+
public IEnumerable<QualifiedContext> ObsoleteCallContexts;
23+
public IEnumerable<QualifiedContext> ObsoleteLetContexts;
24+
public IEnumerable<QualifiedContext> ArgListsWithOneByRefParam;
25+
public IEnumerable<QualifiedContext> EmptyStringLiterals;
1726
}
1827
}

RetailCoder.VBE/Inspections/Inspector.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ before moving them into the ParseTreeResults after qualifying them
124124

125125
ParseTreeWalker.Default.Walk(combinedListener, componentTreePair.Value);
126126

127-
result.ArgListsWithOneByRefParam.Concat(argListWithOneByRefParamListener.Contexts.Select(context => new QualifiedContext(componentTreePair.Key, context)));
128-
result.EmptyStringLiterals.Concat(emptyStringLiteralListener.Contexts.Select(context => new QualifiedContext(componentTreePair.Key, context)));
129-
result.ObsoleteLetContexts.Concat(obsoleteLetStatementListener.Contexts.Select(context => new QualifiedContext(componentTreePair.Key, context)));
130-
result.ObsoleteCallContexts.Concat(obsoleteCallStatementListener.Contexts.Select(context => new QualifiedContext(componentTreePair.Key, context)));
127+
result.ArgListsWithOneByRefParam = result.ArgListsWithOneByRefParam.Concat(argListWithOneByRefParamListener.Contexts.Select(context => new QualifiedContext(componentTreePair.Key, context)));
128+
result.EmptyStringLiterals = result.EmptyStringLiterals.Concat(emptyStringLiteralListener.Contexts.Select(context => new QualifiedContext(componentTreePair.Key, context)));
129+
result.ObsoleteLetContexts = result.ObsoleteLetContexts.Concat(obsoleteLetStatementListener.Contexts.Select(context => new QualifiedContext(componentTreePair.Key, context)));
130+
result.ObsoleteCallContexts = result.ObsoleteCallContexts.Concat(obsoleteCallStatementListener.Contexts.Select(context => new QualifiedContext(componentTreePair.Key, context)));
131131
}
132132
return result;
133133
}

RubberduckTests/Inspections/EmptyStringLiteralInspectionTests.cs

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
using Rubberduck.VBEditor.Extensions;
88
using Rubberduck.VBEditor.VBEHost;
99
using RubberduckTests.Mocks;
10+
using Rubberduck.Settings;
11+
using Rubberduck.Inspections.Rubberduck.Inspections;
12+
using System.Threading;
1013

1114
namespace RubberduckTests.Inspections
1215
{
@@ -25,6 +28,10 @@ Public Sub Foo(ByRef arg1 As String)
2528
End Sub";
2629

2730
//Arrange
31+
var settings = new Mock<IGeneralConfigService>();
32+
var config = GetTestConfig();
33+
settings.Setup(x => x.LoadConfiguration()).Returns(config);
34+
2835
var builder = new MockVbeBuilder();
2936
VBComponent component;
3037
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
@@ -36,7 +43,9 @@ Public Sub Foo(ByRef arg1 As String)
3643
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
3744

3845
var inspection = new EmptyStringLiteralInspection(parser.State);
39-
var inspectionResults = inspection.GetInspectionResults();
46+
var inspector = new Inspector(settings.Object, new IInspection[] { inspection });
47+
48+
var inspectionResults = inspector.FindIssuesAsync(parser.State, CancellationToken.None).Result;
4049

4150
Assert.AreEqual(1, inspectionResults.Count());
4251
}
@@ -50,6 +59,10 @@ public void EmptyStringLiteral_ReturnsResult_Assignment()
5059
End Sub";
5160

5261
//Arrange
62+
var settings = new Mock<IGeneralConfigService>();
63+
var config = GetTestConfig();
64+
settings.Setup(x => x.LoadConfiguration()).Returns(config);
65+
5366
var builder = new MockVbeBuilder();
5467
VBComponent component;
5568
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
@@ -61,7 +74,9 @@ public void EmptyStringLiteral_ReturnsResult_Assignment()
6174
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
6275

6376
var inspection = new EmptyStringLiteralInspection(parser.State);
64-
var inspectionResults = inspection.GetInspectionResults();
77+
var inspector = new Inspector(settings.Object, new IInspection[] { inspection });
78+
79+
var inspectionResults = inspector.FindIssuesAsync(parser.State, CancellationToken.None).Result;
6580

6681
Assert.AreEqual(1, inspectionResults.Count());
6782
}
@@ -75,6 +90,10 @@ public void NotEmptyStringLiteral_DoesNotReturnResult()
7590
End Sub";
7691

7792
//Arrange
93+
var settings = new Mock<IGeneralConfigService>();
94+
var config = GetTestConfig();
95+
settings.Setup(x => x.LoadConfiguration()).Returns(config);
96+
7897
var builder = new MockVbeBuilder();
7998
VBComponent component;
8099
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
@@ -86,7 +105,9 @@ public void NotEmptyStringLiteral_DoesNotReturnResult()
86105
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
87106

88107
var inspection = new EmptyStringLiteralInspection(parser.State);
89-
var inspectionResults = inspection.GetInspectionResults();
108+
var inspector = new Inspector(settings.Object, new IInspection[] { inspection });
109+
110+
var inspectionResults = inspector.FindIssuesAsync(parser.State, CancellationToken.None).Result;
90111

91112
Assert.AreEqual(0, inspectionResults.Count());
92113
}
@@ -105,6 +126,10 @@ public void EmptyStringLiteral_QuickFixWorks()
105126
End Sub";
106127

107128
//Arrange
129+
var settings = new Mock<IGeneralConfigService>();
130+
var config = GetTestConfig();
131+
settings.Setup(x => x.LoadConfiguration()).Returns(config);
132+
108133
var builder = new MockVbeBuilder();
109134
VBComponent component;
110135
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
@@ -118,7 +143,9 @@ public void EmptyStringLiteral_QuickFixWorks()
118143
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
119144

120145
var inspection = new EmptyStringLiteralInspection(parser.State);
121-
var inspectionResults = inspection.GetInspectionResults();
146+
var inspector = new Inspector(settings.Object, new IInspection[] { inspection });
147+
148+
var inspectionResults = inspector.FindIssuesAsync(parser.State, CancellationToken.None).Result;
122149

123150
inspectionResults.First().QuickFixes.First().Fix();
124151

@@ -140,5 +167,21 @@ public void InspectionName()
140167

141168
Assert.AreEqual(inspectionName, inspection.Name);
142169
}
170+
171+
private Configuration GetTestConfig()
172+
{
173+
return new Configuration
174+
{
175+
UserSettings = new UserSettings
176+
{
177+
CodeInspectionSettings = new CodeInspectionSettings
178+
{
179+
CodeInspections = new[] {
180+
new CodeInspectionSetting { Description = new EmptyStringLiteralInspection(null).Description, Severity=CodeInspectionSeverity.Suggestion, }
181+
}
182+
}
183+
}
184+
};
185+
}
143186
}
144187
}

RubberduckTests/Inspections/ObsoleteCallStatementInspectionTests.cs

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
using Rubberduck.VBEditor.Extensions;
88
using Rubberduck.VBEditor.VBEHost;
99
using RubberduckTests.Mocks;
10+
using Rubberduck.Settings;
11+
using Rubberduck.Inspections.Rubberduck.Inspections;
12+
using System.Threading;
1013

1114
namespace RubberduckTests.Inspections
1215
{
@@ -22,6 +25,10 @@ Call Foo
2225
End Sub";
2326

2427
//Arrange
28+
var settings = new Mock<IGeneralConfigService>();
29+
var config = GetTestConfig();
30+
settings.Setup(x => x.LoadConfiguration()).Returns(config);
31+
2532
var builder = new MockVbeBuilder();
2633
VBComponent component;
2734
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
@@ -33,7 +40,9 @@ Call Foo
3340
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
3441

3542
var inspection = new ObsoleteCallStatementInspection(parser.State);
36-
var inspectionResults = inspection.GetInspectionResults();
43+
var inspector = new Inspector(settings.Object, new IInspection[] { inspection });
44+
45+
var inspectionResults = inspector.FindIssuesAsync(parser.State, CancellationToken.None).Result;
3746

3847
Assert.AreEqual(1, inspectionResults.Count());
3948
}
@@ -47,6 +56,10 @@ public void ObsoleteCallStatement_DoesNotReturnResult()
4756
End Sub";
4857

4958
//Arrange
59+
var settings = new Mock<IGeneralConfigService>();
60+
var config = GetTestConfig();
61+
settings.Setup(x => x.LoadConfiguration()).Returns(config);
62+
5063
var builder = new MockVbeBuilder();
5164
VBComponent component;
5265
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
@@ -58,7 +71,9 @@ public void ObsoleteCallStatement_DoesNotReturnResult()
5871
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
5972

6073
var inspection = new ObsoleteCallStatementInspection(parser.State);
61-
var inspectionResults = inspection.GetInspectionResults();
74+
var inspector = new Inspector(settings.Object, new IInspection[] { inspection });
75+
76+
var inspectionResults = inspector.FindIssuesAsync(parser.State, CancellationToken.None).Result;
6277

6378
Assert.AreEqual(0, inspectionResults.Count());
6479
}
@@ -76,6 +91,10 @@ Call Foo
7691
End Sub";
7792

7893
//Arrange
94+
var settings = new Mock<IGeneralConfigService>();
95+
var config = GetTestConfig();
96+
settings.Setup(x => x.LoadConfiguration()).Returns(config);
97+
7998
var builder = new MockVbeBuilder();
8099
VBComponent component;
81100
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
@@ -87,7 +106,9 @@ Call Foo
87106
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
88107

89108
var inspection = new ObsoleteCallStatementInspection(parser.State);
90-
var inspectionResults = inspection.GetInspectionResults();
109+
var inspector = new Inspector(settings.Object, new IInspection[] { inspection });
110+
111+
var inspectionResults = inspector.FindIssuesAsync(parser.State, CancellationToken.None).Result;
91112

92113
Assert.AreEqual(2, inspectionResults.Count());
93114
}
@@ -105,6 +126,10 @@ Sub Goo(arg1 As Integer, arg1 As String)
105126
End Sub";
106127

107128
//Arrange
129+
var settings = new Mock<IGeneralConfigService>();
130+
var config = GetTestConfig();
131+
settings.Setup(x => x.LoadConfiguration()).Returns(config);
132+
108133
var builder = new MockVbeBuilder();
109134
VBComponent component;
110135
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
@@ -116,7 +141,9 @@ Sub Goo(arg1 As Integer, arg1 As String)
116141
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
117142

118143
var inspection = new ObsoleteCallStatementInspection(parser.State);
119-
var inspectionResults = inspection.GetInspectionResults();
144+
var inspector = new Inspector(settings.Object, new IInspection[] { inspection });
145+
146+
var inspectionResults = inspector.FindIssuesAsync(parser.State, CancellationToken.None).Result;
120147

121148
Assert.AreEqual(1, inspectionResults.Count());
122149
}
@@ -143,6 +170,10 @@ Sub Goo(arg1 As Integer, arg1 As String)
143170
End Sub";
144171

145172
//Arrange
173+
var settings = new Mock<IGeneralConfigService>();
174+
var config = GetTestConfig();
175+
settings.Setup(x => x.LoadConfiguration()).Returns(config);
176+
146177
var builder = new MockVbeBuilder();
147178
VBComponent component;
148179
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
@@ -156,7 +187,9 @@ Sub Goo(arg1 As Integer, arg1 As String)
156187
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
157188

158189
var inspection = new ObsoleteCallStatementInspection(parser.State);
159-
var inspectionResults = inspection.GetInspectionResults();
190+
var inspector = new Inspector(settings.Object, new IInspection[] { inspection });
191+
192+
var inspectionResults = inspector.FindIssuesAsync(parser.State, CancellationToken.None).Result;
160193

161194
foreach (var inspectionResult in inspectionResults)
162195
{
@@ -182,5 +215,21 @@ public void InspectionName()
182215

183216
Assert.AreEqual(inspectionName, inspection.Name);
184217
}
218+
219+
private Configuration GetTestConfig()
220+
{
221+
return new Configuration
222+
{
223+
UserSettings = new UserSettings
224+
{
225+
CodeInspectionSettings = new CodeInspectionSettings
226+
{
227+
CodeInspections = new[] {
228+
new CodeInspectionSetting { Description = new ObsoleteCallStatementInspection(null).Description, Severity=CodeInspectionSeverity.Suggestion, }
229+
}
230+
}
231+
}
232+
};
233+
}
185234
}
186235
}

0 commit comments

Comments
 (0)