From 5aecd6762c7f2dda0a9ba82a313d303205ce740e Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 20 Nov 2022 18:25:08 +0900 Subject: [PATCH] internal/shader: refactoring --- internal/shader/syntax_test.go | 50 ++++++++++++++-------------------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/internal/shader/syntax_test.go b/internal/shader/syntax_test.go index f90b53852..f2a8a081d 100644 --- a/internal/shader/syntax_test.go +++ b/internal/shader/syntax_test.go @@ -1202,39 +1202,31 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { } func TestSyntaxAtan(t *testing.T) { - // `atan` takes 1 argument. - if _, err := compileToIR([]byte(`package main + cases := []struct { + stmt string + err bool + }{ + // `atan` takes 1 argument. + {stmt: "_ = atan(vec4(0))", err: false}, + {stmt: "_ = atan(vec4(0), vec4(0))", err: true}, -func Fragment(position vec4, texCoord vec2, color vec4) vec4 { - return atan(vec4(0)) -} -`)); err != nil { - t.Error(err) + // `atan2` takes 2 arguments. + {stmt: "_ = atan2(vec4(0))", err: true}, + {stmt: "_ = atan2(vec4(0), vec4(0))", err: false}, } - if _, err := compileToIR([]byte(`package main + + for _, c := range cases { + _, err := compileToIR([]byte(fmt.Sprintf(`package main func Fragment(position vec4, texCoord vec2, color vec4) vec4 { - return atan(vec4(0), vec4(0)) -} -`)); err == nil { - t.Errorf("error must be non-nil but was nil") - } - // `atan2` takes 2 arguments. - if _, err := compileToIR([]byte(`package main - -func Fragment(position vec4, texCoord vec2, color vec4) vec4 { - return atan2(vec4(0)) -} -`)); 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 { - return atan2(vec4(0), vec4(0)) -} -`)); err != nil { - t.Error(err) + %s + return position +}`, c.stmt))) + if err == nil && c.err { + t.Errorf("%s must return an error but does not", c.stmt) + } else if err != nil && !c.err { + t.Errorf("%s must not return nil but returned %v", c.stmt, err) + } } }