Add Clusure ReturnType test

This commit is contained in:
z7zmey 2018-02-10 11:31:57 +02:00
parent 3ae13a3f04
commit 4c64183e0c

View File

@ -4,6 +4,8 @@ import (
"bytes" "bytes"
"testing" "testing"
"github.com/z7zmey/php-parser/node/name"
"github.com/z7zmey/php-parser/node/expr" "github.com/z7zmey/php-parser/node/expr"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
@ -80,3 +82,27 @@ func TestClosureUse(t *testing.T) {
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php") actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual) assertEqual(t, expected, actual)
} }
func TestClosureReturnType(t *testing.T) {
src := `<? function(): void {};`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.Closure{
ReturnsRef: false,
Static: false,
PhpDocComment: "",
Uses: []node.Node{},
ReturnType: &name.Name{
Parts: []node.Node{&name.NamePart{Value: "void"}},
},
Stmts: []node.Node{},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}