From 0657e67cefe89a74cd8a4e99d3d285e51be4c377 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 24 Jul 2023 02:00:00 +0900 Subject: [PATCH] internal/shader: add more tests for % op --- internal/shader/syntax_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/internal/shader/syntax_test.go b/internal/shader/syntax_test.go index 9a1a9295b..bfeec5fe3 100644 --- a/internal/shader/syntax_test.go +++ b/internal/shader/syntax_test.go @@ -738,6 +738,15 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { }`)); err == nil { t.Errorf("error must be non-nil but was nil") } + if _, err := compileToIR([]byte(`package main + +func Fragment(position vec4, texCoord vec2, color vec4) vec4 { + // If both are constants, both must be an integer! + a := 2.0 % 1.0 + return vec4(a) +}`)); err == nil { + t.Errorf("error must be non-nil but was nil") + } if _, err := compileToIR([]byte(`package main @@ -808,6 +817,16 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { if _, err := compileToIR([]byte(`package main +func Fragment(position vec4, texCoord vec2, color vec4) vec4 { + // If only one of two is a consntant, the constant can be a float. + a := 2 + return vec4(a % 1.0) +}`)); err != nil { + t.Error(err) + } + + if _, err := compileToIR([]byte(`package main + func Fragment(position vec4, texCoord vec2, color vec4) vec4 { a := 1 return vec4(2 % a) @@ -817,6 +836,16 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { if _, err := compileToIR([]byte(`package main +func Fragment(position vec4, texCoord vec2, color vec4) vec4 { + // If only one of two is a consntant, the constant can be a float. + a := 1 + return vec4(2.0 % a) +}`)); err != nil { + t.Error(err) + } + + if _, err := compileToIR([]byte(`package main + func Fragment(position vec4, texCoord vec2, color vec4) vec4 { a := 2 a %= 1