internal/shader: refactoring

This commit is contained in:
Hajime Hoshi 2022-11-20 18:25:08 +09:00
parent dc1df824a5
commit 5aecd6762c

View File

@ -1202,39 +1202,31 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
} }
func TestSyntaxAtan(t *testing.T) { func TestSyntaxAtan(t *testing.T) {
cases := []struct {
stmt string
err bool
}{
// `atan` takes 1 argument. // `atan` takes 1 argument.
if _, err := compileToIR([]byte(`package main {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)
}
if _, err := compileToIR([]byte(`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. // `atan2` takes 2 arguments.
if _, err := compileToIR([]byte(`package main {stmt: "_ = atan2(vec4(0))", err: true},
{stmt: "_ = atan2(vec4(0), vec4(0))", err: false},
}
for _, c := range cases {
_, err := compileToIR([]byte(fmt.Sprintf(`package main
func Fragment(position vec4, texCoord vec2, color vec4) vec4 { func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
return atan2(vec4(0)) %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)
} }
`)); 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)
} }
} }