From 2abe1dfb843c62d0777c9558ae26be99c8a7fa6e Mon Sep 17 00:00:00 2001 From: z7zmey Date: Wed, 2 May 2018 12:14:24 +0300 Subject: [PATCH] create Root node --- node/expr/assign/t_assign_op_test.go | 32 +++++++------- node/expr/binary/t_binary_op_test.go | 54 +++++++++++------------ node/expr/cast/t_cast_test.go | 20 ++++----- node/expr/t_array_dim_fetch_test.go | 4 +- node/expr/t_array_test.go | 6 +-- node/expr/t_bitwise_not_test.go | 2 +- node/expr/t_boolean_not_test.go | 2 +- node/expr/t_class_const_fetch_test.go | 4 +- node/expr/t_clone_test.go | 4 +- node/expr/t_closure_test.go | 8 ++-- node/expr/t_const_fetch_test.go | 6 +-- node/expr/t_empty_test.go | 2 +- node/expr/t_error_supress_test.go | 2 +- node/expr/t_eval_test.go | 2 +- node/expr/t_exit_test.go | 8 ++-- node/expr/t_function_call_test.go | 10 ++--- node/expr/t_inc_dec_test.go | 8 ++-- node/expr/t_include_test.go | 8 ++-- node/expr/t_instance_of_test.go | 6 +-- node/expr/t_isset_test.go | 4 +- node/expr/t_list_test.go | 8 ++-- node/expr/t_method_call_test.go | 2 +- node/expr/t_new_test.go | 8 ++-- node/expr/t_print_test.go | 2 +- node/expr/t_property_fetch_test.go | 2 +- node/expr/t_shell_exec_test.go | 2 +- node/expr/t_short_array_test.go | 6 +-- node/expr/t_short_list_test.go | 6 +-- node/expr/t_static_call_test.go | 10 ++--- node/expr/t_static_property_fetch_test.go | 6 +-- node/expr/t_ternary_test.go | 8 ++-- node/expr/t_unary_test.go | 4 +- node/expr/t_variable_test.go | 4 +- node/expr/t_yield_test.go | 12 ++--- node/n_root.go | 41 +++++++++++++++++ node/name/t_name_test.go | 6 +-- node/scalar/t_encapsed_test.go | 16 +++---- node/scalar/t_heredoc_test.go | 10 ++--- node/scalar/t_magic_constant_test.go | 2 +- node/scalar/t_numbers_test.go | 14 +++--- node/scalar/t_string_test.go | 10 ++--- node/stmt/t_alt_if_test.go | 8 ++-- node/stmt/t_class_const_list_test.go | 4 +- node/stmt/t_class_method_test.go | 12 ++--- node/stmt/t_class_test.go | 12 ++--- node/stmt/t_const_list_test.go | 2 +- node/stmt/t_continue_test.go | 6 +-- node/stmt/t_declare_test.go | 6 +-- node/stmt/t_do_test.go | 2 +- node/stmt/t_echo_test.go | 4 +- node/stmt/t_expression_test.go | 2 +- node/stmt/t_for_test.go | 4 +- node/stmt/t_foreach_test.go | 14 +++--- node/stmt/t_function_test.go | 10 ++--- node/stmt/t_global_test.go | 4 +- node/stmt/t_goto_label_test.go | 2 +- node/stmt/t_halt_compiler_test.go | 2 +- node/stmt/t_if_test.go | 10 ++--- node/stmt/t_inline_html_test.go | 2 +- node/stmt/t_interface_test.go | 6 +-- node/stmt/t_namespace_test.go | 6 +-- node/stmt/t_property_list_test.go | 6 +-- node/stmt/t_static_var_test.go | 6 +-- node/stmt/t_switch_case_default_test.go | 8 ++-- node/stmt/t_throw_test.go | 2 +- node/stmt/t_trait_test.go | 2 +- node/stmt/t_trait_use_test.go | 12 ++--- node/stmt/t_try_catch_finnaly_test.go | 12 ++--- node/stmt/t_unset_test.go | 6 +-- node/stmt/t_use_test.go | 28 ++++++------ node/stmt/t_while_break_test.go | 6 +-- node/t_node_test.go | 12 ++--- node/t_visitor_test.go | 9 ++++ php5/php5.go | 2 +- php5/php5.y | 2 +- php5/php5_test.go | 6 +-- php7/php7.go | 2 +- php7/php7.y | 4 +- php7/php7_test.go | 6 +-- printer/printer.go | 46 ++++++++++--------- printer/printer_test.go | 4 +- visitor/dumper_test.go | 2 +- 82 files changed, 363 insertions(+), 309 deletions(-) create mode 100644 node/n_root.go diff --git a/node/expr/assign/t_assign_op_test.go b/node/expr/assign/t_assign_op_test.go index 90e3527..207e891 100644 --- a/node/expr/assign/t_assign_op_test.go +++ b/node/expr/assign/t_assign_op_test.go @@ -32,7 +32,7 @@ func assertEqual(t *testing.T, expected interface{}, actual interface{}) { func TestReference(t *testing.T) { src := `>= $b;` - expected := &stmt.StmtList{ + expected := &node.Root{ Stmts: []node.Node{ &stmt.Expression{ Expr: &assign.ShiftRight{ diff --git a/node/expr/binary/t_binary_op_test.go b/node/expr/binary/t_binary_op_test.go index 414af88..3f316d0 100644 --- a/node/expr/binary/t_binary_op_test.go +++ b/node/expr/binary/t_binary_op_test.go @@ -30,7 +30,7 @@ func assertEqual(t *testing.T, expected interface{}, actual interface{}) { func TestBitwiseAnd(t *testing.T) { src := `= $b;` - expected := &stmt.StmtList{ + expected := &node.Root{ Stmts: []node.Node{ &stmt.Expression{ Expr: &binary.GreaterOrEqual{ @@ -275,7 +275,7 @@ func TestGreaterOrEqual(t *testing.T) { func TestGreater(t *testing.T) { src := ` $b;` - expected := &stmt.StmtList{ + expected := &node.Root{ Stmts: []node.Node{ &stmt.Expression{ Expr: &binary.Greater{ @@ -300,7 +300,7 @@ func TestGreater(t *testing.T) { func TestIdentical(t *testing.T) { src := `> $b;` - expected := &stmt.StmtList{ + expected := &node.Root{ Stmts: []node.Node{ &stmt.Expression{ Expr: &binary.ShiftRight{ @@ -625,7 +625,7 @@ func TestShiftRight(t *testing.T) { func TestSmallerOrEqual(t *testing.T) { src := ` $b;` - expected := &stmt.StmtList{ + expected := &node.Root{ Stmts: []node.Node{ &stmt.Expression{ Expr: &binary.Spaceship{ diff --git a/node/expr/cast/t_cast_test.go b/node/expr/cast/t_cast_test.go index c8a0246..4058f6c 100644 --- a/node/expr/cast/t_cast_test.go +++ b/node/expr/cast/t_cast_test.go @@ -30,7 +30,7 @@ func assertEqual(t *testing.T, expected interface{}, actual interface{}) { func TestArray(t *testing.T) { src := `1, &$b,);` - expected := &stmt.StmtList{ + expected := &node.Root{ Stmts: []node.Node{ &stmt.Expression{ Expr: &expr.Array{ diff --git a/node/expr/t_bitwise_not_test.go b/node/expr/t_bitwise_not_test.go index 2cf5f72..a4c6456 100644 --- a/node/expr/t_bitwise_not_test.go +++ b/node/expr/t_bitwise_not_test.go @@ -15,7 +15,7 @@ import ( func TestBitwiseNot(t *testing.T) { src := `foo();` - expected := &stmt.StmtList{ + expected := &node.Root{ Stmts: []node.Node{ &stmt.Expression{ Expr: &expr.MethodCall{ diff --git a/node/expr/t_new_test.go b/node/expr/t_new_test.go index e286459..cba3c88 100644 --- a/node/expr/t_new_test.go +++ b/node/expr/t_new_test.go @@ -17,7 +17,7 @@ import ( func TestNew(t *testing.T) { src := `foo;` - expected := &stmt.StmtList{ + expected := &node.Root{ Stmts: []node.Node{ &stmt.Expression{ Expr: &expr.PropertyFetch{ diff --git a/node/expr/t_shell_exec_test.go b/node/expr/t_shell_exec_test.go index 824c453..19f4ee9 100644 --- a/node/expr/t_shell_exec_test.go +++ b/node/expr/t_shell_exec_test.go @@ -17,7 +17,7 @@ import ( func TestShellExec(t *testing.T) { src := "1, &$b,];` - expected := &stmt.StmtList{ + expected := &node.Root{ Stmts: []node.Node{ &stmt.Expression{ Expr: &expr.ShortArray{ diff --git a/node/expr/t_short_list_test.go b/node/expr/t_short_list_test.go index 98a6a8a..3a1a95e 100644 --- a/node/expr/t_short_list_test.go +++ b/node/expr/t_short_list_test.go @@ -16,7 +16,7 @@ import ( func TestShortList(t *testing.T) { src := ` $b;` - expected := &stmt.StmtList{ + expected := &node.Root{ Stmts: []node.Node{ &stmt.Expression{ Expr: &expr.Yield{ @@ -87,7 +87,7 @@ func TestYieldKeyVal(t *testing.T) { func TestYieldExpr(t *testing.T) { src := ` 1;` - expected := &stmt.StmtList{ + expected := &node.Root{ Stmts: []node.Node{ &stmt.Expression{ Expr: &expr.Yield{ @@ -136,7 +136,7 @@ func TestYieldKeyExpr(t *testing.T) { func TestYieldFrom(t *testing.T) { src := `bar()";` - expected := &stmt.StmtList{ + expected := &node.Root{ Stmts: []node.Node{ &stmt.Expression{ Expr: &scalar.Encapsed{ @@ -157,7 +157,7 @@ func TestSimpleVarPropertyFetch(t *testing.T) { func TestDollarOpenCurlyBraces(t *testing.T) { src := `bar()}";` - expected := &stmt.StmtList{ + expected := &node.Root{ Stmts: []node.Node{ &stmt.Expression{ Expr: &scalar.Encapsed{ diff --git a/node/scalar/t_heredoc_test.go b/node/scalar/t_heredoc_test.go index 754195f..10ffb61 100644 --- a/node/scalar/t_heredoc_test.go +++ b/node/scalar/t_heredoc_test.go @@ -19,7 +19,7 @@ test $var LBL; ` - expected := &stmt.StmtList{ + expected := &node.Root{ Stmts: []node.Node{ &stmt.Expression{ Expr: &scalar.Heredoc{ @@ -51,7 +51,7 @@ test $var LBL; ` - expected := &stmt.StmtList{ + expected := &node.Root{ Stmts: []node.Node{ &stmt.Expression{ Expr: &scalar.Heredoc{ @@ -83,7 +83,7 @@ test $var LBL; ` - expected := &stmt.StmtList{ + expected := &node.Root{ Stmts: []node.Node{ &stmt.Expression{ Expr: &scalar.Heredoc{ @@ -112,7 +112,7 @@ func TestEmptyHeredoc(t *testing.T) { CAD; ` - expected := &stmt.StmtList{ + expected := &node.Root{ Stmts: []node.Node{ &stmt.Expression{ Expr: &scalar.Heredoc{ @@ -139,7 +139,7 @@ func TestHeredocScalarString(t *testing.T) { CAD; ` - expected := &stmt.StmtList{ + expected := &node.Root{ Stmts: []node.Node{ &stmt.Expression{ Expr: &scalar.Heredoc{ diff --git a/node/scalar/t_magic_constant_test.go b/node/scalar/t_magic_constant_test.go index 9b8d2f1..0fbdfdb 100644 --- a/node/scalar/t_magic_constant_test.go +++ b/node/scalar/t_magic_constant_test.go @@ -15,7 +15,7 @@ func TestMagicConstant(t *testing.T) { // TODO: test all magic constants src := ` $v) {}` - expected := &stmt.StmtList{ + expected := &node.Root{ Stmts: []node.Node{ &stmt.Foreach{ Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, @@ -112,7 +112,7 @@ func TestForeachWithKey(t *testing.T) { func TestForeachExprWithKey(t *testing.T) { src := ` $v) {}` - expected := &stmt.StmtList{ + expected := &node.Root{ Stmts: []node.Node{ &stmt.Foreach{ Expr: &expr.ShortArray{Items: []node.Node{}}, @@ -137,7 +137,7 @@ func TestForeachExprWithKey(t *testing.T) { func TestForeachWithRef(t *testing.T) { src := ` &$v) {}` - expected := &stmt.StmtList{ + expected := &node.Root{ Stmts: []node.Node{ &stmt.Foreach{ ByRef: true, @@ -163,7 +163,7 @@ func TestForeachWithRef(t *testing.T) { func TestForeachWithList(t *testing.T) { src := ` list($v)) {}` - expected := &stmt.StmtList{ + expected := &node.Root{ Stmts: []node.Node{ &stmt.Foreach{ ByRef: false, diff --git a/node/stmt/t_function_test.go b/node/stmt/t_function_test.go index 92cf463..fb32180 100644 --- a/node/stmt/t_function_test.go +++ b/node/stmt/t_function_test.go @@ -17,7 +17,7 @@ import ( func TestSimpleFunction(t *testing.T) { src := `
` - expected := &stmt.StmtList{ + expected := &node.Root{ Stmts: []node.Node{ &stmt.Nop{}, &stmt.InlineHtml{Value: "
"}, diff --git a/node/stmt/t_interface_test.go b/node/stmt/t_interface_test.go index 78f1e8e..524178d 100644 --- a/node/stmt/t_interface_test.go +++ b/node/stmt/t_interface_test.go @@ -14,7 +14,7 @@ import ( func TestInterface(t *testing.T) { src := ` 0 { - firstStmt := n.Stmts[0] - n.Stmts = n.Stmts[1:] - - switch fs := firstStmt.(type) { - case *stmt.InlineHtml: - io.WriteString(p.w, fs.Value) - io.WriteString(p.w, " 0 { + firstStmt := v.Stmts[0] + v.Stmts = v.Stmts[1:] + + switch fs := firstStmt.(type) { + case *stmt.InlineHtml: + io.WriteString(p.w, fs.Value) + io.WriteString(p.w, "HTML"}, &stmt.Expression{ diff --git a/visitor/dumper_test.go b/visitor/dumper_test.go index cb3094c..0f79ff4 100644 --- a/visitor/dumper_test.go +++ b/visitor/dumper_test.go @@ -39,7 +39,7 @@ func ExampleDumper() { nodes.Walk(dumper) // Unordered output: - //| [*stmt.StmtList] + //| [*node.Root] //| "Position": Pos{Line: 3-11 Pos: 10-143}; //| "Stmts": //| [*stmt.Namespace]