76 lines
1.6 KiB
Go
76 lines
1.6 KiB
Go
package stmt_test
|
|
|
|
import (
|
|
"bytes"
|
|
"github.com/z7zmey/php-parser/node/name"
|
|
"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 TestNamespace(t *testing.T) {
|
|
src := `<? namespace Foo;`
|
|
|
|
expected := &stmt.StmtList{
|
|
Stmts: []node.Node{
|
|
&stmt.Namespace{
|
|
NamespaceName: &name.Name{
|
|
Parts: []node.Node{
|
|
&name.NamePart{Value: "Foo"},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
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 TestNamespaceStmts(t *testing.T) {
|
|
src := `<? namespace Foo {}`
|
|
|
|
expected := &stmt.StmtList{
|
|
Stmts: []node.Node{
|
|
&stmt.Namespace{
|
|
NamespaceName: &name.Name{
|
|
Parts: []node.Node{
|
|
&name.NamePart{Value: "Foo"},
|
|
},
|
|
},
|
|
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 TestAnonymousNamespace(t *testing.T) {
|
|
src := `<? namespace {}`
|
|
|
|
expected := &stmt.StmtList{
|
|
Stmts: []node.Node{
|
|
&stmt.Namespace{
|
|
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)
|
|
}
|