From 42408224653e246f84ed3a44eb42226600e8dfa5 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 25 Nov 2020 00:07:12 +0100 Subject: [PATCH] Improved source generator unit test --- .../SourceGeneratorTests.cs | 43 ++++++++++++++++--- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/tests/ComputeSharp.Tests.Internals/SourceGeneratorTests.cs b/tests/ComputeSharp.Tests.Internals/SourceGeneratorTests.cs index 8ac59224..abff9951 100644 --- a/tests/ComputeSharp.Tests.Internals/SourceGeneratorTests.cs +++ b/tests/ComputeSharp.Tests.Internals/SourceGeneratorTests.cs @@ -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 A; - private readonly float B; + private readonly Vector4 B; + + /// + 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 @@ -57,7 +82,7 @@ namespace ComputeSharp.Tests.Internals { public readonly partial struct MyShader { - public MyShader(MyLibrary.Buffer A, float B) + public MyShader(MyLibrary.Buffer A, System.Numerics.Vector4 B) { this.A = A; this.B = B; @@ -67,7 +92,13 @@ namespace ComputeSharp.Tests.Internals } }"; - VerifyGeneratedMethodLines(source, 1, expected); + VerifyGeneratedMethodLines(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(source, 0, expectedForShaderSource); } ///