update tests

This commit is contained in:
z7zmey 2018-07-01 00:05:59 +03:00
parent e90df8ef5f
commit 9f0e766757
17 changed files with 534 additions and 0 deletions

View File

@ -0,0 +1,41 @@
package assign_test
import (
"testing"
"github.com/z7zmey/php-parser/node/expr/assign"
"github.com/z7zmey/php-parser/meta"
"github.com/z7zmey/php-parser/node"
)
var nodes = []node.Node{
&assign.Reference{},
&assign.Assign{},
&assign.BitwiseAnd{},
&assign.BitwiseOr{},
&assign.BitwiseXor{},
&assign.Concat{},
&assign.Div{},
&assign.Minus{},
&assign.Mod{},
&assign.Mul{},
&assign.Plus{},
&assign.Pow{},
&assign.ShiftLeft{},
&assign.ShiftRight{},
&assign.ShiftRight{},
}
func TestMeta(t *testing.T) {
expected := []meta.Meta{
meta.NewComment("//comment\n", nil),
meta.NewWhiteSpace(" ", nil),
}
for _, n := range nodes {
n.AddMeta(expected)
actual := n.GetMeta()
assertEqual(t, expected, actual)
}
}

View File

@ -0,0 +1,16 @@
package assign_test
import (
"testing"
"github.com/z7zmey/php-parser/position"
)
func TestPosition(t *testing.T) {
expected := position.NewPosition(1, 1, 1, 1)
for _, n := range nodes {
n.SetPosition(expected)
actual := n.GetPosition()
assertEqual(t, expected, actual)
}
}

View File

@ -0,0 +1,53 @@
package binary_test
import (
"testing"
"github.com/z7zmey/php-parser/node/expr/binary"
"github.com/z7zmey/php-parser/meta"
"github.com/z7zmey/php-parser/node"
)
var nodes = []node.Node{
&binary.BitwiseAnd{},
&binary.BitwiseOr{},
&binary.BitwiseXor{},
&binary.BooleanAnd{},
&binary.BooleanOr{},
&binary.Coalesce{},
&binary.Concat{},
&binary.Div{},
&binary.Equal{},
&binary.GreaterOrEqual{},
&binary.Greater{},
&binary.Identical{},
&binary.LogicalAnd{},
&binary.LogicalOr{},
&binary.LogicalXor{},
&binary.Minus{},
&binary.Mod{},
&binary.Mul{},
&binary.NotEqual{},
&binary.NotIdentical{},
&binary.Plus{},
&binary.Pow{},
&binary.ShiftLeft{},
&binary.ShiftRight{},
&binary.SmallerOrEqual{},
&binary.Smaller{},
&binary.Spaceship{},
}
func TestMeta(t *testing.T) {
expected := []meta.Meta{
meta.NewComment("//comment\n", nil),
meta.NewWhiteSpace(" ", nil),
}
for _, n := range nodes {
n.AddMeta(expected)
actual := n.GetMeta()
assertEqual(t, expected, actual)
}
}

View File

@ -0,0 +1,16 @@
package binary_test
import (
"testing"
"github.com/z7zmey/php-parser/position"
)
func TestPosition(t *testing.T) {
expected := position.NewPosition(1, 1, 1, 1)
for _, n := range nodes {
n.SetPosition(expected)
actual := n.GetPosition()
assertEqual(t, expected, actual)
}
}

View File

@ -0,0 +1,33 @@
package cast_test
import (
"testing"
"github.com/z7zmey/php-parser/node/expr/cast"
"github.com/z7zmey/php-parser/meta"
"github.com/z7zmey/php-parser/node"
)
var nodes = []node.Node{
&cast.Array{},
&cast.Bool{},
&cast.Double{},
&cast.Int{},
&cast.Object{},
&cast.String{},
&cast.Unset{},
}
func TestMeta(t *testing.T) {
expected := []meta.Meta{
meta.NewComment("//comment\n", nil),
meta.NewWhiteSpace(" ", nil),
}
for _, n := range nodes {
n.AddMeta(expected)
actual := n.GetMeta()
assertEqual(t, expected, actual)
}
}

View File

@ -0,0 +1,16 @@
package cast_test
import (
"testing"
"github.com/z7zmey/php-parser/position"
)
func TestPosition(t *testing.T) {
expected := position.NewPosition(1, 1, 1, 1)
for _, n := range nodes {
n.SetPosition(expected)
actual := n.GetPosition()
assertEqual(t, expected, actual)
}
}

69
node/expr/t_meta_test.go Normal file
View File

@ -0,0 +1,69 @@
package expr_test
import (
"testing"
"github.com/z7zmey/php-parser/node/expr"
"github.com/z7zmey/php-parser/meta"
"github.com/z7zmey/php-parser/node"
)
var nodes = []node.Node{
&expr.ArrayDimFetch{},
&expr.ArrayItem{},
&expr.Array{},
&expr.BitwiseNot{},
&expr.BooleanNot{},
&expr.ClassConstFetch{},
&expr.Clone{},
&expr.ClosureUse{},
&expr.Closure{},
&expr.ConstFetch{},
&expr.Die{},
&expr.Empty{},
&expr.ErrorSuppress{},
&expr.Eval{},
&expr.Exit{},
&expr.FunctionCall{},
&expr.IncludeOnce{},
&expr.Include{},
&expr.InstanceOf{},
&expr.Isset{},
&expr.List{},
&expr.MethodCall{},
&expr.New{},
&expr.PostDec{},
&expr.PostInc{},
&expr.PreDec{},
&expr.PreInc{},
&expr.Print{},
&expr.PropertyFetch{},
&expr.Reference{},
&expr.RequireOnce{},
&expr.Require{},
&expr.ShellExec{},
&expr.ShortArray{},
&expr.ShortList{},
&expr.StaticCall{},
&expr.StaticPropertyFetch{},
&expr.Ternary{},
&expr.UnaryMinus{},
&expr.UnaryPlus{},
&expr.Variable{},
&expr.YieldFrom{},
&expr.Yield{},
}
func TestMeta(t *testing.T) {
expected := []meta.Meta{
meta.NewComment("//comment\n", nil),
meta.NewWhiteSpace(" ", nil),
}
for _, n := range nodes {
n.AddMeta(expected)
actual := n.GetMeta()
assertEqual(t, expected, actual)
}
}

View File

@ -0,0 +1,16 @@
package expr_test
import (
"testing"
"github.com/z7zmey/php-parser/position"
)
func TestPosition(t *testing.T) {
expected := position.NewPosition(1, 1, 1, 1)
for _, n := range nodes {
n.SetPosition(expected)
actual := n.GetPosition()
assertEqual(t, expected, actual)
}
}

30
node/name/t_meta_test.go Normal file
View File

@ -0,0 +1,30 @@
package name_test
import (
"testing"
"github.com/z7zmey/php-parser/node/name"
"github.com/z7zmey/php-parser/meta"
"github.com/z7zmey/php-parser/node"
)
var nodes = []node.Node{
&name.FullyQualified{},
&name.NamePart{},
&name.Name{},
&name.Relative{},
}
func TestMeta(t *testing.T) {
expected := []meta.Meta{
meta.NewComment("//comment\n", nil),
meta.NewWhiteSpace(" ", nil),
}
for _, n := range nodes {
n.AddMeta(expected)
actual := n.GetMeta()
assertEqual(t, expected, actual)
}
}

View File

@ -0,0 +1,16 @@
package name_test
import (
"testing"
"github.com/z7zmey/php-parser/position"
)
func TestPosition(t *testing.T) {
expected := position.NewPosition(1, 1, 1, 1)
for _, n := range nodes {
n.SetPosition(expected)
actual := n.GetPosition()
assertEqual(t, expected, actual)
}
}

View File

@ -0,0 +1,33 @@
package scalar_test
import (
"testing"
"github.com/z7zmey/php-parser/node/scalar"
"github.com/z7zmey/php-parser/meta"
"github.com/z7zmey/php-parser/node"
)
var nodes = []node.Node{
&scalar.Dnumber{},
&scalar.EncapsedStringPart{},
&scalar.Encapsed{},
&scalar.Heredoc{},
&scalar.Lnumber{},
&scalar.MagicConstant{},
&scalar.String{},
}
func TestMeta(t *testing.T) {
expected := []meta.Meta{
meta.NewComment("//comment\n", nil),
meta.NewWhiteSpace(" ", nil),
}
for _, n := range nodes {
n.AddMeta(expected)
actual := n.GetMeta()
assertEqual(t, expected, actual)
}
}

View File

@ -0,0 +1,16 @@
package scalar_test
import (
"testing"
"github.com/z7zmey/php-parser/position"
)
func TestPosition(t *testing.T) {
expected := position.NewPosition(1, 1, 1, 1)
for _, n := range nodes {
n.SetPosition(expected)
actual := n.GetPosition()
assertEqual(t, expected, actual)
}
}

86
node/stmt/t_meta_test.go Normal file
View File

@ -0,0 +1,86 @@
package stmt_test
import (
"testing"
"github.com/z7zmey/php-parser/node/stmt"
"github.com/z7zmey/php-parser/meta"
"github.com/z7zmey/php-parser/node"
)
var nodes = []node.Node{
&stmt.AltElseIf{},
&stmt.AltElse{},
&stmt.AltFor{},
&stmt.AltForeach{},
&stmt.AltIf{},
&stmt.AltSwitch{},
&stmt.AltWhile{},
&stmt.Break{},
&stmt.CaseList{},
&stmt.Case{},
&stmt.Catch{},
&stmt.ClassConstList{},
&stmt.ClassExtends{},
&stmt.ClassImplements{},
&stmt.ClassMethod{},
&stmt.Class{},
&stmt.ConstList{},
&stmt.Constant{},
&stmt.Continue{},
&stmt.Declare{},
&stmt.Default{},
&stmt.Do{},
&stmt.Echo{},
&stmt.ElseIf{},
&stmt.Else{},
&stmt.Expression{},
&stmt.Finally{},
&stmt.For{},
&stmt.Foreach{},
&stmt.Function{},
&stmt.Global{},
&stmt.Goto{},
&stmt.GroupUse{},
&stmt.HaltCompiler{},
&stmt.If{},
&stmt.InlineHtml{},
&stmt.InterfaceExtends{},
&stmt.Interface{},
&stmt.Label{},
&stmt.Namespace{},
&stmt.Nop{},
&stmt.PropertyList{},
&stmt.Property{},
&stmt.Return{},
&stmt.StaticVar{},
&stmt.Static{},
&stmt.StmtList{},
&stmt.Switch{},
&stmt.Throw{},
&stmt.TraitAdaptationList{},
&stmt.TraitMethodRef{},
&stmt.TraitUseAlias{},
&stmt.TraitUsePrecedence{},
&stmt.TraitUse{},
&stmt.Trait{},
&stmt.Try{},
&stmt.Unset{},
&stmt.UseList{},
&stmt.Use{},
&stmt.While{},
}
func TestMeta(t *testing.T) {
expected := []meta.Meta{
meta.NewComment("//comment\n", nil),
meta.NewWhiteSpace(" ", nil),
}
for _, n := range nodes {
n.AddMeta(expected)
actual := n.GetMeta()
assertEqual(t, expected, actual)
}
}

View File

@ -0,0 +1,16 @@
package stmt_test
import (
"testing"
"github.com/z7zmey/php-parser/position"
)
func TestPosition(t *testing.T) {
expected := position.NewPosition(1, 1, 1, 1)
for _, n := range nodes {
n.SetPosition(expected)
actual := n.GetPosition()
assertEqual(t, expected, actual)
}
}

30
node/t_meta_test.go Normal file
View File

@ -0,0 +1,30 @@
package node_test
import (
"testing"
"github.com/z7zmey/php-parser/meta"
"github.com/z7zmey/php-parser/node"
)
var nodes = []node.Node{
&node.ArgumentList{},
&node.Argument{},
&node.Identifier{},
&node.Nullable{},
&node.Parameter{},
&node.Root{},
}
func TestMeta(t *testing.T) {
expected := []meta.Meta{
meta.NewComment("//comment\n", nil),
meta.NewWhiteSpace(" ", nil),
}
for _, n := range nodes {
n.AddMeta(expected)
actual := n.GetMeta()
assertEqual(t, expected, actual)
}
}

16
node/t_position_test.go Normal file
View File

@ -0,0 +1,16 @@
package node_test
import (
"testing"
"github.com/z7zmey/php-parser/position"
)
func TestPosition(t *testing.T) {
expected := position.NewPosition(1, 1, 1, 1)
for _, n := range nodes {
n.SetPosition(expected)
actual := n.GetPosition()
assertEqual(t, expected, actual)
}
}

View File

@ -2481,6 +2481,37 @@ func TestPrintStmtClassMethod(t *testing.T) {
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
} }
} }
func TestPrintStmtAbstractClassMethod(t *testing.T) {
o := bytes.NewBufferString("")
p := printer.NewPrinter(o, " ")
p.Print(&stmt.ClassMethod{
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
ReturnsRef: true,
MethodName: &node.Identifier{Value: "foo"},
Params: []node.Node{
&node.Parameter{
ByRef: true,
VariableType: &node.Nullable{Expr: &name.Name{Parts: []node.Node{&name.NamePart{Value: "int"}}}},
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
DefaultValue: &expr.ConstFetch{Constant: &name.Name{Parts: []node.Node{&name.NamePart{Value: "null"}}}},
},
&node.Parameter{
Variadic: true,
Variable: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
},
},
ReturnType: &name.Name{Parts: []node.Node{&name.NamePart{Value: "void"}}},
Stmt: &stmt.Nop{},
})
expected := `public function &foo(?int &$a = null, ...$b): void;`
actual := o.String()
if expected != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
}
}
func TestPrintStmtClass(t *testing.T) { func TestPrintStmtClass(t *testing.T) {
o := bytes.NewBufferString("") o := bytes.NewBufferString("")