mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
shader: Add more tests
This commit is contained in:
parent
8ede0b3891
commit
73255f4663
@ -303,6 +303,7 @@ func (sh *Shader) parseFunc(d *ast.FuncDecl, block *block) function {
|
||||
}
|
||||
|
||||
var rets []variable
|
||||
if d.Type.Results != nil {
|
||||
for _, f := range d.Type.Results.List {
|
||||
t := parseType(f.Type)
|
||||
if t == typNone {
|
||||
@ -323,6 +324,7 @@ func (sh *Shader) parseFunc(d *ast.FuncDecl, block *block) function {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return function{
|
||||
name: d.Name.Name,
|
||||
@ -397,7 +399,11 @@ func (s *Shader) detectType(b *block, expr ast.Expr) typ {
|
||||
if e.Kind == token.FLOAT {
|
||||
return typFloat
|
||||
}
|
||||
if e.Kind == token.INT {
|
||||
s.addError(expr.Pos(), fmt.Sprintf("integer literal is not implemented yet: %s", e.Value))
|
||||
} else {
|
||||
s.addError(expr.Pos(), fmt.Sprintf("unexpected literal: %s", e.Value))
|
||||
}
|
||||
return typNone
|
||||
case *ast.CompositeLit:
|
||||
return parseType(e.Type)
|
||||
@ -425,7 +431,9 @@ func (s *Shader) detectType(b *block, expr ast.Expr) typ {
|
||||
func (s *Shader) Dump() string {
|
||||
var lines []string
|
||||
|
||||
if s.position.name != "" {
|
||||
lines = append(lines, fmt.Sprintf("var %s varying %s // position", s.position.name, s.position.typ))
|
||||
}
|
||||
for _, v := range s.varyings {
|
||||
lines = append(lines, fmt.Sprintf("var %s varying %s", v.name, v.typ))
|
||||
}
|
||||
|
@ -23,12 +23,12 @@ import (
|
||||
func TestDump(t *testing.T) {
|
||||
tests := []struct {
|
||||
Name string
|
||||
In string
|
||||
Src string
|
||||
Dump string
|
||||
}{
|
||||
{
|
||||
Name: "general",
|
||||
In: `package main
|
||||
Src: `package main
|
||||
|
||||
type VertexOut struct {
|
||||
Position vec4 ` + "`kage:\"position\"`" + `
|
||||
@ -74,11 +74,27 @@ func F1(a vec2, b vec2) (_ vec4) {
|
||||
c3 = vec4{c0, c1}
|
||||
return c2
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
Name: "Type",
|
||||
Src: `package main
|
||||
|
||||
var c0 = 0.0
|
||||
func F() {
|
||||
c1 := c0
|
||||
}
|
||||
`,
|
||||
Dump: `var c0 float = 0.0
|
||||
func F() {
|
||||
var c1 float
|
||||
c1 = c0
|
||||
}
|
||||
`,
|
||||
},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
s, err := NewShader([]byte(tc.In))
|
||||
s, err := NewShader([]byte(tc.Src))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
continue
|
||||
|
Loading…
Reference in New Issue
Block a user