-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
15 changed files
with
569 additions
and
24 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
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
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace Sungaila.InlineTest.Tests | ||
{ | ||
public class MethodOverloadTests | ||
{ | ||
[AreEqual(Expected = (string?)null)] | ||
public static string? EchoValue() => null; | ||
|
||
[AreEqual("Moin Moin", Expected = "Moin Moin")] | ||
public static string? EchoValue(string input) => input; | ||
|
||
[AreEqual("Moin Moin", Expected = "Moin Moin")] | ||
public static object? EchoValue(object input) => input; | ||
|
||
[AreEqual(1994, Expected = 1994)] | ||
public static int EchoValue(int input) => input; | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
namespace Sungaila.InlineTest.Tests | ||
{ | ||
public struct StructTests | ||
{ | ||
// structs must have a parameterless constructor | ||
// so this dummy constructor should be fine | ||
public StructTests(object? something) { } | ||
|
||
[AreEqual("Moin Moin", Expected = "Moin Moin")] | ||
public string? EchoValueInstance(string input) => input; | ||
|
||
[AreEqual("Moin Moin", Expected = "Moin Moin")] | ||
public static string? EchoValueStatic(string input) => input; | ||
|
||
public struct SubStructDepth1 | ||
{ | ||
[AreEqual("Moin Moin", Expected = "Moin Moin")] | ||
public string? EchoValueInstance(string input) => input; | ||
|
||
[AreEqual("Moin Moin", Expected = "Moin Moin")] | ||
public static string? EchoValueStatic(string input) => input; | ||
|
||
public struct SubStructDepth2 | ||
{ | ||
[AreEqual("Moin Moin", Expected = "Moin Moin")] | ||
public string? EchoValueInstance(string input) => input; | ||
|
||
[AreEqual("Moin Moin", Expected = "Moin Moin")] | ||
public static string? EchoValueStatic(string input) => input; | ||
|
||
public struct SubStructDepth3 | ||
{ | ||
[AreEqual("Moin Moin", Expected = "Moin Moin")] | ||
public string? EchoValueInstance(string input) => input; | ||
|
||
[AreEqual("Moin Moin", Expected = "Moin Moin")] | ||
public static string? EchoValueStatic(string input) => input; | ||
|
||
public struct SubStructDepth4 | ||
{ | ||
[AreEqual("Moin Moin", Expected = "Moin Moin")] | ||
public string? EchoValueInstance(string input) => input; | ||
|
||
[AreEqual("Moin Moin", Expected = "Moin Moin")] | ||
public static string? EchoValueStatic(string input) => input; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
namespace Sungaila.InlineTest.Tests | ||
{ | ||
public class SubClassTests | ||
{ | ||
[AreEqual(Expected = 0.0d)] | ||
public double GetRealInstance() => 0.0d; | ||
|
||
[AreEqual(Expected = 0.0d)] | ||
public static double GetRealStatic() => 0.0d; | ||
|
||
public class SubClassDepth1 | ||
{ | ||
[AreEqual(Expected = 0.0d)] | ||
public double GetRealInstance() => 0.0d; | ||
|
||
[AreEqual(Expected = 0.0d)] | ||
public static double GetRealStatic() => 0.0d; | ||
|
||
public class SubClassDepth2 | ||
{ | ||
[AreEqual(Expected = 0.0d)] | ||
public double GetRealInstance() => 0.0d; | ||
|
||
[AreEqual(Expected = 0.0d)] | ||
public static double GetRealStatic() => 0.0d; | ||
|
||
public class SubClassDepth3 | ||
{ | ||
[AreEqual(Expected = 0.0d)] | ||
public double GetRealInstance() => 0.0d; | ||
|
||
[AreEqual(Expected = 0.0d)] | ||
public static double GetRealStatic() => 0.0d; | ||
|
||
public class SubClassDepth4 | ||
{ | ||
[AreEqual(Expected = 0.0d)] | ||
public double GetRealInstance() => 0.0d; | ||
|
||
[AreEqual(Expected = 0.0d)] | ||
public static double GetRealStatic() => 0.0d; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
; Shipped analyzer releases | ||
; https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md | ||
|
||
## Release 1.0.0 | ||
|
||
### New Rules | ||
|
||
Rule ID | Category | Severity | Notes | ||
--------|----------|----------|------- | ||
IT0000 | Method | Error | InlineTestAnalyzer, [Documentation](https://github.com/sungaila/InlineTest) | ||
IT0001 | Method | Error | InlineTestAnalyzer, [Documentation](https://github.com/sungaila/InlineTest) | ||
IT0002 | Method | Error | InlineTestAnalyzer, [Documentation](https://github.com/sungaila/InlineTest) | ||
IT0003 | Method | Warning | InlineTestAnalyzer, [Documentation](https://github.com/sungaila/InlineTest) | ||
IT0004 | Style | Warning | InlineTestAnalyzer, [Documentation](https://github.com/sungaila/InlineTest) | ||
IT0005 | Style | Warning | InlineTestAnalyzer, [Documentation](https://github.com/sungaila/InlineTest) |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
; Unshipped analyzer release | ||
; https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md | ||
|
68 changes: 68 additions & 0 deletions
68
src/InlineTest/CodeFixProviders/AreEqualNoExpectedValueCodeFixProvider.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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CodeActions; | ||
using Microsoft.CodeAnalysis.CodeFixes; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
using System.Collections.Immutable; | ||
using System.Composition; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Sungaila.InlineTest.CodeFixProviders | ||
{ | ||
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(AreEqualNoExpectedValueCodeFixProvider)), Shared] | ||
internal class AreEqualNoExpectedValueCodeFixProvider : CodeFixProvider | ||
{ | ||
public override ImmutableArray<string> FixableDiagnosticIds => ImmutableArray.Create(InlineTestAnalyzer.AreEqualNoExpectedValueId); | ||
|
||
public override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer; | ||
|
||
public override async Task RegisterCodeFixesAsync(CodeFixContext context) | ||
{ | ||
#if FALSE && DEBUG | ||
if (!System.Diagnostics.Debugger.IsAttached) | ||
{ | ||
System.Diagnostics.Debugger.Launch(); | ||
} | ||
#endif | ||
var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); | ||
|
||
var diagnostic = context.Diagnostics.Single(); | ||
var diagnosticSpan = diagnostic.Location.SourceSpan; | ||
var declaration = root!.FindToken(diagnosticSpan.Start).Parent!.FirstAncestorOrSelf<AttributeSyntax>(); | ||
|
||
context.RegisterCodeFix( | ||
CodeAction.Create( | ||
"Add Expected parameter", | ||
c => AddExpectedParameterAsync(context.Document, declaration!, c), | ||
"Add Expected parameter" | ||
), | ||
diagnostic); | ||
} | ||
|
||
private async Task<Document> AddExpectedParameterAsync(Document document, AttributeSyntax attributeSyntax, CancellationToken cancellationToken) | ||
{ | ||
var newArgument = SyntaxFactory.AttributeArgument( | ||
SyntaxFactory.NameEquals(nameof(AreEqualAttribute.Expected)), | ||
null, | ||
SyntaxFactory.LiteralExpression(SyntaxKind.DefaultLiteralExpression) | ||
); | ||
|
||
var oldRoot = await document.GetSyntaxRootAsync(cancellationToken); | ||
SyntaxNode newRoot; | ||
|
||
if (attributeSyntax.ArgumentList == null) | ||
{ | ||
newRoot = oldRoot!.ReplaceNode(attributeSyntax, | ||
attributeSyntax.WithArgumentList(SyntaxFactory.AttributeArgumentList(SyntaxFactory.SeparatedList(new[] { newArgument })))); | ||
} | ||
else | ||
{ | ||
newRoot = oldRoot!.ReplaceNode(attributeSyntax, attributeSyntax.AddArgumentListArguments(newArgument)); | ||
} | ||
|
||
return document.WithSyntaxRoot(newRoot); | ||
} | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
src/InlineTest/CodeFixProviders/AreNotEqualNoNotExpectedValueCodeFixProvider.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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CodeActions; | ||
using Microsoft.CodeAnalysis.CodeFixes; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
using System.Collections.Immutable; | ||
using System.Composition; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Sungaila.InlineTest.CodeFixProviders | ||
{ | ||
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(AreEqualNoExpectedValueCodeFixProvider)), Shared] | ||
internal class AreNotEqualNoNotExpectedValueCodeFixProvider : CodeFixProvider | ||
{ | ||
public override ImmutableArray<string> FixableDiagnosticIds => ImmutableArray.Create(InlineTestAnalyzer.AreNotEqualNoNotExpectedValueId); | ||
|
||
public override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer; | ||
|
||
public override async Task RegisterCodeFixesAsync(CodeFixContext context) | ||
{ | ||
#if FALSE && DEBUG | ||
if (!System.Diagnostics.Debugger.IsAttached) | ||
{ | ||
System.Diagnostics.Debugger.Launch(); | ||
} | ||
#endif | ||
var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); | ||
|
||
var diagnostic = context.Diagnostics.Single(); | ||
var diagnosticSpan = diagnostic.Location.SourceSpan; | ||
var declaration = root!.FindToken(diagnosticSpan.Start).Parent!.FirstAncestorOrSelf<AttributeSyntax>(); | ||
|
||
context.RegisterCodeFix( | ||
CodeAction.Create( | ||
"Add NotExpected parameter", | ||
c => AddExpectedParameterAsync(context.Document, declaration!, c), | ||
"Add NotExpected parameter" | ||
), | ||
diagnostic); | ||
} | ||
|
||
private async Task<Document> AddExpectedParameterAsync(Document document, AttributeSyntax attributeSyntax, CancellationToken cancellationToken) | ||
{ | ||
var newArgument = SyntaxFactory.AttributeArgument( | ||
SyntaxFactory.NameEquals(nameof(AreNotEqualAttribute.NotExpected)), | ||
null, | ||
SyntaxFactory.LiteralExpression(SyntaxKind.DefaultLiteralExpression) | ||
); | ||
|
||
var oldRoot = await document.GetSyntaxRootAsync(cancellationToken); | ||
SyntaxNode newRoot; | ||
|
||
if (attributeSyntax.ArgumentList == null) | ||
{ | ||
newRoot = oldRoot!.ReplaceNode(attributeSyntax, | ||
attributeSyntax.WithArgumentList(SyntaxFactory.AttributeArgumentList(SyntaxFactory.SeparatedList(new[] { newArgument })))); | ||
} | ||
else | ||
{ | ||
newRoot = oldRoot!.ReplaceNode(attributeSyntax, attributeSyntax.AddArgumentListArguments(newArgument)); | ||
} | ||
|
||
return document.WithSyntaxRoot(newRoot); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.