diff --git a/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs b/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs index bce97fe5..5dc60816 100644 --- a/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs +++ b/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs @@ -1472,6 +1472,108 @@ public class DiagnosticsTests VerifyGeneratedDiagnostics(source, "CMPS0044"); } + [TestMethod] + public void InvalidEmbeddedBytecodeDispatchSize_Flags() + { + string source = $@" + using System; + using ComputeSharp; + + namespace ComputeSharp + {{ + public interface IComputeShader {{ }} + public class ReadWriteBuffer {{ }} + public enum DispatchAxis {{ X, Y, Z, XY, XZ, YZ, XYZ }} + public class EmbeddedBytecodeAttribute : Attribute + {{ + public EmbeddedBytecodeAttribute(DispatchAxis dispatchAxis) {{ }} + }} + }} + + namespace MyFancyApp.Sample + {{ + [EmbeddedBytecode(DispatchAxis.XYZ | DispatchAxis.Y)] + public struct MyShader : IComputeShader + {{ + public ReadWriteBuffer buffer; + + public void Execute() + {{ + }} + }} + }}"; + + VerifyGeneratedDiagnostics(source, "CMPS0048"); + } + + [TestMethod] + public void InvalidEmbeddedBytecodeDispatchSize_ExplicitValue() + { + string source = $@" + using System; + using ComputeSharp; + + namespace ComputeSharp + {{ + public interface IComputeShader {{ }} + public class ReadWriteBuffer {{ }} + public enum DispatchAxis {{ X, Y, Z, XY, XZ, YZ, XYZ }} + public class EmbeddedBytecodeAttribute : Attribute + {{ + public EmbeddedBytecodeAttribute(DispatchAxis dispatchAxis) {{ }} + }} + }} + + namespace MyFancyApp.Sample + {{ + [EmbeddedBytecode((DispatchAxis)243712)] + public struct MyShader : IComputeShader + {{ + public ReadWriteBuffer buffer; + + public void Execute() + {{ + }} + }} + }}"; + + VerifyGeneratedDiagnostics(source, "CMPS0048"); + } + + [TestMethod] + public void InvalidEmbeddedBytecodeDispatchSize_ExplicitValue_Negative() + { + string source = $@" + using System; + using ComputeSharp; + + namespace ComputeSharp + {{ + public interface IComputeShader {{ }} + public class ReadWriteBuffer {{ }} + public enum DispatchAxis {{ X, Y, Z, XY, XZ, YZ, XYZ }} + public class EmbeddedBytecodeAttribute : Attribute + {{ + public EmbeddedBytecodeAttribute(DispatchAxis dispatchAxis) {{ }} + }} + }} + + namespace MyFancyApp.Sample + {{ + [EmbeddedBytecode((DispatchAxis)(-289))] + public struct MyShader : IComputeShader + {{ + public ReadWriteBuffer buffer; + + public void Execute() + {{ + }} + }} + }}"; + + VerifyGeneratedDiagnostics(source, "CMPS0048"); + } + /// /// Verifies the output of a source generator. ///