ClassMethod tests
This commit is contained in:
parent
1ef722b4bb
commit
14493d67e9
96
node/stmt/t_class_method_test.go
Normal file
96
node/stmt/t_class_method_test.go
Normal file
@ -0,0 +1,96 @@
|
||||
package stmt_test
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node/name"
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/node/stmt"
|
||||
"github.com/z7zmey/php-parser/php5"
|
||||
"github.com/z7zmey/php-parser/php7"
|
||||
)
|
||||
|
||||
func TestSimpleClassMethod(t *testing.T) {
|
||||
src := `<? class foo{ function bar() {} }`
|
||||
|
||||
expected := &stmt.StmtList{
|
||||
Stmts: []node.Node{
|
||||
&stmt.Class{
|
||||
ClassName: &node.Identifier{Value: "foo"},
|
||||
Stmts: []node.Node{
|
||||
&stmt.ClassMethod{
|
||||
PhpDocComment: "",
|
||||
MethodName: &node.Identifier{Value: "bar"},
|
||||
Stmts: []node.Node{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
|
||||
assertEqual(t, expected, actual)
|
||||
|
||||
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestPhp5ClassMethod(t *testing.T) {
|
||||
src := `<? class foo{ public static function &bar() {} }`
|
||||
|
||||
expected := &stmt.StmtList{
|
||||
Stmts: []node.Node{
|
||||
&stmt.Class{
|
||||
ClassName: &node.Identifier{Value: "foo"},
|
||||
Stmts: []node.Node{
|
||||
&stmt.ClassMethod{
|
||||
PhpDocComment: "",
|
||||
ReturnsRef: true,
|
||||
MethodName: &node.Identifier{Value: "bar"},
|
||||
Modifiers: []node.Node{
|
||||
&node.Identifier{Value: "public"},
|
||||
&node.Identifier{Value: "static"},
|
||||
},
|
||||
Stmts: []node.Node{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := php5.Parse(bytes.NewBufferString(src), "test.php")
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestPhp7ClassMethod(t *testing.T) {
|
||||
src := `<? class foo{ public static function &bar(): void {} }`
|
||||
|
||||
expected := &stmt.StmtList{
|
||||
Stmts: []node.Node{
|
||||
&stmt.Class{
|
||||
ClassName: &node.Identifier{Value: "foo"},
|
||||
Stmts: []node.Node{
|
||||
&stmt.ClassMethod{
|
||||
PhpDocComment: "",
|
||||
ReturnsRef: true,
|
||||
MethodName: &node.Identifier{Value: "bar"},
|
||||
Modifiers: []node.Node{
|
||||
&node.Identifier{Value: "public"},
|
||||
&node.Identifier{Value: "static"},
|
||||
},
|
||||
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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user