Skip to content

Commit

Permalink
Limit inspection to Public Enums
Browse files Browse the repository at this point in the history
Added tests reflecting new limitation.
  • Loading branch information
IvenBach committed Nov 28, 2020
1 parent 7019b39 commit 272ce50
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
Expand Up @@ -20,7 +20,8 @@ public EnumerationDeclaredWithinWorksheetInspection(IDeclarationFinderProvider d

protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder)
{
return declaration.DeclarationType == DeclarationType.Enumeration
return declaration.Accessibility == Accessibility.Public
&& declaration.DeclarationType == DeclarationType.Enumeration
&& declaration.QualifiedModuleName.ComponentType == ComponentType.Document;
}

Expand Down
Expand Up @@ -21,7 +21,7 @@ public void EnumerationDeclaredWithinWorksheet_InspectionName()
[Test]
[Category("Inspections")]
[Category("EnumerationDeclaredWithinWorksheet")]
public void Project_with_multiple_enumerations_flags_only_enum_declared_within_worksheets()
public void Project_with_multiple_public_enumerations_flags_only_enum_declared_within_worksheets()
{
#region InputCode
const string worksheetCode = @"Option Explicit
Expand Down Expand Up @@ -61,6 +61,60 @@ End Enum
Assert.AreEqual(1, actual);
}

[Test]
[Category("Inspections")]
[Category("EnumerationDeclaredWithinWorksheet")]
public void Project_with_only_private_worksheet_enumeration_does_not_return_result()
{
#region InputCode
const string worksheetCode = @"Option Explicit
Private Enum WorksheetEnum
wsMember1 = 0
wsMember1 = 1
End Enum
";
#endregion

var inspectionResults = InspectionResultsForModules(
("FirstSheet", worksheetCode, ComponentType.Document));

int actual = inspectionResults.Count();

Assert.AreEqual(0, actual);
}

[Test]
[Category("Inspections")]
[Category("EnumerationDeclaredWithinWorksheet")]
public void Project_with_public_and_private_enumeration_declared_within_worksheets_returns_only_public_declarations()
{
#region InputCode
const string publicDeclaration = @"Option Explicit
Public Enum WorksheetEnum
wsMember1 = 0
wsMember2 = 1
End Enum
";
const string privateDeclaration = @"Option Explicit
Private Enum WorksheetEnum
wsMember1 = 0
wsMember2 = 1
End Enum
";
#endregion

var inspectionResults = InspectionResultsForModules(
("FirstPublicSheet", publicDeclaration, ComponentType.Document),
("FirstPrivateSheet", privateDeclaration, ComponentType.Document),
("SecondPrivateSheet", privateDeclaration, ComponentType.Document),
("SecondPublicSheet", publicDeclaration, ComponentType.Document),
("ThirdPrivateSheet", privateDeclaration, ComponentType.Document));

int actual = inspectionResults.Count();

Assert.AreEqual(2, actual);
}

[Test]
[Category("Inspections")]
[Category("EnumerationDeclaredWithinWorksheet")]
Expand All @@ -77,7 +131,7 @@ End Enum
[TestCase(ComponentType.UserControl)]
[TestCase(ComponentType.UserForm)]
[TestCase(ComponentType.VBForm)]
public void Enumerations_declared_within_non_worksheet_object_have_no_inpsection_result(ComponentType componentType)
public void Public_enumerations_declared_within_non_worksheet_object_have_no_inpsection_result(ComponentType componentType)
{
const string code = @"Option Explicit
Public Enum TestEnum
Expand Down

0 comments on commit 272ce50

Please sign in to comment.