From 1817d97df5c32b59125baa57d641630e9a45ebc6 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 7 Mar 2021 20:29:04 +0100 Subject: [PATCH] Added unit tests for shader constant properties --- .../DiagnosticsTests.cs | 143 ++++++++++++++++++ 1 file changed, 143 insertions(+) diff --git a/tests/ComputeSharp.Tests.Internals.SourceGenerators/DiagnosticsTests.cs b/tests/ComputeSharp.Tests.Internals.SourceGenerators/DiagnosticsTests.cs index 40ea4c4a..2eaa16b3 100644 --- a/tests/ComputeSharp.Tests.Internals.SourceGenerators/DiagnosticsTests.cs +++ b/tests/ComputeSharp.Tests.Internals.SourceGenerators/DiagnosticsTests.cs @@ -1138,6 +1138,149 @@ namespace ComputeSharp.Tests.Internals VerifyGeneratedDiagnostics(source, "CMPS0042"); } + [TestMethod] + public void InvalidShaderConstantPropertyType() + { + string source = @" + using ComputeSharp; + + namespace ComputeSharp + { + public class ReadWriteBuffer { } + } + + namespace MyFancyApp.Sample + { + public struct MyShader : IComputeShader + { + public ReadWriteBuffer buffer; + + private static string Pi => ""Hello""; + + public void Execute() + { + } + } + }"; + + VerifyGeneratedDiagnostics(source, "CMPS0043"); + } + + [TestMethod] + public void InvalidShaderConstantPropertyDeclaration_AutoProp() + { + string source = @" + using ComputeSharp; + + namespace ComputeSharp + { + public class ReadWriteBuffer { } + } + + namespace MyFancyApp.Sample + { + public struct MyShader : IComputeShader + { + public ReadWriteBuffer buffer; + + private static float Pi { get; } = 3.14f; + + public void Execute() + { + } + } + }"; + + VerifyGeneratedDiagnostics(source, "CMPS0044"); + } + + [TestMethod] + public void InvalidShaderConstantPropertyDeclaration_GetterBlock() + { + string source = @" + using ComputeSharp; + + namespace ComputeSharp + { + public class ReadWriteBuffer { } + } + + namespace MyFancyApp.Sample + { + public struct MyShader : IComputeShader + { + public ReadWriteBuffer buffer; + + private static float Pi + { + get => 3.14f; + } + + public void Execute() + { + } + } + }"; + + VerifyGeneratedDiagnostics(source, "CMPS0044"); + } + + [TestMethod] + public void NonReadonlyShaderPropertyDeclaration() + { + string source = @" + using ComputeSharp; + + namespace ComputeSharp + { + public class ReadWriteBuffer { } + } + + namespace MyFancyApp.Sample + { + public struct MyShader : IComputeShader + { + public ReadWriteBuffer buffer; + + private static float Pi { get; set; } = 3.14f; + + public void Execute() + { + } + } + }"; + + VerifyGeneratedDiagnostics(source, "CMPS0045"); + } + + [TestMethod] + public void InstanceShaderPropertyDeclaration() + { + string source = @" + using ComputeSharp; + + namespace ComputeSharp + { + public class ReadWriteBuffer { } + } + + namespace MyFancyApp.Sample + { + public struct MyShader : IComputeShader + { + public ReadWriteBuffer buffer; + + private float Pi => 3.14f; + + public void Execute() + { + } + } + }"; + + VerifyGeneratedDiagnostics(source, "CMPS0046"); + } + /// /// Verifies the output of a source generator. ///