ebiten/internal/shader/shader_test.go

151 lines
2.3 KiB
Go
Raw Normal View History

2020-05-08 17:46:01 +02:00
// Copyright 2020 The Ebiten Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package shader_test
import (
"testing"
. "github.com/hajimehoshi/ebiten/internal/shader"
)
2020-05-09 10:19:05 +02:00
func TestDump(t *testing.T) {
2020-05-08 17:46:01 +02:00
tests := []struct {
2020-05-10 12:48:24 +02:00
Name string
2020-05-10 13:41:43 +02:00
Src string
2020-05-08 17:46:01 +02:00
Dump string
}{
{
2020-05-10 12:48:24 +02:00
Name: "general",
2020-05-10 13:41:43 +02:00
Src: `package main
2020-05-09 11:05:30 +02:00
2020-05-08 17:46:01 +02:00
type VertexOut struct {
Position vec4 ` + "`kage:\"position\"`" + `
TexCoord vec2
Color vec4
}
var Foo float
var (
Bar vec2
Baz, Quux vec3
)
2020-05-08 21:21:45 +02:00
const C1 float = 1
const C2, C3 float = 2, 3
2020-05-09 10:19:05 +02:00
2020-05-09 16:38:52 +02:00
func F1(a, b vec2) vec4 {
var c0 vec2 = a
2020-05-10 12:32:40 +02:00
var c1, c2 = c0, 1.0
2020-05-09 16:58:22 +02:00
c1.x = c2.x
c3 := vec4{c0, c1}
2020-05-09 16:38:52 +02:00
return c2
2020-05-09 10:19:05 +02:00
}
2020-05-08 17:46:01 +02:00
`,
2020-05-10 17:13:08 +02:00
Dump: `var Bar uniform vec2
var Baz uniform vec3
var Foo uniform float
var Quux uniform vec3
2020-05-10 17:13:08 +02:00
type VertexOut struct {
Position vec4
TexCoord vec2
Color vec4
}
2020-05-08 21:21:45 +02:00
const C1 float = 1
const C2 float = 2
const C3 float = 3
2020-05-09 16:38:52 +02:00
func F1(a vec2, b vec2) (_ vec4) {
2020-05-09 19:01:28 +02:00
var c0 vec2 = a
2020-05-10 12:48:24 +02:00
var c1 vec2 = c0
2020-05-10 12:32:40 +02:00
var c2 vec2 = 1.0
var c3 vec4
2020-05-09 19:01:28 +02:00
c1.x = c2.x
c3 = vec4{c0, c1}
2020-05-09 16:58:22 +02:00
return c2
2020-05-09 16:38:52 +02:00
}
2020-05-10 13:41:43 +02:00
`,
},
{
2020-05-10 14:37:59 +02:00
Name: "AutoType",
Src: `package main
var V0 = 0.0
2020-05-10 14:37:59 +02:00
func F() {
v1 := V0
2020-05-10 14:37:59 +02:00
}
`,
Dump: `var V0 uniform float
2020-05-10 14:37:59 +02:00
func F() {
var v1 float
v1 = V0
2020-05-10 14:37:59 +02:00
}
`,
},
{
Name: "AutoType2",
Src: `package main
var V0 = 0.0
2020-05-10 14:37:59 +02:00
func F() {
v1 := V0
2020-05-10 14:37:59 +02:00
{
v2 := v1
}
}
`,
Dump: `var V0 uniform float
2020-05-10 14:37:59 +02:00
func F() {
var v1 float
v1 = V0
2020-05-10 14:37:59 +02:00
{
var v2 float
v2 = v1
}
2020-05-10 13:41:43 +02:00
}
2020-05-08 17:46:01 +02:00
`,
},
2020-05-10 16:19:39 +02:00
/*{
Name: "Struct",
Src: `package main
type S struct {
M0 float
M1, M2 vec2
M3, M4, M5 vec3
}
`,
Dump: `var V0 uniform float
type S struct {
M0 float
M1 vec2
M2 vec2
M3 vec3
M4 vec3
M5 vec3
}
`,
},*/
2020-05-08 17:46:01 +02:00
}
for _, tc := range tests {
2020-05-10 13:41:43 +02:00
s, err := NewShader([]byte(tc.Src))
2020-05-08 17:46:01 +02:00
if err != nil {
t.Error(err)
continue
}
if got, want := s.Dump(), tc.Dump; got != want {
2020-05-10 12:48:24 +02:00
t.Errorf("%s: got: %v, want: %v", tc.Name, got, want)
2020-05-08 17:46:01 +02:00
}
}
}