Improved source generator unit test

このコミットが含まれているのは:
Sergio Pedri committed 2020-11-25 01:17:39 +01:00
1 親 a028d3d93d
コミット 4240822465
1ファイル変更
+37 -6
+37 -6
ファイルの表示
@@ -17,8 +17,24 @@ namespace ComputeSharp.Tests.Internals
public void SequentialEnum()
{
string source = @"
using MyLibrary;
using System.Numerics;
using MyLibrary;
using ComputeSharp;
namespace ComputeSharp
{
public readonly struct ThreadIds
{
public int X => throw null;
public int Y => throw null;
public int Z => throw null;
}
public interface IComputeShader
{
void Execute((int X, int Y, int Z) ids);
}
}
namespace MyLibrary
{
@@ -39,16 +55,25 @@ namespace ComputeSharp.Tests.Internals
public partial class Foo
{
[AutoConstructor]
public readonly partial struct MyShader
public readonly partial struct MyShader : IComputeShader
{
private readonly Buffer<Vector4> A;
private readonly float B;
private readonly Vector4 B;
/// <inheritdoc/>
public void Execute(ThreadIds ids)
{
Vector4 foo = default;
Vector4 bar = default(Vector4);
Vector4 baz = B;
A[ids.X] = (Vector4)foo + bar + baz;
}
}
}
}
}";
string expected = @"
string expectedForAutoConstructor = @"
namespace MyFancyApp.Sample
{
public partial interface IFoo<T>
@@ -57,7 +82,7 @@ namespace ComputeSharp.Tests.Internals
{
public readonly partial struct MyShader
{
public MyShader(MyLibrary.Buffer<System.Numerics.Vector4> A, float B)
public MyShader(MyLibrary.Buffer<System.Numerics.Vector4> A, System.Numerics.Vector4 B)
{
this.A = A;
this.B = B;
@@ -67,7 +92,13 @@ namespace ComputeSharp.Tests.Internals
}
}";
VerifyGeneratedMethodLines<AutoConstructorAttributeGenerator>(source, 1, expected);
VerifyGeneratedMethodLines<AutoConstructorAttributeGenerator>(source, 0, expectedForAutoConstructor);
string expectedForShaderSource = @"
#pragma warning disable
[assembly: ComputeSharp.IComputeShaderSource(""MyFancyApp.Sample.IFoo`1+Foo+MyShader"", ""Execute"", ""void CSMain(uint3 ids : SV_DispatchThreadId)\r\n{\r\n if (ids.x < __x && ids.y < __y && ids.z < __z)\r\n {\r\n float4 foo = (float4)0;\r\n float4 bar = (float4)0;\r\n float4 baz = B;\r\n A[ids.x] = (float4)foo + bar + baz;\r\n }\r\n}"")]";
VerifyGeneratedMethodLines<IComputeShaderSourceAttributeGenerator>(source, 0, expectedForShaderSource);
}
/// <summary>