Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd672a0
commit 03c62ea
Showing
2 changed files
with
265 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
265 changes: 257 additions & 8 deletions
265
RubberduckTestsCodeAnalysis/InspectionXmlDocAnalyzerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,261 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Linq; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.Diagnostics; | ||
using NUnit.Framework; | ||
using TestHelper; | ||
|
||
namespace RubberduckTestsCodeAnalysis | ||
namespace RubberduckCodeAnalysis.Test | ||
{ | ||
class InspectionXmlDocAnalyzerTests | ||
[TestFixture] | ||
public class InspectionXmlDocAnalyzerTests : DiagnosticVerifier | ||
{ | ||
} | ||
protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer() | ||
=> new InspectionXmlDocAnalyzer(); | ||
|
||
private Diagnostic[] GetDiagnostics(string code) | ||
{ | ||
const string iinspection = @" | ||
public interface IInspection { } | ||
"; | ||
return GetSortedDiagnostics(new[] { iinspection + code }, LanguageNames.CSharp, GetCSharpDiagnosticAnalyzer()); | ||
} | ||
|
||
[Test][Category("InspectionXmlDoc")] | ||
public void NegativeIfNotInNamespaceRubberduckCodeAnalysisInspectionConcrete() | ||
{ | ||
var test = @" | ||
namespace Rubberduck.CodeAnalysis.Inspections.NotConcrete | ||
{ | ||
/// <summary> | ||
/// blablabla | ||
/// </summary> | ||
/// <why> | ||
/// blablabla | ||
/// </why> | ||
/// <example hasresult=""true""> | ||
/// <![CDATA[ | ||
/// Public Sub DoSomething() | ||
/// ' ... | ||
/// End Sub | ||
/// ]]> | ||
/// </example> | ||
public sealed class SomeInspection : IInspection { } | ||
} | ||
"; | ||
|
||
var diagnostics = GetDiagnostics(test); | ||
Assert.IsFalse(diagnostics.Any(d => d.Descriptor.Id == InspectionXmlDocAnalyzer.MissingInspectionSummaryElement)); | ||
} | ||
|
||
[Test][Category("InspectionXmlDoc")] | ||
public void NegativeIfNotInInheritingIInspection() | ||
{ | ||
var test = @" | ||
namespace Rubberduck.CodeAnalysis.Inspections.Abstract | ||
{ | ||
/// <summary> | ||
/// blablabla | ||
/// </summary> | ||
/// <why> | ||
/// blablabla | ||
/// </why> | ||
/// <example hasresult=""true""> | ||
/// <![CDATA[ | ||
/// Public Sub DoSomething() | ||
/// ' ... | ||
/// End Sub | ||
/// ]]> | ||
/// </example> | ||
public sealed class SomeInspection : NotIInspection { } | ||
} | ||
"; | ||
|
||
var diagnostics = GetDiagnostics(test); | ||
Assert.IsFalse(diagnostics.Any(d => d.Descriptor.Id == InspectionXmlDocAnalyzer.MissingInspectionSummaryElement)); | ||
} | ||
|
||
[Test][Category("InspectionXmlDoc")] | ||
public void MissingInspectionSummary_Negative() | ||
{ | ||
var test = @" | ||
namespace Rubberduck.CodeAnalysis.Inspections.Concrete | ||
{ | ||
/// <summary> | ||
/// blablabla | ||
/// </summary> | ||
/// <why> | ||
/// blablabla | ||
/// </why> | ||
/// <example hasresult=""true""> | ||
/// <![CDATA[ | ||
/// Public Sub DoSomething() | ||
/// ' ... | ||
/// End Sub | ||
/// ]]> | ||
/// </example> | ||
public sealed class SomeInspection : IInspection { } | ||
} | ||
"; | ||
|
||
var diagnostics = GetDiagnostics(test); | ||
Assert.IsFalse(diagnostics.Any(d => d.Descriptor.Id == InspectionXmlDocAnalyzer.MissingInspectionSummaryElement)); | ||
} | ||
|
||
[Test][Category("InspectionXmlDoc")] | ||
public void MissingInspectionSummary() | ||
{ | ||
var test = @" | ||
namespace Rubberduck.CodeAnalysis.Inspections.Concrete | ||
{ | ||
/// <why> | ||
/// blablabla | ||
/// </why> | ||
/// <example hasresult=""true""> | ||
/// <![CDATA[ | ||
/// Public Sub DoSomething() | ||
/// ' ... | ||
/// End Sub | ||
/// ]]> | ||
/// </example> | ||
public sealed class SomeInspection : IInspection { } | ||
} | ||
"; | ||
|
||
var diagnostics = GetDiagnostics(test); | ||
Assert.IsTrue(diagnostics.Any(d => d.Descriptor.Id == InspectionXmlDocAnalyzer.MissingInspectionSummaryElement)); | ||
} | ||
|
||
|
||
[Test][Category("InspectionXmlDoc")] | ||
public void MissingInspectionWhyElement() | ||
{ | ||
var test = @" | ||
namespace Rubberduck.CodeAnalysis.Inspections.Concrete | ||
{ | ||
/// <summary> | ||
/// blablabla | ||
/// </summary> | ||
/// <example hasresult=""true""> | ||
/// <![CDATA[ | ||
/// Public Sub DoSomething() | ||
/// ' ... | ||
/// End Sub | ||
/// ]]> | ||
/// </example> | ||
public sealed class SomeInspection : IInspection { } | ||
} | ||
"; | ||
|
||
var diagnostics = GetDiagnostics(test); | ||
Assert.IsTrue(diagnostics.Any(d => d.Descriptor.Id == InspectionXmlDocAnalyzer.MissingInspectionWhyElement)); | ||
} | ||
|
||
[Test][Category("InspectionXmlDoc")] | ||
public void MissingInspectionWhyElement_Negative() | ||
{ | ||
var test = @" | ||
namespace Rubberduck.CodeAnalysis.Inspections.Concrete | ||
{ | ||
/// <summary> | ||
/// blablabla | ||
/// </summary> | ||
/// <why> | ||
/// blablabla | ||
/// </why> | ||
/// <example hasresult=""true""> | ||
/// <![CDATA[ | ||
/// Public Sub DoSomething() | ||
/// ' ... | ||
/// End Sub | ||
/// ]]> | ||
/// </example> | ||
public sealed class SomeInspection : IInspection { } | ||
} | ||
"; | ||
|
||
var diagnostics = GetDiagnostics(test); | ||
Assert.IsFalse(diagnostics.Any(d => d.Descriptor.Id == InspectionXmlDocAnalyzer.MissingInspectionWhyElement)); | ||
} | ||
|
||
[Test][Category("InspectionXmlDoc")] | ||
public void MissingHasResultAttribute_Misspelled() | ||
{ | ||
var test = @" | ||
namespace Rubberduck.CodeAnalysis.Inspections.Concrete | ||
{ | ||
/// <summary> | ||
/// blablabla | ||
/// </summary> | ||
/// <why> | ||
/// blablabla | ||
/// </why> | ||
/// <example hasResults=""true""> | ||
/// <![CDATA[ | ||
/// Public Sub DoSomething() | ||
/// ' ... | ||
/// End Sub | ||
/// ]]> | ||
/// </example> | ||
public sealed class SomeInspection : IInspection { } | ||
} | ||
"; | ||
|
||
var diagnostics = GetDiagnostics(test); | ||
Assert.IsTrue(diagnostics.Any(d => d.Descriptor.Id == InspectionXmlDocAnalyzer.MissingHasResultAttribute)); | ||
} | ||
|
||
[Test][Category("InspectionXmlDoc")] | ||
public void MissingHasResultAttribute_Missing() | ||
{ | ||
var test = @" | ||
namespace Rubberduck.CodeAnalysis.Inspections.Concrete | ||
{ | ||
/// <summary> | ||
/// blablabla | ||
/// </summary> | ||
/// <why> | ||
/// blablabla | ||
/// </why> | ||
/// <example> | ||
/// <![CDATA[ | ||
/// Public Sub DoSomething() | ||
/// ' ... | ||
/// End Sub | ||
/// ]]> | ||
/// </example> | ||
public sealed class SomeInspection : IInspection { } | ||
} | ||
"; | ||
|
||
var diagnostics = GetDiagnostics(test); | ||
Assert.IsTrue(diagnostics.Any(d => d.Descriptor.Id == InspectionXmlDocAnalyzer.MissingHasResultAttribute)); | ||
} | ||
|
||
[Test][Category("InspectionXmlDoc")] | ||
public void MissingHasResultAttribute_Negative() | ||
{ | ||
var test = @" | ||
namespace Rubberduck.CodeAnalysis.Inspections.Concrete | ||
{ | ||
/// <summary> | ||
/// blablabla | ||
/// </summary> | ||
/// <why> | ||
/// blablabla | ||
/// </why> | ||
/// <example hasresult=""true""> | ||
/// <![CDATA[ | ||
/// Public Sub DoSomething() | ||
/// ' ... | ||
/// End Sub | ||
/// ]]> | ||
/// </example> | ||
public sealed class SomeInspection : IInspection { } | ||
} | ||
"; | ||
|
||
var diagnostics = GetDiagnostics(test); | ||
Assert.IsFalse(diagnostics.Any(d => d.Descriptor.Id == InspectionXmlDocAnalyzer.MissingHasResultAttribute)); | ||
} | ||
} | ||
} |