Skip to content

Commit 0cd3f46

Browse files
committed
added unit tests
1 parent d59e8ee commit 0cd3f46

File tree

7 files changed

+130
-15
lines changed

7 files changed

+130
-15
lines changed

Rubberduck.CodeAnalysis/Inspections/Concrete/InconsistentArrayBaseInspection.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ public InconsistentArrayBaseInspection(IDeclarationFinderProvider declarationFin
5656

5757
protected override bool IsResultReference(IdentifierReference reference, DeclarationFinder finder)
5858
{
59-
var parentModule = finder.ModuleDeclaration(reference.QualifiedModuleName);
60-
var hasOptionBase1 = parentModule.Context.GetDescendent<VBAParser.OptionBaseStmtContext>()?.numberLiteral()?.GetText() == "1";
59+
var hasOptionBase1 = reference.Context
60+
.GetAncestor<VBAParser.ModuleContext>()
61+
.GetDescendent<VBAParser.OptionBaseStmtContext>()?
62+
.numberLiteral()?.GetText() == "1";
6163

6264
if (hasOptionBase1 && reference.Declaration.ProjectName == "VBA" && reference.Declaration.IdentifierName == "Array")
6365
{

Rubberduck.CodeAnalysis/Inspections/Concrete/InconsistentParamArrayBaseInspection.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ public InconsistentParamArrayBaseInspection(IDeclarationFinderProvider declarati
6464

6565
protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder)
6666
{
67-
var parentModule = finder.ModuleDeclaration(declaration.QualifiedModuleName);
68-
var hasOptionBase1 = parentModule.Context.GetDescendent<VBAParser.OptionBaseStmtContext>()?.numberLiteral()?.GetText() == "1";
67+
var hasOptionBase1 = declaration.Context
68+
.GetAncestor<VBAParser.ModuleContext>()
69+
.GetDescendent<VBAParser.OptionBaseStmtContext>()?
70+
.numberLiteral()?.GetText() == "1";
71+
6972

7073
if (hasOptionBase1 && declaration is ParameterDeclaration parameter)
7174
{

Rubberduck.CodeAnalysis/Inspections/Concrete/VariableTypeNotDeclaredInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected override string ResultDescription(Declaration declaration)
5555
var declarationType = declaration.DeclarationType.ToLocalizedString();
5656
var declarationName = declaration.IdentifierName;
5757
return string.Format(
58-
InspectionResults.ResourceManager.GetString(nameof(ImplicitVariantDeclarationInspection), CultureInfo.CurrentUICulture),
58+
InspectionResults.ResourceManager.GetString(nameof(InspectionResults.ImplicitVariantDeclarationInspection), CultureInfo.CurrentUICulture),
5959
declarationType,
6060
declarationName);
6161
}

RubberduckTests/AddRemoveReferences/AddRemoveReferencesViewModelTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Runtime.InteropServices;
5-
using System.Windows.Forms;
6-
using Moq;
1+
using Moq;
72
using NUnit.Framework;
83
using Rubberduck.AddRemoveReferences;
94
using Rubberduck.UI;
105
using Rubberduck.UI.AddRemoveReferences;
116
using Rubberduck.VBEditor;
127
using Rubberduck.VBEditor.SafeComWrappers;
8+
using System;
9+
using System.Collections.Generic;
10+
using System.Linq;
11+
using System.Runtime.InteropServices;
12+
using System.Windows.Forms;
1313

1414
namespace RubberduckTests.AddRemoveReferences
1515
{
@@ -403,7 +403,7 @@ public void ViewModelMoveDownCommand_MovesPriorityDown()
403403
[Test]
404404
[Category("AddRemoveReferences")]
405405
public void ViewModelMoveDownCommand_DoesNotMoveLastReference()
406-
406+
407407
{
408408
var viewModel = AddRemoveReferencesSetup.ArrangeViewModel();
409409
var referenced = viewModel.ProjectReferences.OfType<ReferenceModel>().ToDictionary(model => model.Priority.GetValueOrDefault());
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
using NUnit.Framework;
2+
using Rubberduck.CodeAnalysis.Inspections;
3+
using Rubberduck.CodeAnalysis.Inspections.Concrete;
4+
using Rubberduck.Parsing.VBA;
5+
using Rubberduck.VBEditor.SafeComWrappers;
6+
using RubberduckTests.Mocks;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
10+
namespace RubberduckTests.Inspections
11+
{
12+
[TestFixture]
13+
public class InconsistentParamArrayBaseInspectionTests : InspectionTestsBase
14+
{
15+
[Test]
16+
[Category("Inspections")]
17+
public void InconsistentParamArrayBase_ReturnsResult()
18+
{
19+
const string inputCode =
20+
@"Option Base 1
21+
Public Sub DoSomething(ParamArray Values)
22+
End Sub";
23+
Assert.AreEqual(1, InspectionResultsForStandardModule(inputCode).Count());
24+
}
25+
26+
[Test]
27+
[Category("Inspections")]
28+
public void WithoutOptionBase_NoResult()
29+
{
30+
const string inputCode =
31+
@"Public Sub DoSomething(ParamArray Values)
32+
End Sub";
33+
34+
Assert.AreEqual(0, InspectionResultsForStandardModule(inputCode).Count());
35+
36+
}
37+
38+
[Test]
39+
[Category("Inspections")]
40+
public void NonParamArrayParameter_NoResult()
41+
{
42+
const string inputCode =
43+
@"Option Base 1
44+
Public Sub DoSomething(ByRef Values() As Variant)
45+
End Sub";
46+
Assert.AreEqual(0, InspectionResultsForStandardModule(inputCode).Count());
47+
}
48+
49+
protected override IInspection InspectionUnderTest(RubberduckParserState state)
50+
{
51+
return new InconsistentParamArrayBaseInspection(state);
52+
}
53+
}
54+
55+
[TestFixture]
56+
public class InconsistentArrayBaseInspectionTests : InspectionTestsBase
57+
{
58+
[Test]
59+
[Category("Inspections")]
60+
public void InconsistentArrayBase_ReturnsResult()
61+
{
62+
const string inputCode =
63+
@"Option Base 1
64+
Public Sub DoSomething()
65+
Dim Values As Variant
66+
Values = VBA.Array(42)
67+
End Sub";
68+
69+
Assert.AreEqual(1, InspectionResults(inputCode).Count());
70+
}
71+
72+
[Test]
73+
[Category("Inspections")]
74+
public void WithoutOptionBase_NoResult()
75+
{
76+
const string inputCode =
77+
@"Public Sub DoSomething()
78+
Dim Values As Variant
79+
Values = VBA.Array(42)
80+
End Sub";
81+
82+
Assert.AreEqual(0, InspectionResults(inputCode).Count());
83+
84+
}
85+
86+
[Test]
87+
[Category("Inspections")]
88+
public void WithoutQualifier_NoResult()
89+
{
90+
const string inputCode =
91+
@"Public Sub DoSomething()
92+
Dim Values As Variant
93+
Values = Array(42)
94+
End Sub";
95+
96+
Assert.AreEqual(0, InspectionResults(inputCode).Count());
97+
98+
}
99+
100+
private IEnumerable<IInspectionResult> InspectionResults(string inputCode)
101+
{
102+
return InspectionResultsForModules(("TestModule1", inputCode, ComponentType.StandardModule), ReferenceLibrary.VBA);
103+
}
104+
105+
protected override IInspection InspectionUnderTest(RubberduckParserState state)
106+
{
107+
return new InconsistentArrayBaseInspection(state);
108+
}
109+
}
110+
}

RubberduckTests/Inspections/MultilineParameterInspectionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
using System.Linq;
21
using NUnit.Framework;
32
using Rubberduck.CodeAnalysis.Inspections;
43
using Rubberduck.CodeAnalysis.Inspections.Concrete;
54
using Rubberduck.Parsing.VBA;
5+
using System.Linq;
66

77
namespace RubberduckTests.Inspections
88
{

RubberduckTests/SmartIndenter/EndOfLineCommentTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using System.Linq;
21
using NUnit.Framework;
32
using Rubberduck.SmartIndenter;
43
using RubberduckTests.Settings;
4+
using System.Linq;
55

66
namespace RubberduckTests.SmartIndenter
77
{
@@ -220,7 +220,7 @@ public void WorksOutsideOfProcedures()
220220
{
221221
"#Const Foo = Bar 'Comment",
222222
"",
223-
"Private Sub Test()",
223+
"Private Sub Test()",
224224
"End Sub"
225225
};
226226

0 commit comments

Comments
 (0)