-
-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for missing descriptor attribute code fixer
- Loading branch information
1 parent
6a73364
commit 462d724
Showing
2 changed files
with
184 additions
and
1 deletion.
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
178 changes: 178 additions & 0 deletions
178
...rp.D2D1.Tests.SourceGenerators/Test_MissingPixelShaderDescriptorOnPixelShaderCodeFixer.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,178 @@ | ||
extern alias Core; | ||
extern alias D2D1; | ||
|
||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.Testing; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using CSharpCodeFixTest = Microsoft.CodeAnalysis.CSharp.Testing.CSharpCodeFixTest< | ||
ComputeSharp.D2D1.SourceGenerators.MissingPixelShaderDescriptorOnPixelShaderAnalyzer, | ||
ComputeSharp.D2D1.CodeFixers.MissingPixelShaderDescriptorOnPixelShaderCodeFixer, | ||
Microsoft.CodeAnalysis.Testing.Verifiers.MSTestVerifier>; | ||
|
||
namespace ComputeSharp.D2D1.Tests.SourceGenerators; | ||
|
||
[TestClass] | ||
public class Test_MissingPixelShaderDescriptorOnPixelShaderCodeFixer | ||
{ | ||
[TestMethod] | ||
public async Task FileContainsComputeSharpD2D1UsingDirective() | ||
{ | ||
string original = """ | ||
using ComputeSharp.D2D1; | ||
|
||
partial struct {|CMPSD2D0065:MyShader|} : ID2D1PixelShader | ||
{ | ||
public ComputeSharp.Float4 Execute() => 0; | ||
} | ||
"""; | ||
|
||
string @fixed = """ | ||
using ComputeSharp.D2D1; | ||
|
||
[D2DGeneratedPixelShaderDescriptor] | ||
partial struct MyShader : ID2D1PixelShader | ||
{ | ||
public ComputeSharp.Float4 Execute() => 0; | ||
} | ||
"""; | ||
|
||
CSharpCodeFixTest test = new() | ||
{ | ||
TestCode = original, | ||
FixedCode = @fixed, | ||
ReferenceAssemblies = ReferenceAssemblies.Net.Net60 | ||
}; | ||
|
||
test.TestState.AdditionalReferences.Add(typeof(Core::ComputeSharp.Float4).Assembly); | ||
test.TestState.AdditionalReferences.Add(typeof(D2D1::ComputeSharp.D2D1.ID2D1PixelShader).Assembly); | ||
test.TestState.AnalyzerConfigFiles.Add(("/.editorconfig", "[*]\nend_of_line = lf")); | ||
|
||
await test.RunAsync(); | ||
} | ||
|
||
[TestMethod] | ||
public async Task FileDoesNotContainComputeSharpD2D1UsingDirective() | ||
{ | ||
string original = """ | ||
partial struct {|CMPSD2D0065:MyShader|} : ComputeSharp.D2D1.ID2D1PixelShader | ||
{ | ||
public ComputeSharp.Float4 Execute() => 0; | ||
} | ||
"""; | ||
|
||
string @fixed = """ | ||
using ComputeSharp.D2D1; | ||
|
||
[D2DGeneratedPixelShaderDescriptor] | ||
partial struct MyShader : ComputeSharp.D2D1.ID2D1PixelShader | ||
{ | ||
public ComputeSharp.Float4 Execute() => 0; | ||
} | ||
"""; | ||
|
||
CSharpCodeFixTest test = new() | ||
{ | ||
TestCode = original, | ||
FixedCode = @fixed, | ||
ReferenceAssemblies = ReferenceAssemblies.Net.Net60 | ||
}; | ||
|
||
test.TestState.AdditionalReferences.Add(typeof(Core::ComputeSharp.Float4).Assembly); | ||
test.TestState.AdditionalReferences.Add(typeof(D2D1::ComputeSharp.D2D1.ID2D1PixelShader).Assembly); | ||
test.TestState.AnalyzerConfigFiles.Add(("/.editorconfig", "[*]\nend_of_line = lf")); | ||
|
||
await test.RunAsync(); | ||
} | ||
|
||
[TestMethod] | ||
public async Task InsertsAttributeAfterAllOtherD2DAttributes() | ||
{ | ||
string original = """ | ||
using ComputeSharp.D2D1; | ||
|
||
[D2DInputCount(1)] | ||
[D2DInputSimple(0)] | ||
partial struct {|CMPSD2D0065:MyShader|} : ID2D1PixelShader | ||
{ | ||
public ComputeSharp.Float4 Execute() => 0; | ||
} | ||
"""; | ||
|
||
string @fixed = """ | ||
using ComputeSharp.D2D1; | ||
|
||
[D2DInputCount(1)] | ||
[D2DInputSimple(0)] | ||
[D2DGeneratedPixelShaderDescriptor] | ||
partial struct MyShader : ID2D1PixelShader | ||
{ | ||
public ComputeSharp.Float4 Execute() => 0; | ||
} | ||
"""; | ||
|
||
CSharpCodeFixTest test = new() | ||
{ | ||
TestCode = original, | ||
FixedCode = @fixed, | ||
ReferenceAssemblies = ReferenceAssemblies.Net.Net60 | ||
}; | ||
|
||
test.TestState.AdditionalReferences.Add(typeof(Core::ComputeSharp.Float4).Assembly); | ||
test.TestState.AdditionalReferences.Add(typeof(D2D1::ComputeSharp.D2D1.ID2D1PixelShader).Assembly); | ||
test.TestState.AnalyzerConfigFiles.Add(("/.editorconfig", "[*]\nend_of_line = lf")); | ||
|
||
await test.RunAsync(); | ||
} | ||
|
||
[TestMethod] | ||
public async Task InsertsAttributeAfterAllOtherD2DAttributes_WithOtherNonD2DAttribute() | ||
{ | ||
string original = """ | ||
using System; | ||
using ComputeSharp.D2D1; | ||
|
||
[D2DInputCount(1)] | ||
[D2DInputSimple(0)] | ||
[Test] | ||
partial struct {|CMPSD2D0065:MyShader|} : ID2D1PixelShader | ||
{ | ||
public ComputeSharp.Float4 Execute() => 0; | ||
} | ||
|
||
public class TestAttribute : Attribute | ||
{ | ||
} | ||
"""; | ||
|
||
string @fixed = """ | ||
using System; | ||
using ComputeSharp.D2D1; | ||
|
||
[D2DInputCount(1)] | ||
[D2DInputSimple(0)] | ||
[D2DGeneratedPixelShaderDescriptor] | ||
[Test] | ||
partial struct MyShader : ID2D1PixelShader | ||
{ | ||
public ComputeSharp.Float4 Execute() => 0; | ||
} | ||
|
||
public class TestAttribute : Attribute | ||
{ | ||
} | ||
"""; | ||
|
||
CSharpCodeFixTest test = new() | ||
{ | ||
TestCode = original, | ||
FixedCode = @fixed, | ||
ReferenceAssemblies = ReferenceAssemblies.Net.Net60 | ||
}; | ||
|
||
test.TestState.AdditionalReferences.Add(typeof(Core::ComputeSharp.Float4).Assembly); | ||
test.TestState.AdditionalReferences.Add(typeof(D2D1::ComputeSharp.D2D1.ID2D1PixelShader).Assembly); | ||
test.TestState.AnalyzerConfigFiles.Add(("/.editorconfig", "[*]\nend_of_line = lf")); | ||
|
||
await test.RunAsync(); | ||
} | ||
} |