61 lines
1.4 KiB
Go
61 lines
1.4 KiB
Go
|
package stmt_test
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/z7zmey/php-parser/node/expr/binary_op"
|
||
|
|
||
|
"github.com/z7zmey/php-parser/node/expr"
|
||
|
"github.com/z7zmey/php-parser/node/expr/assign_op"
|
||
|
|
||
|
"github.com/z7zmey/php-parser/node/scalar"
|
||
|
|
||
|
"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 TestFor(t *testing.T) {
|
||
|
src := `<? for($i = 0; $i < 10; $i++, $i++) {}`
|
||
|
|
||
|
expected := &stmt.StmtList{
|
||
|
Stmts: []node.Node{
|
||
|
&stmt.For{
|
||
|
Init: []node.Node{
|
||
|
&assign_op.Assign{
|
||
|
assign_op.AssignOp{
|
||
|
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$i"}},
|
||
|
Expression: &scalar.Lnumber{Value: "0"},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
Cond: []node.Node{
|
||
|
&binary_op.Smaller{
|
||
|
binary_op.BinaryOp{
|
||
|
Left: &expr.Variable{VarName: &node.Identifier{Value: "$i"}},
|
||
|
Right: &scalar.Lnumber{Value: "10"},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
Loop: []node.Node{
|
||
|
&expr.PostInc{
|
||
|
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$i"}},
|
||
|
},
|
||
|
&expr.PostInc{
|
||
|
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$i"}},
|
||
|
},
|
||
|
},
|
||
|
Stmt: &stmt.StmtList{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)
|
||
|
}
|