From 50f8a47119d13b79c8479f5a5b043a5f4bb1c489 Mon Sep 17 00:00:00 2001 From: Vadym Slizov Date: Thu, 14 May 2020 19:07:05 +0300 Subject: [PATCH] update tests --- internal/php5/parser_test.go | 23147 +++++++++++++++++ internal/php7/parser_test.go | 25883 ++++++++++++++++++++ node/expr/assign/n_assign.go | 66 - node/expr/assign/n_assign_ref.go | 66 - node/expr/assign/n_bitwise_and.go | 66 - node/expr/assign/n_bitwise_or.go | 66 - node/expr/assign/n_bitwise_xor.go | 66 - node/expr/assign/n_coalesce.go | 66 - node/expr/assign/n_concat.go | 66 - node/expr/assign/n_div.go | 66 - node/expr/assign/n_minus.go | 66 - node/expr/assign/n_mod.go | 66 - node/expr/assign/n_mul.go | 66 - node/expr/assign/n_plus.go | 66 - node/expr/assign/n_pow.go | 66 - node/expr/assign/n_shift_left.go | 66 - node/expr/assign/n_shift_right.go | 66 - node/expr/assign/t_assign_op_test.go | 1344 - node/expr/assign/t_freefloating_test.go | 84 - node/expr/assign/t_position_test.go | 18 - node/expr/assign/t_visitor_test.go | 190 - node/expr/binary/n_bitwise_and.go | 66 - node/expr/binary/n_bitwise_or.go | 66 - node/expr/binary/n_bitwise_xor.go | 66 - node/expr/binary/n_boolean_and.go | 66 - node/expr/binary/n_boolean_or.go | 66 - node/expr/binary/n_coalesce.go | 66 - node/expr/binary/n_concat.go | 66 - node/expr/binary/n_div.go | 66 - node/expr/binary/n_equal.go | 66 - node/expr/binary/n_greater.go | 66 - node/expr/binary/n_greater_or_equal.go | 66 - node/expr/binary/n_identical.go | 66 - node/expr/binary/n_logical_and.go | 66 - node/expr/binary/n_logical_or.go | 66 - node/expr/binary/n_logical_xor.go | 66 - node/expr/binary/n_minus.go | 66 - node/expr/binary/n_mod.go | 66 - node/expr/binary/n_mul.go | 66 - node/expr/binary/n_not_equal.go | 66 - node/expr/binary/n_not_identical.go | 66 - node/expr/binary/n_plus.go | 66 - node/expr/binary/n_pow.go | 66 - node/expr/binary/n_shift_left.go | 66 - node/expr/binary/n_shift_right.go | 66 - node/expr/binary/n_smaller.go | 66 - node/expr/binary/n_smaller_or_equal.go | 66 - node/expr/binary/n_spaceship.go | 66 - node/expr/binary/t_binary_op_test.go | 2030 -- node/expr/binary/t_freefloating_test.go | 117 - node/expr/binary/t_position_test.go | 18 - node/expr/binary/t_visitor_test.go | 285 - node/expr/cast/n_cast_array.go | 58 - node/expr/cast/n_cast_bool.go | 58 - node/expr/cast/n_cast_double.go | 58 - node/expr/cast/n_cast_int.go | 58 - node/expr/cast/n_cast_object.go | 58 - node/expr/cast/n_cast_string.go | 58 - node/expr/cast/n_cast_unset.go | 58 - node/expr/cast/t_cast_test.go | 653 - node/expr/cast/t_freefloating_test.go | 57 - node/expr/cast/t_position_test.go | 18 - node/expr/cast/t_visitor_test.go | 119 - node/expr/n_array.go | 62 - node/expr/n_array_dim_fetch.go | 66 - node/expr/n_array_item.go | 70 - node/expr/n_arrow_function.go | 88 - node/expr/n_bitwise_not.go | 58 - node/expr/n_boolean_not.go | 58 - node/expr/n_class_const_fetch.go | 66 - node/expr/n_clone.go | 58 - node/expr/n_closure.go | 100 - node/expr/n_closure_use.go | 62 - node/expr/n_const_fetch.go | 58 - node/expr/n_empty.go | 58 - node/expr/n_error_suppress.go | 58 - node/expr/n_eval.go | 58 - node/expr/n_exit.go | 61 - node/expr/n_function_call.go | 66 - node/expr/n_include.go | 58 - node/expr/n_include_once.go | 58 - node/expr/n_instance_of.go | 66 - node/expr/n_isset.go | 62 - node/expr/n_list.go | 62 - node/expr/n_method_call.go | 74 - node/expr/n_new.go | 66 - node/expr/n_post_dec.go | 58 - node/expr/n_post_inc.go | 58 - node/expr/n_pre_dec.go | 58 - node/expr/n_pre_inc.go | 58 - node/expr/n_print.go | 58 - node/expr/n_property_fetch.go | 66 - node/expr/n_reference.go | 58 - node/expr/n_require.go | 58 - node/expr/n_require_once.go | 58 - node/expr/n_shell_exec.go | 62 - node/expr/n_short_array.go | 62 - node/expr/n_short_list.go | 62 - node/expr/n_static_call.go | 74 - node/expr/n_static_property_fetch.go | 66 - node/expr/n_ternary.go | 74 - node/expr/n_unary_minus.go | 58 - node/expr/n_unary_plus.go | 58 - node/expr/n_variable.go | 63 - node/expr/n_yield.go | 66 - node/expr/n_yield_from.go | 58 - node/expr/t_array_dim_fetch_test.go | 166 - node/expr/t_array_test.go | 284 - node/expr/t_arrow_function_test.go | 144 - node/expr/t_bitwise_not_test.go | 73 - node/expr/t_boolean_not_test.go | 73 - node/expr/t_class_const_fetch_test.go | 145 - node/expr/t_clone_test.go | 131 - node/expr/t_closure_test.go | 427 - node/expr/t_const_fetch_test.go | 197 - node/expr/t_empty_test.go | 73 - node/expr/t_error_supress_test.go | 73 - node/expr/t_eval_test.go | 73 - node/expr/t_exit_test.go | 301 - node/expr/t_freefloating_test.go | 165 - node/expr/t_function_call_test.go | 462 - node/expr/t_inc_dec_test.go | 247 - node/expr/t_include_test.go | 247 - node/expr/t_instance_of_test.go | 248 - node/expr/t_isset_test.go | 152 - node/expr/t_list_test.go | 577 - node/expr/t_method_call_test.go | 90 - node/expr/t_new_test.go | 323 - node/expr/t_position_test.go | 18 - node/expr/t_print_test.go | 73 - node/expr/t_property_fetch_test.go | 82 - node/expr/t_reference_test.go | 117 - node/expr/t_shell_exec_test.go | 86 - node/expr/t_short_array_test.go | 220 - node/expr/t_short_list_test.go | 304 - node/expr/t_static_call_test.go | 416 - node/expr/t_static_property_fetch_test.go | 247 - node/expr/t_ternary_test.go | 450 - node/expr/t_unary_test.go | 131 - node/expr/t_variable_test.go | 123 - node/expr/t_visitor_test.go | 416 - node/expr/t_yield_test.go | 360 - node/n_argument.go | 64 - node/n_argument_list.go | 61 - node/n_identifier.go | 53 - node/n_nullable.go | 57 - node/n_parameter.go | 80 - node/n_root.go | 61 - node/name/n_fully_qualified.go | 67 - node/name/n_name.go | 67 - node/name/n_name_part.go | 53 - node/name/n_relative.go | 67 - node/name/names.go | 11 - node/name/t_freefloating_test.go | 48 - node/name/t_name_test.go | 235 - node/name/t_position_test.go | 18 - node/name/t_visitor_test.go | 89 - node/node.go | 16 - node/scalar/node_dnumber.go | 53 - node/scalar/node_encapsed.go | 62 - node/scalar/node_encapsed_string_part.go | 53 - node/scalar/node_heredoc.go | 66 - node/scalar/node_lnumber.go | 53 - node/scalar/node_magic_constant.go | 53 - node/scalar/node_string.go | 53 - node/scalar/t_encapsed_test.go | 662 - node/scalar/t_freefloating_test.go | 57 - node/scalar/t_heredoc_test.go | 336 - node/scalar/t_magic_constant_test.go | 57 - node/scalar/t_numbers_test.go | 308 - node/scalar/t_position_test.go | 18 - node/scalar/t_string_test.go | 228 - node/scalar/t_visitor_test.go | 104 - node/stmt/n_alt_else.go | 58 - node/stmt/n_alt_else_if.go | 66 - node/stmt/n_alt_for.go | 94 - node/stmt/n_alt_foreach.go | 82 - node/stmt/n_alt_if.go | 104 - node/stmt/n_alt_switch.go | 66 - node/stmt/n_alt_while.go | 66 - node/stmt/n_break.go | 58 - node/stmt/n_case.go | 70 - node/stmt/n_case_list.go | 62 - node/stmt/n_catch.go | 82 - node/stmt/n_class.go | 110 - node/stmt/n_class_const_list.go | 74 - node/stmt/n_class_extends.go | 58 - node/stmt/n_class_implements.go | 62 - node/stmt/n_class_method.go | 105 - node/stmt/n_const_list.go | 62 - node/stmt/n_constant.go | 70 - node/stmt/n_continue.go | 58 - node/stmt/n_declare.go | 74 - node/stmt/n_default.go | 62 - node/stmt/n_do.go | 66 - node/stmt/n_echo.go | 62 - node/stmt/n_else.go | 58 - node/stmt/n_else_if.go | 66 - node/stmt/n_expression.go | 58 - node/stmt/n_finally.go | 62 - node/stmt/n_for.go | 94 - node/stmt/n_foreach.go | 82 - node/stmt/n_function.go | 98 - node/stmt/n_global.go | 62 - node/stmt/n_goto.go | 58 - node/stmt/n_group_use.go | 84 - node/stmt/n_halt_compiler.go | 47 - node/stmt/n_if.go | 104 - node/stmt/n_inline_html.go | 53 - node/stmt/n_interface.go | 82 - node/stmt/n_interface_extends.go | 62 - node/stmt/n_label.go | 58 - node/stmt/n_namespace.go | 70 - node/stmt/n_nop.go | 47 - node/stmt/n_property.go | 70 - node/stmt/n_property_list.go | 82 - node/stmt/n_return.go | 58 - node/stmt/n_static.go | 62 - node/stmt/n_static_var.go | 66 - node/stmt/n_stmt_list.go | 62 - node/stmt/n_switch.go | 66 - node/stmt/n_throw.go | 58 - node/stmt/n_trait.go | 74 - node/stmt/n_trait_adaptation_list.go | 62 - node/stmt/n_trait_method_ref.go | 66 - node/stmt/n_trait_use.go | 70 - node/stmt/n_trait_use_alias.go | 74 - node/stmt/n_trait_use_precedence.go | 70 - node/stmt/n_try.go | 82 - node/stmt/n_unset.go | 62 - node/stmt/n_use.go | 80 - node/stmt/n_use_list.go | 70 - node/stmt/n_while.go | 66 - node/stmt/t_alt_if_test.go | 407 - node/stmt/t_class_const_list_test.go | 239 - node/stmt/t_class_method_test.go | 626 - node/stmt/t_class_test.go | 513 - node/stmt/t_const_list_test.go | 104 - node/stmt/t_continue_test.go | 213 - node/stmt/t_declare_test.go | 255 - node/stmt/t_do_test.go | 66 - node/stmt/t_echo_test.go | 130 - node/stmt/t_expression_test.go | 57 - node/stmt/t_for_test.go | 291 - node/stmt/t_foreach_test.go | 625 - node/stmt/t_freefloating_test.go | 216 - node/stmt/t_function_test.go | 383 - node/stmt/t_global_test.go | 204 - node/stmt/t_goto_label_test.go | 72 - node/stmt/t_halt_compiler_test.go | 46 - node/stmt/t_if_test.go | 545 - node/stmt/t_inline_html_test.go | 55 - node/stmt/t_interface_test.go | 224 - node/stmt/t_namespace_test.go | 154 - node/stmt/t_position_test.go | 18 - node/stmt/t_property_list_test.go | 487 - node/stmt/t_static_var_test.go | 263 - node/stmt/t_switch_case_default_test.go | 433 - node/stmt/t_throw_test.go | 64 - node/stmt/t_trait_test.go | 57 - node/stmt/t_trait_use_test.go | 822 - node/stmt/t_try_catch_finnaly_test.go | 640 - node/stmt/t_unset_test.go | 199 - node/stmt/t_use_test.go | 1385 -- node/stmt/t_visitor_test.go | 574 - node/stmt/t_while_break_test.go | 213 - node/t_freefloating_test.go | 53 - node/t_node_test.go | 2755 --- node/t_position_test.go | 18 - node/t_visitor_test.go | 113 - 270 files changed, 49030 insertions(+), 39496 deletions(-) create mode 100644 internal/php5/parser_test.go create mode 100644 internal/php7/parser_test.go delete mode 100644 node/expr/assign/n_assign.go delete mode 100644 node/expr/assign/n_assign_ref.go delete mode 100644 node/expr/assign/n_bitwise_and.go delete mode 100644 node/expr/assign/n_bitwise_or.go delete mode 100644 node/expr/assign/n_bitwise_xor.go delete mode 100644 node/expr/assign/n_coalesce.go delete mode 100644 node/expr/assign/n_concat.go delete mode 100644 node/expr/assign/n_div.go delete mode 100644 node/expr/assign/n_minus.go delete mode 100644 node/expr/assign/n_mod.go delete mode 100644 node/expr/assign/n_mul.go delete mode 100644 node/expr/assign/n_plus.go delete mode 100644 node/expr/assign/n_pow.go delete mode 100644 node/expr/assign/n_shift_left.go delete mode 100644 node/expr/assign/n_shift_right.go delete mode 100644 node/expr/assign/t_assign_op_test.go delete mode 100644 node/expr/assign/t_freefloating_test.go delete mode 100644 node/expr/assign/t_position_test.go delete mode 100644 node/expr/assign/t_visitor_test.go delete mode 100644 node/expr/binary/n_bitwise_and.go delete mode 100644 node/expr/binary/n_bitwise_or.go delete mode 100644 node/expr/binary/n_bitwise_xor.go delete mode 100644 node/expr/binary/n_boolean_and.go delete mode 100644 node/expr/binary/n_boolean_or.go delete mode 100644 node/expr/binary/n_coalesce.go delete mode 100644 node/expr/binary/n_concat.go delete mode 100644 node/expr/binary/n_div.go delete mode 100644 node/expr/binary/n_equal.go delete mode 100644 node/expr/binary/n_greater.go delete mode 100644 node/expr/binary/n_greater_or_equal.go delete mode 100644 node/expr/binary/n_identical.go delete mode 100644 node/expr/binary/n_logical_and.go delete mode 100644 node/expr/binary/n_logical_or.go delete mode 100644 node/expr/binary/n_logical_xor.go delete mode 100644 node/expr/binary/n_minus.go delete mode 100644 node/expr/binary/n_mod.go delete mode 100644 node/expr/binary/n_mul.go delete mode 100644 node/expr/binary/n_not_equal.go delete mode 100644 node/expr/binary/n_not_identical.go delete mode 100644 node/expr/binary/n_plus.go delete mode 100644 node/expr/binary/n_pow.go delete mode 100644 node/expr/binary/n_shift_left.go delete mode 100644 node/expr/binary/n_shift_right.go delete mode 100644 node/expr/binary/n_smaller.go delete mode 100644 node/expr/binary/n_smaller_or_equal.go delete mode 100644 node/expr/binary/n_spaceship.go delete mode 100644 node/expr/binary/t_binary_op_test.go delete mode 100644 node/expr/binary/t_freefloating_test.go delete mode 100644 node/expr/binary/t_position_test.go delete mode 100644 node/expr/binary/t_visitor_test.go delete mode 100644 node/expr/cast/n_cast_array.go delete mode 100644 node/expr/cast/n_cast_bool.go delete mode 100644 node/expr/cast/n_cast_double.go delete mode 100644 node/expr/cast/n_cast_int.go delete mode 100644 node/expr/cast/n_cast_object.go delete mode 100644 node/expr/cast/n_cast_string.go delete mode 100644 node/expr/cast/n_cast_unset.go delete mode 100644 node/expr/cast/t_cast_test.go delete mode 100644 node/expr/cast/t_freefloating_test.go delete mode 100644 node/expr/cast/t_position_test.go delete mode 100644 node/expr/cast/t_visitor_test.go delete mode 100644 node/expr/n_array.go delete mode 100644 node/expr/n_array_dim_fetch.go delete mode 100644 node/expr/n_array_item.go delete mode 100644 node/expr/n_arrow_function.go delete mode 100644 node/expr/n_bitwise_not.go delete mode 100644 node/expr/n_boolean_not.go delete mode 100644 node/expr/n_class_const_fetch.go delete mode 100644 node/expr/n_clone.go delete mode 100644 node/expr/n_closure.go delete mode 100644 node/expr/n_closure_use.go delete mode 100644 node/expr/n_const_fetch.go delete mode 100644 node/expr/n_empty.go delete mode 100644 node/expr/n_error_suppress.go delete mode 100644 node/expr/n_eval.go delete mode 100644 node/expr/n_exit.go delete mode 100644 node/expr/n_function_call.go delete mode 100644 node/expr/n_include.go delete mode 100644 node/expr/n_include_once.go delete mode 100644 node/expr/n_instance_of.go delete mode 100644 node/expr/n_isset.go delete mode 100644 node/expr/n_list.go delete mode 100644 node/expr/n_method_call.go delete mode 100644 node/expr/n_new.go delete mode 100644 node/expr/n_post_dec.go delete mode 100644 node/expr/n_post_inc.go delete mode 100644 node/expr/n_pre_dec.go delete mode 100644 node/expr/n_pre_inc.go delete mode 100644 node/expr/n_print.go delete mode 100644 node/expr/n_property_fetch.go delete mode 100644 node/expr/n_reference.go delete mode 100644 node/expr/n_require.go delete mode 100644 node/expr/n_require_once.go delete mode 100644 node/expr/n_shell_exec.go delete mode 100644 node/expr/n_short_array.go delete mode 100644 node/expr/n_short_list.go delete mode 100644 node/expr/n_static_call.go delete mode 100644 node/expr/n_static_property_fetch.go delete mode 100644 node/expr/n_ternary.go delete mode 100644 node/expr/n_unary_minus.go delete mode 100644 node/expr/n_unary_plus.go delete mode 100644 node/expr/n_variable.go delete mode 100644 node/expr/n_yield.go delete mode 100644 node/expr/n_yield_from.go delete mode 100644 node/expr/t_array_dim_fetch_test.go delete mode 100644 node/expr/t_array_test.go delete mode 100644 node/expr/t_arrow_function_test.go delete mode 100644 node/expr/t_bitwise_not_test.go delete mode 100644 node/expr/t_boolean_not_test.go delete mode 100644 node/expr/t_class_const_fetch_test.go delete mode 100644 node/expr/t_clone_test.go delete mode 100644 node/expr/t_closure_test.go delete mode 100644 node/expr/t_const_fetch_test.go delete mode 100644 node/expr/t_empty_test.go delete mode 100644 node/expr/t_error_supress_test.go delete mode 100644 node/expr/t_eval_test.go delete mode 100644 node/expr/t_exit_test.go delete mode 100644 node/expr/t_freefloating_test.go delete mode 100644 node/expr/t_function_call_test.go delete mode 100644 node/expr/t_inc_dec_test.go delete mode 100644 node/expr/t_include_test.go delete mode 100644 node/expr/t_instance_of_test.go delete mode 100644 node/expr/t_isset_test.go delete mode 100644 node/expr/t_list_test.go delete mode 100644 node/expr/t_method_call_test.go delete mode 100644 node/expr/t_new_test.go delete mode 100644 node/expr/t_position_test.go delete mode 100644 node/expr/t_print_test.go delete mode 100644 node/expr/t_property_fetch_test.go delete mode 100644 node/expr/t_reference_test.go delete mode 100644 node/expr/t_shell_exec_test.go delete mode 100644 node/expr/t_short_array_test.go delete mode 100644 node/expr/t_short_list_test.go delete mode 100644 node/expr/t_static_call_test.go delete mode 100644 node/expr/t_static_property_fetch_test.go delete mode 100644 node/expr/t_ternary_test.go delete mode 100644 node/expr/t_unary_test.go delete mode 100644 node/expr/t_variable_test.go delete mode 100644 node/expr/t_visitor_test.go delete mode 100644 node/expr/t_yield_test.go delete mode 100644 node/n_argument.go delete mode 100644 node/n_argument_list.go delete mode 100644 node/n_identifier.go delete mode 100644 node/n_nullable.go delete mode 100644 node/n_parameter.go delete mode 100644 node/n_root.go delete mode 100644 node/name/n_fully_qualified.go delete mode 100644 node/name/n_name.go delete mode 100644 node/name/n_name_part.go delete mode 100644 node/name/n_relative.go delete mode 100644 node/name/names.go delete mode 100644 node/name/t_freefloating_test.go delete mode 100644 node/name/t_name_test.go delete mode 100644 node/name/t_position_test.go delete mode 100644 node/name/t_visitor_test.go delete mode 100644 node/node.go delete mode 100644 node/scalar/node_dnumber.go delete mode 100644 node/scalar/node_encapsed.go delete mode 100644 node/scalar/node_encapsed_string_part.go delete mode 100644 node/scalar/node_heredoc.go delete mode 100644 node/scalar/node_lnumber.go delete mode 100644 node/scalar/node_magic_constant.go delete mode 100644 node/scalar/node_string.go delete mode 100644 node/scalar/t_encapsed_test.go delete mode 100644 node/scalar/t_freefloating_test.go delete mode 100644 node/scalar/t_heredoc_test.go delete mode 100644 node/scalar/t_magic_constant_test.go delete mode 100644 node/scalar/t_numbers_test.go delete mode 100644 node/scalar/t_position_test.go delete mode 100644 node/scalar/t_string_test.go delete mode 100644 node/scalar/t_visitor_test.go delete mode 100644 node/stmt/n_alt_else.go delete mode 100644 node/stmt/n_alt_else_if.go delete mode 100644 node/stmt/n_alt_for.go delete mode 100644 node/stmt/n_alt_foreach.go delete mode 100644 node/stmt/n_alt_if.go delete mode 100644 node/stmt/n_alt_switch.go delete mode 100644 node/stmt/n_alt_while.go delete mode 100644 node/stmt/n_break.go delete mode 100644 node/stmt/n_case.go delete mode 100644 node/stmt/n_case_list.go delete mode 100644 node/stmt/n_catch.go delete mode 100644 node/stmt/n_class.go delete mode 100644 node/stmt/n_class_const_list.go delete mode 100644 node/stmt/n_class_extends.go delete mode 100644 node/stmt/n_class_implements.go delete mode 100644 node/stmt/n_class_method.go delete mode 100644 node/stmt/n_const_list.go delete mode 100644 node/stmt/n_constant.go delete mode 100644 node/stmt/n_continue.go delete mode 100644 node/stmt/n_declare.go delete mode 100644 node/stmt/n_default.go delete mode 100644 node/stmt/n_do.go delete mode 100644 node/stmt/n_echo.go delete mode 100644 node/stmt/n_else.go delete mode 100644 node/stmt/n_else_if.go delete mode 100644 node/stmt/n_expression.go delete mode 100644 node/stmt/n_finally.go delete mode 100644 node/stmt/n_for.go delete mode 100644 node/stmt/n_foreach.go delete mode 100644 node/stmt/n_function.go delete mode 100644 node/stmt/n_global.go delete mode 100644 node/stmt/n_goto.go delete mode 100644 node/stmt/n_group_use.go delete mode 100644 node/stmt/n_halt_compiler.go delete mode 100644 node/stmt/n_if.go delete mode 100644 node/stmt/n_inline_html.go delete mode 100644 node/stmt/n_interface.go delete mode 100644 node/stmt/n_interface_extends.go delete mode 100644 node/stmt/n_label.go delete mode 100644 node/stmt/n_namespace.go delete mode 100644 node/stmt/n_nop.go delete mode 100644 node/stmt/n_property.go delete mode 100644 node/stmt/n_property_list.go delete mode 100644 node/stmt/n_return.go delete mode 100644 node/stmt/n_static.go delete mode 100644 node/stmt/n_static_var.go delete mode 100644 node/stmt/n_stmt_list.go delete mode 100644 node/stmt/n_switch.go delete mode 100644 node/stmt/n_throw.go delete mode 100644 node/stmt/n_trait.go delete mode 100644 node/stmt/n_trait_adaptation_list.go delete mode 100644 node/stmt/n_trait_method_ref.go delete mode 100644 node/stmt/n_trait_use.go delete mode 100644 node/stmt/n_trait_use_alias.go delete mode 100644 node/stmt/n_trait_use_precedence.go delete mode 100644 node/stmt/n_try.go delete mode 100644 node/stmt/n_unset.go delete mode 100644 node/stmt/n_use.go delete mode 100644 node/stmt/n_use_list.go delete mode 100644 node/stmt/n_while.go delete mode 100644 node/stmt/t_alt_if_test.go delete mode 100644 node/stmt/t_class_const_list_test.go delete mode 100644 node/stmt/t_class_method_test.go delete mode 100644 node/stmt/t_class_test.go delete mode 100644 node/stmt/t_const_list_test.go delete mode 100644 node/stmt/t_continue_test.go delete mode 100644 node/stmt/t_declare_test.go delete mode 100644 node/stmt/t_do_test.go delete mode 100644 node/stmt/t_echo_test.go delete mode 100644 node/stmt/t_expression_test.go delete mode 100644 node/stmt/t_for_test.go delete mode 100644 node/stmt/t_foreach_test.go delete mode 100644 node/stmt/t_freefloating_test.go delete mode 100644 node/stmt/t_function_test.go delete mode 100644 node/stmt/t_global_test.go delete mode 100644 node/stmt/t_goto_label_test.go delete mode 100644 node/stmt/t_halt_compiler_test.go delete mode 100644 node/stmt/t_if_test.go delete mode 100644 node/stmt/t_inline_html_test.go delete mode 100644 node/stmt/t_interface_test.go delete mode 100644 node/stmt/t_namespace_test.go delete mode 100644 node/stmt/t_position_test.go delete mode 100644 node/stmt/t_property_list_test.go delete mode 100644 node/stmt/t_static_var_test.go delete mode 100644 node/stmt/t_switch_case_default_test.go delete mode 100644 node/stmt/t_throw_test.go delete mode 100644 node/stmt/t_trait_test.go delete mode 100644 node/stmt/t_trait_use_test.go delete mode 100644 node/stmt/t_try_catch_finnaly_test.go delete mode 100644 node/stmt/t_unset_test.go delete mode 100644 node/stmt/t_use_test.go delete mode 100644 node/stmt/t_visitor_test.go delete mode 100644 node/stmt/t_while_break_test.go delete mode 100644 node/t_freefloating_test.go delete mode 100644 node/t_node_test.go delete mode 100644 node/t_position_test.go delete mode 100644 node/t_visitor_test.go diff --git a/internal/php5/parser_test.go b/internal/php5/parser_test.go new file mode 100644 index 0000000..638d1df --- /dev/null +++ b/internal/php5/parser_test.go @@ -0,0 +1,23147 @@ +package php5_test + +import ( + "gotest.tools/assert" + "testing" + + "github.com/z7zmey/php-parser/internal/php5" + "github.com/z7zmey/php-parser/pkg/ast" + "github.com/z7zmey/php-parser/pkg/position" +) + +func TestIdentifier(t *testing.T) { + src := `bar($a, ...$b); + foo::bar($a, ...$b); + $foo::bar($a, ...$b); + new foo($a, ...$b); + ` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 2, + EndLine: 7, + StartPos: 6, + EndPos: 133, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 2, + EndLine: 2, + StartPos: 6, + EndPos: 21, + }, + }, + Expr: &ast.ExprFunctionCall{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 2, + EndLine: 2, + StartPos: 6, + EndPos: 20, + }, + }, + Function: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 2, + EndLine: 2, + StartPos: 6, + EndPos: 9, + }, + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 2, + EndLine: 2, + StartPos: 6, + EndPos: 9, + }, + }, + Value: []byte("foo"), + }, + }, + }, + ArgumentList: &ast.ArgumentList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 2, + EndLine: 2, + StartPos: 9, + EndPos: 20, + }, + }, + Arguments: []ast.Vertex{ + &ast.Argument{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 2, + EndLine: 2, + StartPos: 10, + EndPos: 12, + }, + }, + Variadic: false, + IsReference: false, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 2, + EndLine: 2, + StartPos: 10, + EndPos: 12, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 2, + EndLine: 2, + StartPos: 10, + EndPos: 12, + }, + }, + Value: []byte("a"), + }, + }, + }, + &ast.Argument{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 2, + EndLine: 2, + StartPos: 14, + EndPos: 19, + }, + }, + Variadic: true, + IsReference: false, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 2, + EndLine: 2, + StartPos: 17, + EndPos: 19, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 2, + EndLine: 2, + StartPos: 17, + EndPos: 19, + }, + }, + Value: []byte("b"), + }, + }, + }, + }, + }, + }, + }, + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 3, + EndLine: 3, + StartPos: 24, + EndPos: 40, + }, + }, + Expr: &ast.ExprFunctionCall{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 3, + EndLine: 3, + StartPos: 24, + EndPos: 39, + }, + }, + Function: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 3, + EndLine: 3, + StartPos: 24, + EndPos: 28, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 3, + EndLine: 3, + StartPos: 24, + EndPos: 28, + }, + }, + Value: []byte("foo"), + }, + }, + ArgumentList: &ast.ArgumentList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 3, + EndLine: 3, + StartPos: 28, + EndPos: 39, + }, + }, + Arguments: []ast.Vertex{ + &ast.Argument{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 3, + EndLine: 3, + StartPos: 29, + EndPos: 31, + }, + }, + Variadic: false, + IsReference: false, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 3, + EndLine: 3, + StartPos: 29, + EndPos: 31, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 3, + EndLine: 3, + StartPos: 29, + EndPos: 31, + }, + }, + Value: []byte("a"), + }, + }, + }, + &ast.Argument{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 3, + EndLine: 3, + StartPos: 33, + EndPos: 38, + }, + }, + Variadic: true, + IsReference: false, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 3, + EndLine: 3, + StartPos: 36, + EndPos: 38, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 3, + EndLine: 3, + StartPos: 36, + EndPos: 38, + }, + }, + Value: []byte("b"), + }, + }, + }, + }, + }, + }, + }, + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 4, + EndLine: 4, + StartPos: 43, + EndPos: 64, + }, + }, + Expr: &ast.ExprMethodCall{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 4, + EndLine: 4, + StartPos: 43, + EndPos: 63, + }, + }, + Var: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 4, + EndLine: 4, + StartPos: 43, + EndPos: 47, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 4, + EndLine: 4, + StartPos: 43, + EndPos: 47, + }, + }, + Value: []byte("foo"), + }, + }, + Method: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 4, + EndLine: 4, + StartPos: 49, + EndPos: 52, + }, + }, + Value: []byte("bar"), + }, + ArgumentList: &ast.ArgumentList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 4, + EndLine: 4, + StartPos: 52, + EndPos: 63, + }, + }, + Arguments: []ast.Vertex{ + &ast.Argument{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 4, + EndLine: 4, + StartPos: 53, + EndPos: 55, + }, + }, + Variadic: false, + IsReference: false, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 4, + EndLine: 4, + StartPos: 53, + EndPos: 55, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 4, + EndLine: 4, + StartPos: 53, + EndPos: 55, + }, + }, + Value: []byte("a"), + }, + }, + }, + &ast.Argument{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 4, + EndLine: 4, + StartPos: 57, + EndPos: 62, + }, + }, + IsReference: false, + Variadic: true, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 4, + EndLine: 4, + StartPos: 60, + EndPos: 62, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 4, + EndLine: 4, + StartPos: 60, + EndPos: 62, + }, + }, + Value: []byte("b"), + }, + }, + }, + }, + }, + }, + }, + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 5, + EndLine: 5, + StartPos: 67, + EndPos: 87, + }, + }, + Expr: &ast.ExprStaticCall{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 5, + EndLine: 5, + StartPos: 67, + EndPos: 86, + }, + }, + Class: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 5, + EndLine: 5, + StartPos: 67, + EndPos: 70, + }, + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 5, + EndLine: 5, + StartPos: 67, + EndPos: 70, + }, + }, + Value: []byte("foo"), + }, + }, + }, + Call: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 5, + EndLine: 5, + StartPos: 72, + EndPos: 75, + }, + }, + Value: []byte("bar"), + }, + ArgumentList: &ast.ArgumentList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 5, + EndLine: 5, + StartPos: 75, + EndPos: 86, + }, + }, + Arguments: []ast.Vertex{ + &ast.Argument{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 5, + EndLine: 5, + StartPos: 76, + EndPos: 78, + }, + }, + Variadic: false, + IsReference: false, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 5, + EndLine: 5, + StartPos: 76, + EndPos: 78, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 5, + EndLine: 5, + StartPos: 76, + EndPos: 78, + }, + }, + Value: []byte("a"), + }, + }, + }, + &ast.Argument{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 5, + EndLine: 5, + StartPos: 80, + EndPos: 85, + }, + }, + Variadic: true, + IsReference: false, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 5, + EndLine: 5, + StartPos: 83, + EndPos: 85, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 5, + EndLine: 5, + StartPos: 83, + EndPos: 85, + }, + }, + Value: []byte("b"), + }, + }, + }, + }, + }, + }, + }, + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 6, + EndLine: 6, + StartPos: 90, + EndPos: 111, + }, + }, + Expr: &ast.ExprStaticCall{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 6, + EndLine: 6, + StartPos: 90, + EndPos: 110, + }, + }, + Class: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 6, + EndLine: 6, + StartPos: 90, + EndPos: 94, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 6, + EndLine: 6, + StartPos: 90, + EndPos: 94, + }, + }, + Value: []byte("foo"), + }, + }, + Call: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 6, + EndLine: 6, + StartPos: 96, + EndPos: 99, + }, + }, + Value: []byte("bar"), + }, + ArgumentList: &ast.ArgumentList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 6, + EndLine: 6, + StartPos: 99, + EndPos: 110, + }, + }, + Arguments: []ast.Vertex{ + &ast.Argument{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 6, + EndLine: 6, + StartPos: 100, + EndPos: 102, + }, + }, + Variadic: false, + IsReference: false, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 6, + EndLine: 6, + StartPos: 100, + EndPos: 102, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 6, + EndLine: 6, + StartPos: 100, + EndPos: 102, + }, + }, + Value: []byte("a"), + }, + }, + }, + &ast.Argument{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 6, + EndLine: 6, + StartPos: 104, + EndPos: 109, + }, + }, + Variadic: true, + IsReference: false, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 6, + EndLine: 6, + StartPos: 107, + EndPos: 109, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 6, + EndLine: 6, + StartPos: 107, + EndPos: 109, + }, + }, + Value: []byte("b"), + }, + }, + }, + }, + }, + }, + }, + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 7, + EndLine: 7, + StartPos: 114, + EndPos: 133, + }, + }, + Expr: &ast.ExprNew{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 7, + EndLine: 7, + StartPos: 114, + EndPos: 132, + }, + }, + Class: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 7, + EndLine: 7, + StartPos: 118, + EndPos: 121, + }, + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 7, + EndLine: 7, + StartPos: 118, + EndPos: 121, + }, + }, + Value: []byte("foo"), + }, + }, + }, + ArgumentList: &ast.ArgumentList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 7, + EndLine: 7, + StartPos: 121, + EndPos: 132, + }, + }, + Arguments: []ast.Vertex{ + &ast.Argument{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 7, + EndLine: 7, + StartPos: 122, + EndPos: 124, + }, + }, + Variadic: false, + IsReference: false, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 7, + EndLine: 7, + StartPos: 122, + EndPos: 124, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 7, + EndLine: 7, + StartPos: 122, + EndPos: 124, + }, + }, + Value: []byte("a"), + }, + }, + }, + &ast.Argument{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 7, + EndLine: 7, + StartPos: 126, + EndPos: 131, + }, + }, + Variadic: true, + IsReference: false, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 7, + EndLine: 7, + StartPos: 129, + EndPos: 131, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 7, + EndLine: 7, + StartPos: 129, + EndPos: 131, + }, + }, + Value: []byte("b"), + }, + }, + }, + }, + }, + }, + }, + }, + } + + php5parser := php5.NewParser([]byte(src), "5.6") + php5parser.Parse() + actual := php5parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestPhp5ParameterNode(t *testing.T) { + src := `bar()";` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 22, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 22, + }, + }, + Expr: &ast.ScalarEncapsed{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 21, + }, + }, + Parts: []ast.Vertex{ + &ast.ScalarEncapsedStringPart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 4, + EndPos: 9, + }, + }, + Value: []byte("test "), + }, + &ast.ExprPropertyFetch{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 9, + EndPos: 18, + }, + }, + Var: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 9, + EndPos: 13, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 9, + EndPos: 13, + }, + }, + Value: []byte("foo"), + }, + }, + Property: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 15, + EndPos: 18, + }, + }, + Value: []byte("bar"), + }, + }, + &ast.ScalarEncapsedStringPart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 18, + EndPos: 20, + }, + }, + Value: []byte("()"), + }, + }, + }, + }, + }, + } + + php5parser := php5.NewParser([]byte(src), "5.6") + php5parser.Parse() + actual := php5parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestScalarEncapsed_DollarOpenCurlyBraces(t *testing.T) { + src := `bar()}";` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 24, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 24, + }, + }, + Expr: &ast.ScalarEncapsed{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 23, + }, + }, + Parts: []ast.Vertex{ + &ast.ScalarEncapsedStringPart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 4, + EndPos: 9, + }, + }, + Value: []byte("test "), + }, + &ast.ExprMethodCall{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 10, + EndPos: 21, + }, + }, + Var: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 10, + EndPos: 14, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 10, + EndPos: 14, + }, + }, + Value: []byte("foo"), + }, + }, + Method: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 16, + EndPos: 19, + }, + }, + Value: []byte("bar"), + }, + ArgumentList: &ast.ArgumentList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 19, + EndPos: 21, + }, + }, + }, + }, + }, + }, + }, + }, + } + + php5parser := php5.NewParser([]byte(src), "5.6") + php5parser.Parse() + actual := php5parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestScalarHeredoc_HeredocSimpleLabel(t *testing.T) { + src := ` $v) {}` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 30, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtForeach{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 30, + }, + }, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 14, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 14, + }, + }, + Value: []byte("a"), + }, + }, + Key: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 18, + EndPos: 20, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 18, + EndPos: 20, + }, + }, + Value: []byte("k"), + }, + }, + Var: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 24, + EndPos: 26, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 24, + EndPos: 26, + }, + }, + Value: []byte("v"), + }, + }, + Stmt: &ast.StmtStmtList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 28, + EndPos: 30, + }, + }, + Stmts: []ast.Vertex{}, + }, + }, + }, + } + + php5parser := php5.NewParser([]byte(src), "5.6") + php5parser.Parse() + actual := php5parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestStmtForeach_ExprWithKey(t *testing.T) { + src := ` $v) {}` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 30, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtForeach{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 30, + }, + }, + Expr: &ast.ExprShortArray{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 14, + }, + }, + Items: []ast.Vertex{}, + }, + Key: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 18, + EndPos: 20, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 18, + EndPos: 20, + }, + }, + Value: []byte("k"), + }, + }, + Var: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 24, + EndPos: 26, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 24, + EndPos: 26, + }, + }, + Value: []byte("v"), + }, + }, + Stmt: &ast.StmtStmtList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 28, + EndPos: 30, + }, + }, + Stmts: []ast.Vertex{}, + }, + }, + }, + } + + php5parser := php5.NewParser([]byte(src), "5.6") + php5parser.Parse() + actual := php5parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestStmtForeach_WithRef(t *testing.T) { + src := ` &$v) {}` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 31, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtForeach{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 31, + }, + }, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 14, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 14, + }, + }, + Value: []byte("a"), + }, + }, + Key: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 18, + EndPos: 20, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 18, + EndPos: 20, + }, + }, + Value: []byte("k"), + }, + }, + Var: &ast.ExprReference{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 24, + EndPos: 27, + }, + }, + Var: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 25, + EndPos: 27, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 25, + EndPos: 27, + }, + }, + Value: []byte("v"), + }, + }, + }, + Stmt: &ast.StmtStmtList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 29, + EndPos: 31, + }, + }, + Stmts: []ast.Vertex{}, + }, + }, + }, + } + + php5parser := php5.NewParser([]byte(src), "5.6") + php5parser.Parse() + actual := php5parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestStmtForeach_WithList(t *testing.T) { + src := ` list($v)) {}` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 36, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtForeach{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 36, + }, + }, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 14, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 14, + }, + }, + Value: []byte("a"), + }, + }, + Key: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 18, + EndPos: 20, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 18, + EndPos: 20, + }, + }, + Value: []byte("k"), + }, + }, + Var: &ast.ExprList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 24, + EndPos: 32, + }, + }, + Items: []ast.Vertex{ + &ast.ExprArrayItem{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 29, + EndPos: 31, + }, + }, + Val: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 29, + EndPos: 31, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 29, + EndPos: 31, + }, + }, + Value: []byte("v"), + }, + }, + }, + }, + }, + Stmt: &ast.StmtStmtList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 34, + EndPos: 36, + }, + }, + Stmts: []ast.Vertex{}, + }, + }, + }, + } + + php5parser := php5.NewParser([]byte(src), "5.6") + php5parser.Parse() + actual := php5parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestStmtFunction(t *testing.T) { + src := `
` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 17, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtNop{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 5, + }, + }, + }, + &ast.StmtInlineHtml{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 5, + EndPos: 17, + }, + }, + Value: []byte("
"), + }, + }, + } + + php5parser := php5.NewParser([]byte(src), "5.6") + php5parser.Parse() + actual := php5parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestStmtInterface(t *testing.T) { + src := `1, &$b,);` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 21, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 21, + }, + }, + Expr: &ast.ExprArray{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 20, + }, + }, + Items: []ast.Vertex{ + &ast.ExprArrayItem{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 9, + EndPos: 13, + }, + }, + Key: &ast.ScalarLnumber{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 9, + EndPos: 10, + }, + }, + Value: []byte("1"), + }, + Val: &ast.ScalarLnumber{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 13, + }, + }, + Value: []byte("1"), + }, + }, + &ast.ExprArrayItem{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 15, + EndPos: 18, + }, + }, + Val: &ast.ExprReference{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 15, + EndPos: 18, + }, + }, + Var: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 16, + EndPos: 18, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 16, + EndPos: 18, + }, + }, + Value: []byte("b"), + }, + }, + }, + }, + &ast.ExprArrayItem{}, + }, + }, + }, + }, + } + + php5parser := php5.NewParser([]byte(src), "5.6") + php5parser.Parse() + actual := php5parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestExprBitwiseNot(t *testing.T) { + src := `foo();` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 13, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 13, + }, + }, + Expr: &ast.ExprMethodCall{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 12, + }, + }, + Var: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 5, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 5, + }, + }, + Value: []byte("a"), + }, + }, + Method: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 10, + }, + }, + Value: []byte("foo"), + }, + ArgumentList: &ast.ArgumentList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 10, + EndPos: 12, + }, + }, + }, + }, + }, + }, + } + + php5parser := php5.NewParser([]byte(src), "5.6") + php5parser.Parse() + actual := php5parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestExprNew(t *testing.T) { + src := `foo;` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 11, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 11, + }, + }, + Expr: &ast.ExprPropertyFetch{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 10, + }, + }, + Var: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 5, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 5, + }, + }, + Value: []byte("a"), + }, + }, + Property: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 10, + }, + }, + Value: []byte("foo"), + }, + }, + }, + }, + } + + php5parser := php5.NewParser([]byte(src), "5.6") + php5parser.Parse() + actual := php5parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestExprReference_ForeachWithRef(t *testing.T) { + t.Helper() + src := ` &$v) {}` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 31, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtForeach{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 31, + }, + }, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 14, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 14, + }, + }, + Value: []byte("a"), + }, + }, + Key: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 18, + EndPos: 20, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 18, + EndPos: 20, + }, + }, + Value: []byte("k"), + }, + }, + Var: &ast.ExprReference{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 24, + EndPos: 27, + }, + }, + Var: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 25, + EndPos: 27, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 25, + EndPos: 27, + }, + }, + Value: []byte("v"), + }, + }, + }, + Stmt: &ast.StmtStmtList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 29, + EndPos: 31, + }, + }, + Stmts: []ast.Vertex{}, + }, + }, + }, + } + + php5parser := php5.NewParser([]byte(src), "5.6") + php5parser.Parse() + actual := php5parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestExprShellExec(t *testing.T) { + src := "1, &$b,];` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 16, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 16, + }, + }, + Expr: &ast.ExprShortArray{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 15, + }, + }, + Items: []ast.Vertex{ + &ast.ExprArrayItem{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 4, + EndPos: 8, + }, + }, + Key: &ast.ScalarLnumber{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 4, + EndPos: 5, + }, + }, + Value: []byte("1"), + }, + Val: &ast.ScalarLnumber{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 8, + }, + }, + Value: []byte("1"), + }, + }, + &ast.ExprArrayItem{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 10, + EndPos: 13, + }, + }, + Val: &ast.ExprReference{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 10, + EndPos: 13, + }, + }, + Var: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 11, + EndPos: 13, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 11, + EndPos: 13, + }, + }, + Value: []byte("b"), + }, + }, + }, + }, + &ast.ExprArrayItem{}, + }, + }, + }, + }, + } + + php5parser := php5.NewParser([]byte(src), "5.6") + php5parser.Parse() + actual := php5parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestExprStaticCall(t *testing.T) { + src := ` $b;` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 18, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 18, + }, + }, + Expr: &ast.ExprYield{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 17, + }, + }, + Key: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 9, + EndPos: 11, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 9, + EndPos: 11, + }, + }, + Value: []byte("a"), + }, + }, + Value: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 15, + EndPos: 17, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 15, + EndPos: 17, + }, + }, + Value: []byte("b"), + }, + }, + }, + }, + }, + } + + php5parser := php5.NewParser([]byte(src), "5.6") + php5parser.Parse() + actual := php5parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestExprYield_Expr(t *testing.T) { + src := ` 1;` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 17, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 17, + }, + }, + Expr: &ast.ExprYield{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 16, + }, + }, + Key: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 9, + EndPos: 11, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 9, + EndPos: 11, + }, + }, + Value: []byte("a"), + }, + }, + Value: &ast.ScalarLnumber{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 15, + EndPos: 16, + }, + }, + Value: []byte("1"), + }, + }, + }, + }, + } + + php5parser := php5.NewParser([]byte(src), "5.6") + php5parser.Parse() + actual := php5parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +// expr assign + +func TestExprAssign_Assign(t *testing.T) { + src := `>= $b;` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 13, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 13, + }, + }, + Expr: &ast.ExprAssignShiftRight{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 12, + }, + }, + Var: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 5, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 5, + }, + }, + Value: []byte("a"), + }, + }, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 10, + EndPos: 12, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 10, + EndPos: 12, + }, + }, + Value: []byte("b"), + }, + }, + }, + }, + }, + } + + php5parser := php5.NewParser([]byte(src), "5.6") + php5parser.Parse() + actual := php5parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +// expr binary + +func TestExprBinary_BitwiseAnd(t *testing.T) { + src := `= $b;` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 12, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 12, + }, + }, + Expr: &ast.ExprBinaryGreaterOrEqual{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 11, + }, + }, + Left: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 5, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 5, + }, + }, + Value: []byte("a"), + }, + }, + Right: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 9, + EndPos: 11, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 9, + EndPos: 11, + }, + }, + Value: []byte("b"), + }, + }, + }, + }, + }, + } + + php5parser := php5.NewParser([]byte(src), "5.6") + php5parser.Parse() + actual := php5parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestExprBinary_Greater(t *testing.T) { + src := ` $b;` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 11, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 11, + }, + }, + Expr: &ast.ExprBinaryGreater{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 10, + }, + }, + Left: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 5, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 5, + }, + }, + Value: []byte("a"), + }, + }, + Right: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 8, + EndPos: 10, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 8, + EndPos: 10, + }, + }, + Value: []byte("b"), + }, + }, + }, + }, + }, + } + + php5parser := php5.NewParser([]byte(src), "5.6") + php5parser.Parse() + actual := php5parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestExprBinary_Identical(t *testing.T) { + src := `> $b;` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 12, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 12, + }, + }, + Expr: &ast.ExprBinaryShiftRight{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 11, + }, + }, + Left: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 5, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 5, + }, + }, + Value: []byte("a"), + }, + }, + Right: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 9, + EndPos: 11, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 9, + EndPos: 11, + }, + }, + Value: []byte("b"), + }, + }, + }, + }, + }, + } + + php5parser := php5.NewParser([]byte(src), "5.6") + php5parser.Parse() + actual := php5parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestExprBinary_SmallerOrEqual(t *testing.T) { + src := `bar($a, ...$b); + foo::bar($a, ...$b); + $foo::bar($a, ...$b); + new foo($a, ...$b); + /** anonymous class */ + new class ($a, ...$b) {}; + ` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 2, + EndLine: 9, + StartPos: 6, + EndPos: 186, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 2, + EndLine: 2, + StartPos: 6, + EndPos: 21, + }, + }, + Expr: &ast.ExprFunctionCall{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 2, + EndLine: 2, + StartPos: 6, + EndPos: 20, + }, + }, + Function: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 2, + EndLine: 2, + StartPos: 6, + EndPos: 9, + }, + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 2, + EndLine: 2, + StartPos: 6, + EndPos: 9, + }, + }, + Value: []byte("foo"), + }, + }, + }, + ArgumentList: &ast.ArgumentList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 2, + EndLine: 2, + StartPos: 9, + EndPos: 20, + }, + }, + Arguments: []ast.Vertex{ + &ast.Argument{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 2, + EndLine: 2, + StartPos: 10, + EndPos: 12, + }, + }, + Variadic: false, + IsReference: false, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 2, + EndLine: 2, + StartPos: 10, + EndPos: 12, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 2, + EndLine: 2, + StartPos: 10, + EndPos: 12, + }, + }, + Value: []byte("a"), + }, + }, + }, + &ast.Argument{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 2, + EndLine: 2, + StartPos: 14, + EndPos: 19, + }, + }, + Variadic: true, + IsReference: false, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 2, + EndLine: 2, + StartPos: 17, + EndPos: 19, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 2, + EndLine: 2, + StartPos: 17, + EndPos: 19, + }, + }, + Value: []byte("b"), + }, + }, + }, + }, + }, + }, + }, + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 3, + EndLine: 3, + StartPos: 24, + EndPos: 40, + }, + }, + Expr: &ast.ExprFunctionCall{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 3, + EndLine: 3, + StartPos: 24, + EndPos: 39, + }, + }, + Function: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 3, + EndLine: 3, + StartPos: 24, + EndPos: 28, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 3, + EndLine: 3, + StartPos: 24, + EndPos: 28, + }, + }, + Value: []byte("foo"), + }, + }, + ArgumentList: &ast.ArgumentList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 3, + EndLine: 3, + StartPos: 28, + EndPos: 39, + }, + }, + Arguments: []ast.Vertex{ + &ast.Argument{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 3, + EndLine: 3, + StartPos: 29, + EndPos: 31, + }, + }, + Variadic: false, + IsReference: false, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 3, + EndLine: 3, + StartPos: 29, + EndPos: 31, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 3, + EndLine: 3, + StartPos: 29, + EndPos: 31, + }, + }, + Value: []byte("a"), + }, + }, + }, + &ast.Argument{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 3, + EndLine: 3, + StartPos: 33, + EndPos: 38, + }, + }, + Variadic: true, + IsReference: false, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 3, + EndLine: 3, + StartPos: 36, + EndPos: 38, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 3, + EndLine: 3, + StartPos: 36, + EndPos: 38, + }, + }, + Value: []byte("b"), + }, + }, + }, + }, + }, + }, + }, + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 4, + EndLine: 4, + StartPos: 43, + EndPos: 64, + }, + }, + Expr: &ast.ExprMethodCall{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 4, + EndLine: 4, + StartPos: 43, + EndPos: 63, + }, + }, + Var: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 4, + EndLine: 4, + StartPos: 43, + EndPos: 47, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 4, + EndLine: 4, + StartPos: 43, + EndPos: 47, + }, + }, + Value: []byte("foo"), + }, + }, + Method: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 4, + EndLine: 4, + StartPos: 49, + EndPos: 52, + }, + }, + Value: []byte("bar"), + }, + ArgumentList: &ast.ArgumentList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 4, + EndLine: 4, + StartPos: 52, + EndPos: 63, + }, + }, + Arguments: []ast.Vertex{ + &ast.Argument{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 4, + EndLine: 4, + StartPos: 53, + EndPos: 55, + }, + }, + IsReference: false, + Variadic: false, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 4, + EndLine: 4, + StartPos: 53, + EndPos: 55, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 4, + EndLine: 4, + StartPos: 53, + EndPos: 55, + }, + }, + Value: []byte("a"), + }, + }, + }, + &ast.Argument{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 4, + EndLine: 4, + StartPos: 57, + EndPos: 62, + }, + }, + Variadic: true, + IsReference: false, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 4, + EndLine: 4, + StartPos: 60, + EndPos: 62, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 4, + EndLine: 4, + StartPos: 60, + EndPos: 62, + }, + }, + Value: []byte("b"), + }, + }, + }, + }, + }, + }, + }, + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 5, + EndLine: 5, + StartPos: 67, + EndPos: 87, + }, + }, + Expr: &ast.ExprStaticCall{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 5, + EndLine: 5, + StartPos: 67, + EndPos: 86, + }, + }, + Class: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 5, + EndLine: 5, + StartPos: 67, + EndPos: 70, + }, + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 5, + EndLine: 5, + StartPos: 67, + EndPos: 70, + }, + }, + Value: []byte("foo"), + }, + }, + }, + Call: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 5, + EndLine: 5, + StartPos: 72, + EndPos: 75, + }, + }, + Value: []byte("bar"), + }, + ArgumentList: &ast.ArgumentList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 5, + EndLine: 5, + StartPos: 75, + EndPos: 86, + }, + }, + Arguments: []ast.Vertex{ + &ast.Argument{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 5, + EndLine: 5, + StartPos: 76, + EndPos: 78, + }, + }, + Variadic: false, + IsReference: false, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 5, + EndLine: 5, + StartPos: 76, + EndPos: 78, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 5, + EndLine: 5, + StartPos: 76, + EndPos: 78, + }, + }, + Value: []byte("a"), + }, + }, + }, + &ast.Argument{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 5, + EndLine: 5, + StartPos: 80, + EndPos: 85, + }, + }, + Variadic: true, + IsReference: false, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 5, + EndLine: 5, + StartPos: 83, + EndPos: 85, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 5, + EndLine: 5, + StartPos: 83, + EndPos: 85, + }, + }, + Value: []byte("b"), + }, + }, + }, + }, + }, + }, + }, + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 6, + EndLine: 6, + StartPos: 90, + EndPos: 111, + }, + }, + Expr: &ast.ExprStaticCall{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 6, + EndLine: 6, + StartPos: 90, + EndPos: 110, + }, + }, + Class: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 6, + EndLine: 6, + StartPos: 90, + EndPos: 94, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 6, + EndLine: 6, + StartPos: 90, + EndPos: 94, + }, + }, + Value: []byte("foo"), + }, + }, + Call: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 6, + EndLine: 6, + StartPos: 96, + EndPos: 99, + }, + }, + Value: []byte("bar"), + }, + ArgumentList: &ast.ArgumentList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 6, + EndLine: 6, + StartPos: 99, + EndPos: 110, + }, + }, + Arguments: []ast.Vertex{ + &ast.Argument{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 6, + EndLine: 6, + StartPos: 100, + EndPos: 102, + }, + }, + Variadic: false, + IsReference: false, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 6, + EndLine: 6, + StartPos: 100, + EndPos: 102, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 6, + EndLine: 6, + StartPos: 100, + EndPos: 102, + }, + }, + Value: []byte("a"), + }, + }, + }, + &ast.Argument{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 6, + EndLine: 6, + StartPos: 104, + EndPos: 109, + }, + }, + Variadic: true, + IsReference: false, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 6, + EndLine: 6, + StartPos: 107, + EndPos: 109, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 6, + EndLine: 6, + StartPos: 107, + EndPos: 109, + }, + }, + Value: []byte("b"), + }, + }, + }, + }, + }, + }, + }, + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 7, + EndLine: 7, + StartPos: 114, + EndPos: 133, + }, + }, + Expr: &ast.ExprNew{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 7, + EndLine: 7, + StartPos: 114, + EndPos: 132, + }, + }, + Class: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 7, + EndLine: 7, + StartPos: 118, + EndPos: 121, + }, + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 7, + EndLine: 7, + StartPos: 118, + EndPos: 121, + }, + }, + Value: []byte("foo"), + }, + }, + }, + ArgumentList: &ast.ArgumentList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 7, + EndLine: 7, + StartPos: 121, + EndPos: 132, + }, + }, + Arguments: []ast.Vertex{ + &ast.Argument{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 7, + EndLine: 7, + StartPos: 122, + EndPos: 124, + }, + }, + Variadic: false, + IsReference: false, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 7, + EndLine: 7, + StartPos: 122, + EndPos: 124, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 7, + EndLine: 7, + StartPos: 122, + EndPos: 124, + }, + }, + Value: []byte("a"), + }, + }, + }, + &ast.Argument{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 7, + EndLine: 7, + StartPos: 126, + EndPos: 131, + }, + }, + Variadic: true, + IsReference: false, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 7, + EndLine: 7, + StartPos: 129, + EndPos: 131, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 7, + EndLine: 7, + StartPos: 129, + EndPos: 131, + }, + }, + Value: []byte("b"), + }, + }, + }, + }, + }, + }, + }, + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 9, + EndLine: 9, + StartPos: 161, + EndPos: 186, + }, + }, + Expr: &ast.ExprNew{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 9, + EndLine: 9, + StartPos: 161, + EndPos: 185, + }, + }, + Class: &ast.StmtClass{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 9, + EndLine: 9, + StartPos: 165, + EndPos: 185, + }, + }, + ArgumentList: &ast.ArgumentList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 9, + EndLine: 9, + StartPos: 171, + EndPos: 182, + }, + }, + Arguments: []ast.Vertex{ + &ast.Argument{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 9, + EndLine: 9, + StartPos: 172, + EndPos: 174, + }, + }, + Variadic: false, + IsReference: false, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 9, + EndLine: 9, + StartPos: 172, + EndPos: 174, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 9, + EndLine: 9, + StartPos: 172, + EndPos: 174, + }, + }, + Value: []byte("a"), + }, + }, + }, + &ast.Argument{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 9, + EndLine: 9, + StartPos: 176, + EndPos: 181, + }, + }, + Variadic: true, + IsReference: false, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 9, + EndLine: 9, + StartPos: 179, + EndPos: 181, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 9, + EndLine: 9, + StartPos: 179, + EndPos: 181, + }, + }, + Value: []byte("b"), + }, + }, + }, + }, + }, + Stmts: []ast.Vertex{}, + }, + }, + }, + }, + } + + php7parser := php7.NewParser([]byte(src), "7.4") + php7parser.Parse() + actual := php7parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestPhp7ParameterNode(t *testing.T) { + src := `bar()";` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 22, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 22, + }, + }, + Expr: &ast.ScalarEncapsed{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 21, + }, + }, + Parts: []ast.Vertex{ + &ast.ScalarEncapsedStringPart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 4, + EndPos: 9, + }, + }, + Value: []byte("test "), + }, + &ast.ExprPropertyFetch{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 9, + EndPos: 18, + }, + }, + Var: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 9, + EndPos: 13, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 9, + EndPos: 13, + }, + }, + Value: []byte("foo"), + }, + }, + Property: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 15, + EndPos: 18, + }, + }, + Value: []byte("bar"), + }, + }, + &ast.ScalarEncapsedStringPart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 18, + EndPos: 20, + }, + }, + Value: []byte("()"), + }, + }, + }, + }, + }, + } + + php7parser := php7.NewParser([]byte(src), "7.4") + php7parser.Parse() + actual := php7parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestScalarEncapsed_DollarOpenCurlyBraces(t *testing.T) { + src := `bar()}";` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 24, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 24, + }, + }, + Expr: &ast.ScalarEncapsed{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 23, + }, + }, + Parts: []ast.Vertex{ + &ast.ScalarEncapsedStringPart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 4, + EndPos: 9, + }, + }, + Value: []byte("test "), + }, + &ast.ExprMethodCall{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 10, + EndPos: 21, + }, + }, + Var: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 10, + EndPos: 14, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 10, + EndPos: 14, + }, + }, + Value: []byte("foo"), + }, + }, + Method: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 16, + EndPos: 19, + }, + }, + Value: []byte("bar"), + }, + ArgumentList: &ast.ArgumentList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 19, + EndPos: 21, + }, + }, + }, + }, + }, + }, + }, + }, + } + + php7parser := php7.NewParser([]byte(src), "7.4") + php7parser.Parse() + actual := php7parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestScalarHeredoc_HeredocSimpleLabel(t *testing.T) { + src := ` $v) {}` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 30, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtForeach{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 30, + }, + }, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 14, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 14, + }, + }, + Value: []byte("a"), + }, + }, + Key: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 18, + EndPos: 20, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 18, + EndPos: 20, + }, + }, + Value: []byte("k"), + }, + }, + Var: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 24, + EndPos: 26, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 24, + EndPos: 26, + }, + }, + Value: []byte("v"), + }, + }, + Stmt: &ast.StmtStmtList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 28, + EndPos: 30, + }, + }, + Stmts: []ast.Vertex{}, + }, + }, + }, + } + + php7parser := php7.NewParser([]byte(src), "7.4") + php7parser.Parse() + actual := php7parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestStmtForeach_ExprWithKey(t *testing.T) { + src := ` $v) {}` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 30, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtForeach{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 30, + }, + }, + Expr: &ast.ExprShortArray{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 14, + }, + }, + Items: []ast.Vertex{}, + }, + Key: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 18, + EndPos: 20, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 18, + EndPos: 20, + }, + }, + Value: []byte("k"), + }, + }, + Var: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 24, + EndPos: 26, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 24, + EndPos: 26, + }, + }, + Value: []byte("v"), + }, + }, + Stmt: &ast.StmtStmtList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 28, + EndPos: 30, + }, + }, + Stmts: []ast.Vertex{}, + }, + }, + }, + } + + php7parser := php7.NewParser([]byte(src), "7.4") + php7parser.Parse() + actual := php7parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestStmtForeach_WithRef(t *testing.T) { + src := ` &$v) {}` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 31, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtForeach{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 31, + }, + }, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 14, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 14, + }, + }, + Value: []byte("a"), + }, + }, + Key: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 18, + EndPos: 20, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 18, + EndPos: 20, + }, + }, + Value: []byte("k"), + }, + }, + Var: &ast.ExprReference{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 24, + EndPos: 27, + }, + }, + Var: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 25, + EndPos: 27, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 25, + EndPos: 27, + }, + }, + Value: []byte("v"), + }, + }, + }, + Stmt: &ast.StmtStmtList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 29, + EndPos: 31, + }, + }, + Stmts: []ast.Vertex{}, + }, + }, + }, + } + + php7parser := php7.NewParser([]byte(src), "7.4") + php7parser.Parse() + actual := php7parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestStmtForeach_WithList(t *testing.T) { + src := ` list($v)) {}` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 36, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtForeach{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 36, + }, + }, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 14, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 14, + }, + }, + Value: []byte("a"), + }, + }, + Key: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 18, + EndPos: 20, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 18, + EndPos: 20, + }, + }, + Value: []byte("k"), + }, + }, + Var: &ast.ExprList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 24, + EndPos: 32, + }, + }, + Items: []ast.Vertex{ + &ast.ExprArrayItem{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 29, + EndPos: 31, + }, + }, + Val: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 29, + EndPos: 31, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 29, + EndPos: 31, + }, + }, + Value: []byte("v"), + }, + }, + }, + }, + }, + Stmt: &ast.StmtStmtList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 34, + EndPos: 36, + }, + }, + Stmts: []ast.Vertex{}, + }, + }, + }, + } + + php7parser := php7.NewParser([]byte(src), "7.4") + php7parser.Parse() + actual := php7parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestStmtFunction(t *testing.T) { + src := `
` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 17, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtNop{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 5, + }, + }, + }, + &ast.StmtInlineHtml{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 5, + EndPos: 17, + }, + }, + Value: []byte("
"), + }, + }, + } + + php7parser := php7.NewParser([]byte(src), "7.4") + php7parser.Parse() + actual := php7parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestStmtInterface(t *testing.T) { + src := `1, &$b,);` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 21, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 21, + }, + }, + Expr: &ast.ExprArray{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 20, + }, + }, + Items: []ast.Vertex{ + &ast.ExprArrayItem{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 9, + EndPos: 13, + }, + }, + Key: &ast.ScalarLnumber{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 9, + EndPos: 10, + }, + }, + Value: []byte("1"), + }, + Val: &ast.ScalarLnumber{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 13, + }, + }, + Value: []byte("1"), + }, + }, + &ast.ExprArrayItem{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 15, + EndPos: 18, + }, + }, + Val: &ast.ExprReference{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 15, + EndPos: 18, + }, + }, + Var: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 16, + EndPos: 18, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 16, + EndPos: 18, + }, + }, + Value: []byte("b"), + }, + }, + }, + }, + &ast.ExprArrayItem{}, + }, + }, + }, + }, + } + + php7parser := php7.NewParser([]byte(src), "7.4") + php7parser.Parse() + actual := php7parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestExprArray_ItemUnpack(t *testing.T) { + src := ` $a;` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 14, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 14, + }, + }, + Expr: &ast.ExprArrowFunction{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 13, + }, + }, + ReturnsRef: false, + Static: false, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 11, + EndPos: 13, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 11, + EndPos: 13, + }, + }, + Value: []byte("a"), + }, + }, + }, + }, + }, + } + + php7parser := php7.NewParser([]byte(src), "7.4") + php7parser.Parse() + actual := php7parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestExprArrowFunction_ReturnType(t *testing.T) { + src := ` $a;` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 23, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 23, + }, + }, + Expr: &ast.ExprArrowFunction{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 22, + }, + }, + Static: false, + ReturnsRef: true, + ReturnType: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 13, + EndPos: 16, + }, + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 13, + EndPos: 16, + }, + }, + Value: []byte("foo"), + }, + }, + }, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 20, + EndPos: 22, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 20, + EndPos: 22, + }, + }, + Value: []byte("a"), + }, + }, + }, + }, + }, + } + + php7parser := php7.NewParser([]byte(src), "7.4") + php7parser.Parse() + actual := php7parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestExprBitwiseNot(t *testing.T) { + src := `foo();` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 13, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 13, + }, + }, + Expr: &ast.ExprMethodCall{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 12, + }, + }, + Var: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 5, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 5, + }, + }, + Value: []byte("a"), + }, + }, + Method: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 10, + }, + }, + Value: []byte("foo"), + }, + ArgumentList: &ast.ArgumentList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 10, + EndPos: 12, + }, + }, + }, + }, + }, + }, + } + + php7parser := php7.NewParser([]byte(src), "7.4") + php7parser.Parse() + actual := php7parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestExprNew(t *testing.T) { + src := `foo;` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 11, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 11, + }, + }, + Expr: &ast.ExprPropertyFetch{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 10, + }, + }, + Var: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 5, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 5, + }, + }, + Value: []byte("a"), + }, + }, + Property: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 10, + }, + }, + Value: []byte("foo"), + }, + }, + }, + }, + } + + php7parser := php7.NewParser([]byte(src), "7.4") + php7parser.Parse() + actual := php7parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestExprReference_ForeachWithRef(t *testing.T) { + t.Helper() + src := ` &$v) {}` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 31, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtForeach{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 31, + }, + }, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 14, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 14, + }, + }, + Value: []byte("a"), + }, + }, + Key: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 18, + EndPos: 20, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 18, + EndPos: 20, + }, + }, + Value: []byte("k"), + }, + }, + Var: &ast.ExprReference{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 24, + EndPos: 27, + }, + }, + Var: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 25, + EndPos: 27, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 25, + EndPos: 27, + }, + }, + Value: []byte("v"), + }, + }, + }, + Stmt: &ast.StmtStmtList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 29, + EndPos: 31, + }, + }, + Stmts: []ast.Vertex{}, + }, + }, + }, + } + + php7parser := php7.NewParser([]byte(src), "7.4") + php7parser.Parse() + actual := php7parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestExprShellExec(t *testing.T) { + src := "1, &$b,];` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 16, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 16, + }, + }, + Expr: &ast.ExprShortArray{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 15, + }, + }, + Items: []ast.Vertex{ + &ast.ExprArrayItem{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 4, + EndPos: 8, + }, + }, + Key: &ast.ScalarLnumber{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 4, + EndPos: 5, + }, + }, + Value: []byte("1"), + }, + Val: &ast.ScalarLnumber{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 8, + }, + }, + Value: []byte("1"), + }, + }, + &ast.ExprArrayItem{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 10, + EndPos: 13, + }, + }, + Val: &ast.ExprReference{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 10, + EndPos: 13, + }, + }, + Var: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 11, + EndPos: 13, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 11, + EndPos: 13, + }, + }, + Value: []byte("b"), + }, + }, + }, + }, + &ast.ExprArrayItem{}, + }, + }, + }, + }, + } + + php7parser := php7.NewParser([]byte(src), "7.4") + php7parser.Parse() + actual := php7parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestExprShortList(t *testing.T) { + src := ` $b;` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 18, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 18, + }, + }, + Expr: &ast.ExprYield{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 17, + }, + }, + Key: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 9, + EndPos: 11, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 9, + EndPos: 11, + }, + }, + Value: []byte("a"), + }, + }, + Value: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 15, + EndPos: 17, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 15, + EndPos: 17, + }, + }, + Value: []byte("b"), + }, + }, + }, + }, + }, + } + + php7parser := php7.NewParser([]byte(src), "7.4") + php7parser.Parse() + actual := php7parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestExprYield_Expr(t *testing.T) { + src := ` 1;` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 17, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 17, + }, + }, + Expr: &ast.ExprYield{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 16, + }, + }, + Key: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 9, + EndPos: 11, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 9, + EndPos: 11, + }, + }, + Value: []byte("a"), + }, + }, + Value: &ast.ScalarLnumber{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 15, + EndPos: 16, + }, + }, + Value: []byte("1"), + }, + }, + }, + }, + } + + php7parser := php7.NewParser([]byte(src), "7.4") + php7parser.Parse() + actual := php7parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestExprYieldFrom(t *testing.T) { + src := `>= $b;` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 13, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 13, + }, + }, + Expr: &ast.ExprAssignShiftRight{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 12, + }, + }, + Var: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 5, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 5, + }, + }, + Value: []byte("a"), + }, + }, + Expr: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 10, + EndPos: 12, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 10, + EndPos: 12, + }, + }, + Value: []byte("b"), + }, + }, + }, + }, + }, + } + + php7parser := php7.NewParser([]byte(src), "7.4") + php7parser.Parse() + actual := php7parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestExprAssign_Coalesce(t *testing.T) { + src := `= $b;` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 12, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 12, + }, + }, + Expr: &ast.ExprBinaryGreaterOrEqual{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 11, + }, + }, + Left: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 5, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 5, + }, + }, + Value: []byte("a"), + }, + }, + Right: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 9, + EndPos: 11, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 9, + EndPos: 11, + }, + }, + Value: []byte("b"), + }, + }, + }, + }, + }, + } + + php7parser := php7.NewParser([]byte(src), "7.4") + php7parser.Parse() + actual := php7parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestExprBinary_Greater(t *testing.T) { + src := ` $b;` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 11, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 11, + }, + }, + Expr: &ast.ExprBinaryGreater{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 10, + }, + }, + Left: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 5, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 5, + }, + }, + Value: []byte("a"), + }, + }, + Right: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 8, + EndPos: 10, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 8, + EndPos: 10, + }, + }, + Value: []byte("b"), + }, + }, + }, + }, + }, + } + + php7parser := php7.NewParser([]byte(src), "7.4") + php7parser.Parse() + actual := php7parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestExprBinary_Identical(t *testing.T) { + src := `> $b;` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 12, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 12, + }, + }, + Expr: &ast.ExprBinaryShiftRight{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 11, + }, + }, + Left: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 5, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 5, + }, + }, + Value: []byte("a"), + }, + }, + Right: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 9, + EndPos: 11, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 9, + EndPos: 11, + }, + }, + Value: []byte("b"), + }, + }, + }, + }, + }, + } + + php7parser := php7.NewParser([]byte(src), "7.4") + php7parser.Parse() + actual := php7parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +func TestExprBinary_SmallerOrEqual(t *testing.T) { + src := ` $b;` + + expected := &ast.Root{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 13, + }, + }, + Stmts: []ast.Vertex{ + &ast.StmtExpression{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 13, + }, + }, + Expr: &ast.ExprBinarySpaceship{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 12, + }, + }, + Left: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 5, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 3, + EndPos: 5, + }, + }, + Value: []byte("a"), + }, + }, + Right: &ast.ExprVariable{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 10, + EndPos: 12, + }, + }, + VarName: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 10, + EndPos: 12, + }, + }, + Value: []byte("b"), + }, + }, + }, + }, + }, + } + + php7parser := php7.NewParser([]byte(src), "7.4") + php7parser.Parse() + actual := php7parser.GetRootNode() + assert.DeepEqual(t, expected, actual) +} + +// expr cast + +func TestExprCast_Array(t *testing.T) { + src := `>= $b;` - - expected := &node.Root{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 13, - }, - Stmts: []node.Node{ - &stmt.Expression{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 13, - }, - Expr: &assign.ShiftRight{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 12, - }, - Variable: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 5, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 5, - }, - Value: "a", - }, - }, - Expression: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 10, - EndPos: 12, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 10, - EndPos: 12, - }, - Value: "b", - }, - }, - }, - }, - }, - } - - php7parser := php7.NewParser([]byte(src), "7.4") - php7parser.Parse() - actual := php7parser.GetRootNode() - assert.DeepEqual(t, expected, actual) - - php5parser := php5.NewParser([]byte(src), "5.6") - php5parser.Parse() - actual = php5parser.GetRootNode() - assert.DeepEqual(t, expected, actual) -} - -func TestCoalesce(t *testing.T) { - src := `= $b;` - - expected := &node.Root{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 12, - }, - Stmts: []node.Node{ - &stmt.Expression{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 12, - }, - Expr: &binary.GreaterOrEqual{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 11, - }, - Left: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 5, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 5, - }, - Value: "a", - }, - }, - Right: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 9, - EndPos: 11, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 9, - EndPos: 11, - }, - Value: "b", - }, - }, - }, - }, - }, - } - - php7parser := php7.NewParser([]byte(src), "7.4") - php7parser.Parse() - actual := php7parser.GetRootNode() - assert.DeepEqual(t, expected, actual) - - php5parser := php5.NewParser([]byte(src), "5.6") - php5parser.Parse() - actual = php5parser.GetRootNode() - assert.DeepEqual(t, expected, actual) -} - -func TestGreater(t *testing.T) { - src := ` $b;` - - expected := &node.Root{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 11, - }, - Stmts: []node.Node{ - &stmt.Expression{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 11, - }, - Expr: &binary.Greater{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 10, - }, - Left: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 5, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 5, - }, - Value: "a", - }, - }, - Right: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 8, - EndPos: 10, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 8, - EndPos: 10, - }, - Value: "b", - }, - }, - }, - }, - }, - } - - php7parser := php7.NewParser([]byte(src), "7.4") - php7parser.Parse() - actual := php7parser.GetRootNode() - assert.DeepEqual(t, expected, actual) - - php5parser := php5.NewParser([]byte(src), "5.6") - php5parser.Parse() - actual = php5parser.GetRootNode() - assert.DeepEqual(t, expected, actual) -} - -func TestIdentical(t *testing.T) { - src := `> $b;` - - expected := &node.Root{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 12, - }, - Stmts: []node.Node{ - &stmt.Expression{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 12, - }, - Expr: &binary.ShiftRight{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 11, - }, - Left: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 5, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 5, - }, - Value: "a", - }, - }, - Right: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 9, - EndPos: 11, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 9, - EndPos: 11, - }, - Value: "b", - }, - }, - }, - }, - }, - } - - php7parser := php7.NewParser([]byte(src), "7.4") - php7parser.Parse() - actual := php7parser.GetRootNode() - assert.DeepEqual(t, expected, actual) - - php5parser := php5.NewParser([]byte(src), "5.6") - php5parser.Parse() - actual = php5parser.GetRootNode() - assert.DeepEqual(t, expected, actual) -} - -func TestSmallerOrEqual(t *testing.T) { - src := ` $b;` - - expected := &node.Root{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 13, - }, - Stmts: []node.Node{ - &stmt.Expression{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 13, - }, - Expr: &binary.Spaceship{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 12, - }, - Left: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 5, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 5, - }, - Value: "a", - }, - }, - Right: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 10, - EndPos: 12, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 10, - EndPos: 12, - }, - Value: "b", - }, - }, - }, - }, - }, - } - - php7parser := php7.NewParser([]byte(src), "7.4") - php7parser.Parse() - actual := php7parser.GetRootNode() - assert.DeepEqual(t, expected, actual) -} diff --git a/node/expr/binary/t_freefloating_test.go b/node/expr/binary/t_freefloating_test.go deleted file mode 100644 index 7db5cf4..0000000 --- a/node/expr/binary/t_freefloating_test.go +++ /dev/null @@ -1,117 +0,0 @@ -package binary_test - -import ( - "testing" - - "gotest.tools/assert" - - "github.com/z7zmey/php-parser/freefloating" - "github.com/z7zmey/php-parser/node" - "github.com/z7zmey/php-parser/node/expr/binary" -) - -var expected freefloating.Collection = freefloating.Collection{ - freefloating.Start: []freefloating.String{ - { - StringType: freefloating.WhiteSpaceType, - Value: " ", - Position: nil, - }, - { - StringType: freefloating.CommentType, - Value: "//comment\n", - Position: nil, - }, - }, -} - -var nodes = []node.Node{ - &binary.BitwiseAnd{ - FreeFloating: expected, - }, - &binary.BitwiseOr{ - FreeFloating: expected, - }, - &binary.BitwiseXor{ - FreeFloating: expected, - }, - &binary.BooleanAnd{ - FreeFloating: expected, - }, - &binary.BooleanOr{ - FreeFloating: expected, - }, - &binary.Coalesce{ - FreeFloating: expected, - }, - &binary.Concat{ - FreeFloating: expected, - }, - &binary.Div{ - FreeFloating: expected, - }, - &binary.Equal{ - FreeFloating: expected, - }, - &binary.GreaterOrEqual{ - FreeFloating: expected, - }, - &binary.Greater{ - FreeFloating: expected, - }, - &binary.Identical{ - FreeFloating: expected, - }, - &binary.LogicalAnd{ - FreeFloating: expected, - }, - &binary.LogicalOr{ - FreeFloating: expected, - }, - &binary.LogicalXor{ - FreeFloating: expected, - }, - &binary.Minus{ - FreeFloating: expected, - }, - &binary.Mod{ - FreeFloating: expected, - }, - &binary.Mul{ - FreeFloating: expected, - }, - &binary.NotEqual{ - FreeFloating: expected, - }, - &binary.NotIdentical{ - FreeFloating: expected, - }, - &binary.Plus{ - FreeFloating: expected, - }, - &binary.Pow{ - FreeFloating: expected, - }, - &binary.ShiftLeft{ - FreeFloating: expected, - }, - &binary.ShiftRight{ - FreeFloating: expected, - }, - &binary.SmallerOrEqual{ - FreeFloating: expected, - }, - &binary.Smaller{ - FreeFloating: expected, - }, - &binary.Spaceship{ - FreeFloating: expected, - }, -} - -func TestMeta(t *testing.T) { - for _, n := range nodes { - actual := *n.GetFreeFloating() - assert.DeepEqual(t, expected, actual) - } -} diff --git a/node/expr/binary/t_position_test.go b/node/expr/binary/t_position_test.go deleted file mode 100644 index 079e380..0000000 --- a/node/expr/binary/t_position_test.go +++ /dev/null @@ -1,18 +0,0 @@ -package binary_test - -import ( - "testing" - - "gotest.tools/assert" - - "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() - assert.DeepEqual(t, expected, actual) - } -} diff --git a/node/expr/binary/t_visitor_test.go b/node/expr/binary/t_visitor_test.go deleted file mode 100644 index 7962e23..0000000 --- a/node/expr/binary/t_visitor_test.go +++ /dev/null @@ -1,285 +0,0 @@ -package binary_test - -import ( - "testing" - - "github.com/z7zmey/php-parser/node" - "github.com/z7zmey/php-parser/node/expr" - "github.com/z7zmey/php-parser/node/expr/binary" - "github.com/z7zmey/php-parser/walker" - "gotest.tools/assert" -) - -var nodesToTest = []struct { - node node.Node // node - expectedVisitedKeys []string // visited keys - expectedAttributes map[string]interface{} -}{ - { - &binary.BitwiseAnd{ - Left: &expr.Variable{}, - Right: &expr.Variable{}, - }, - []string{"Left", "Right"}, - nil, - }, - { - &binary.BitwiseOr{ - Left: &expr.Variable{}, - Right: &expr.Variable{}, - }, - []string{"Left", "Right"}, - nil, - }, - { - &binary.BitwiseXor{ - Left: &expr.Variable{}, - Right: &expr.Variable{}, - }, - []string{"Left", "Right"}, - nil, - }, - { - &binary.BooleanAnd{ - Left: &expr.Variable{}, - Right: &expr.Variable{}, - }, - []string{"Left", "Right"}, - nil, - }, - { - &binary.BooleanOr{ - Left: &expr.Variable{}, - Right: &expr.Variable{}, - }, - []string{"Left", "Right"}, - nil, - }, - { - &binary.Coalesce{ - Left: &expr.Variable{}, - Right: &expr.Variable{}, - }, - []string{"Left", "Right"}, - nil, - }, - { - &binary.Concat{ - Left: &expr.Variable{}, - Right: &expr.Variable{}, - }, - []string{"Left", "Right"}, - nil, - }, - { - &binary.Div{ - Left: &expr.Variable{}, - Right: &expr.Variable{}, - }, - []string{"Left", "Right"}, - nil, - }, - { - &binary.Equal{ - Left: &expr.Variable{}, - Right: &expr.Variable{}, - }, - []string{"Left", "Right"}, - nil, - }, - { - &binary.GreaterOrEqual{ - Left: &expr.Variable{}, - Right: &expr.Variable{}, - }, - []string{"Left", "Right"}, - nil, - }, - { - &binary.Greater{ - Left: &expr.Variable{}, - Right: &expr.Variable{}, - }, - []string{"Left", "Right"}, - nil, - }, - { - &binary.Identical{ - Left: &expr.Variable{}, - Right: &expr.Variable{}, - }, - []string{"Left", "Right"}, - nil, - }, - { - &binary.LogicalAnd{ - Left: &expr.Variable{}, - Right: &expr.Variable{}, - }, - []string{"Left", "Right"}, - nil, - }, - { - &binary.LogicalOr{ - Left: &expr.Variable{}, - Right: &expr.Variable{}, - }, - []string{"Left", "Right"}, - nil, - }, - { - &binary.LogicalXor{ - Left: &expr.Variable{}, - Right: &expr.Variable{}, - }, - []string{"Left", "Right"}, - nil, - }, - { - &binary.Minus{ - Left: &expr.Variable{}, - Right: &expr.Variable{}, - }, - []string{"Left", "Right"}, - nil, - }, - { - &binary.Mod{ - Left: &expr.Variable{}, - Right: &expr.Variable{}, - }, - []string{"Left", "Right"}, - nil, - }, - { - &binary.Mul{ - Left: &expr.Variable{}, - Right: &expr.Variable{}, - }, - []string{"Left", "Right"}, - nil, - }, - { - &binary.NotEqual{ - Left: &expr.Variable{}, - Right: &expr.Variable{}, - }, - []string{"Left", "Right"}, - nil, - }, - { - &binary.NotIdentical{ - Left: &expr.Variable{}, - Right: &expr.Variable{}, - }, - []string{"Left", "Right"}, - nil, - }, - { - &binary.Plus{ - Left: &expr.Variable{}, - Right: &expr.Variable{}, - }, - []string{"Left", "Right"}, - nil, - }, - { - &binary.Pow{ - Left: &expr.Variable{}, - Right: &expr.Variable{}, - }, - []string{"Left", "Right"}, - nil, - }, - { - &binary.ShiftLeft{ - Left: &expr.Variable{}, - Right: &expr.Variable{}, - }, - []string{"Left", "Right"}, - nil, - }, - { - &binary.ShiftRight{ - Left: &expr.Variable{}, - Right: &expr.Variable{}, - }, - []string{"Left", "Right"}, - nil, - }, - { - &binary.SmallerOrEqual{ - Left: &expr.Variable{}, - Right: &expr.Variable{}, - }, - []string{"Left", "Right"}, - nil, - }, - { - &binary.Smaller{ - Left: &expr.Variable{}, - Right: &expr.Variable{}, - }, - []string{"Left", "Right"}, - nil, - }, - { - &binary.Spaceship{ - Left: &expr.Variable{}, - Right: &expr.Variable{}, - }, - []string{"Left", "Right"}, - nil, - }, -} - -type visitorMock struct { - visitChildren bool - visitedKeys []string -} - -func (v *visitorMock) EnterNode(n walker.Walkable) bool { return v.visitChildren } -func (v *visitorMock) LeaveNode(n walker.Walkable) {} -func (v *visitorMock) EnterChildNode(key string, w walker.Walkable) { - v.visitedKeys = append(v.visitedKeys, key) -} -func (v *visitorMock) LeaveChildNode(key string, w walker.Walkable) {} -func (v *visitorMock) EnterChildList(key string, w walker.Walkable) { - v.visitedKeys = append(v.visitedKeys, key) -} -func (v *visitorMock) LeaveChildList(key string, w walker.Walkable) {} - -func TestVisitorDisableChildren(t *testing.T) { - for _, tt := range nodesToTest { - v := &visitorMock{false, []string{}} - tt.node.Walk(v) - - expected := []string{} - actual := v.visitedKeys - - assert.DeepEqual(t, expected, actual) - } -} - -func TestVisitor(t *testing.T) { - for _, tt := range nodesToTest { - v := &visitorMock{true, []string{}} - tt.node.Walk(v) - - expected := tt.expectedVisitedKeys - actual := v.visitedKeys - - assert.DeepEqual(t, expected, actual) - } -} - -// test Attributes() - -func TestNameAttributes(t *testing.T) { - for _, tt := range nodesToTest { - expected := tt.expectedAttributes - actual := tt.node.Attributes() - - assert.DeepEqual(t, expected, actual) - } -} diff --git a/node/expr/cast/n_cast_array.go b/node/expr/cast/n_cast_array.go deleted file mode 100644 index f12458b..0000000 --- a/node/expr/cast/n_cast_array.go +++ /dev/null @@ -1,58 +0,0 @@ -package cast - -import ( - "github.com/z7zmey/php-parser/freefloating" - "github.com/z7zmey/php-parser/node" - "github.com/z7zmey/php-parser/position" - "github.com/z7zmey/php-parser/walker" -) - -// Array node -type Array struct { - FreeFloating freefloating.Collection - Position *position.Position - Expr node.Node -} - -// NewArray node constructor -func NewArray(Expr node.Node) *Array { - return &Array{ - FreeFloating: nil, - Expr: Expr, - } -} - -// SetPosition sets node position -func (n *Array) SetPosition(p *position.Position) { - n.Position = p -} - -// GetPosition returns node positions -func (n *Array) GetPosition() *position.Position { - return n.Position -} - -func (n *Array) GetFreeFloating() *freefloating.Collection { - return &n.FreeFloating -} - -// Attributes returns node attributes as map -func (n *Array) Attributes() map[string]interface{} { - return nil -} - -// Walk traverses nodes -// Walk is invoked recursively until v.EnterNode returns true -func (n *Array) Walk(v walker.Visitor) { - if v.EnterNode(n) == false { - return - } - - if n.Expr != nil { - v.EnterChildNode("Expr", n) - n.Expr.Walk(v) - v.LeaveChildNode("Expr", n) - } - - v.LeaveNode(n) -} diff --git a/node/expr/cast/n_cast_bool.go b/node/expr/cast/n_cast_bool.go deleted file mode 100644 index a794df8..0000000 --- a/node/expr/cast/n_cast_bool.go +++ /dev/null @@ -1,58 +0,0 @@ -package cast - -import ( - "github.com/z7zmey/php-parser/freefloating" - "github.com/z7zmey/php-parser/node" - "github.com/z7zmey/php-parser/position" - "github.com/z7zmey/php-parser/walker" -) - -// Bool node -type Bool struct { - FreeFloating freefloating.Collection - Position *position.Position - Expr node.Node -} - -// NewBool node constructor -func NewBool(Expr node.Node) *Bool { - return &Bool{ - FreeFloating: nil, - Expr: Expr, - } -} - -// SetPosition sets node position -func (n *Bool) SetPosition(p *position.Position) { - n.Position = p -} - -// GetPosition returns node positions -func (n *Bool) GetPosition() *position.Position { - return n.Position -} - -func (n *Bool) GetFreeFloating() *freefloating.Collection { - return &n.FreeFloating -} - -// Attributes returns node attributes as map -func (n *Bool) Attributes() map[string]interface{} { - return nil -} - -// Walk traverses nodes -// Walk is invoked recursively until v.EnterNode returns true -func (n *Bool) Walk(v walker.Visitor) { - if v.EnterNode(n) == false { - return - } - - if n.Expr != nil { - v.EnterChildNode("Expr", n) - n.Expr.Walk(v) - v.LeaveChildNode("Expr", n) - } - - v.LeaveNode(n) -} diff --git a/node/expr/cast/n_cast_double.go b/node/expr/cast/n_cast_double.go deleted file mode 100644 index 61dcc43..0000000 --- a/node/expr/cast/n_cast_double.go +++ /dev/null @@ -1,58 +0,0 @@ -package cast - -import ( - "github.com/z7zmey/php-parser/freefloating" - "github.com/z7zmey/php-parser/node" - "github.com/z7zmey/php-parser/position" - "github.com/z7zmey/php-parser/walker" -) - -// Double node -type Double struct { - FreeFloating freefloating.Collection - Position *position.Position - Expr node.Node -} - -// NewDouble node constructor -func NewDouble(Expr node.Node) *Double { - return &Double{ - FreeFloating: nil, - Expr: Expr, - } -} - -// SetPosition sets node position -func (n *Double) SetPosition(p *position.Position) { - n.Position = p -} - -// GetPosition returns node positions -func (n *Double) GetPosition() *position.Position { - return n.Position -} - -func (n *Double) GetFreeFloating() *freefloating.Collection { - return &n.FreeFloating -} - -// Attributes returns node attributes as map -func (n *Double) Attributes() map[string]interface{} { - return nil -} - -// Walk traverses nodes -// Walk is invoked recursively until v.EnterNode returns true -func (n *Double) Walk(v walker.Visitor) { - if v.EnterNode(n) == false { - return - } - - if n.Expr != nil { - v.EnterChildNode("Expr", n) - n.Expr.Walk(v) - v.LeaveChildNode("Expr", n) - } - - v.LeaveNode(n) -} diff --git a/node/expr/cast/n_cast_int.go b/node/expr/cast/n_cast_int.go deleted file mode 100644 index fc3f98d..0000000 --- a/node/expr/cast/n_cast_int.go +++ /dev/null @@ -1,58 +0,0 @@ -package cast - -import ( - "github.com/z7zmey/php-parser/freefloating" - "github.com/z7zmey/php-parser/node" - "github.com/z7zmey/php-parser/position" - "github.com/z7zmey/php-parser/walker" -) - -// Int node -type Int struct { - FreeFloating freefloating.Collection - Position *position.Position - Expr node.Node -} - -// NewInt node constructor -func NewInt(Expr node.Node) *Int { - return &Int{ - FreeFloating: nil, - Expr: Expr, - } -} - -// SetPosition sets node position -func (n *Int) SetPosition(p *position.Position) { - n.Position = p -} - -// GetPosition returns node positions -func (n *Int) GetPosition() *position.Position { - return n.Position -} - -func (n *Int) GetFreeFloating() *freefloating.Collection { - return &n.FreeFloating -} - -// Attributes returns node attributes as map -func (n *Int) Attributes() map[string]interface{} { - return nil -} - -// Walk traverses nodes -// Walk is invoked recursively until v.EnterNode returns true -func (n *Int) Walk(v walker.Visitor) { - if v.EnterNode(n) == false { - return - } - - if n.Expr != nil { - v.EnterChildNode("Expr", n) - n.Expr.Walk(v) - v.LeaveChildNode("Expr", n) - } - - v.LeaveNode(n) -} diff --git a/node/expr/cast/n_cast_object.go b/node/expr/cast/n_cast_object.go deleted file mode 100644 index ea67ce2..0000000 --- a/node/expr/cast/n_cast_object.go +++ /dev/null @@ -1,58 +0,0 @@ -package cast - -import ( - "github.com/z7zmey/php-parser/freefloating" - "github.com/z7zmey/php-parser/node" - "github.com/z7zmey/php-parser/position" - "github.com/z7zmey/php-parser/walker" -) - -// Object node -type Object struct { - FreeFloating freefloating.Collection - Position *position.Position - Expr node.Node -} - -// NewObject node constructor -func NewObject(Expr node.Node) *Object { - return &Object{ - FreeFloating: nil, - Expr: Expr, - } -} - -// SetPosition sets node position -func (n *Object) SetPosition(p *position.Position) { - n.Position = p -} - -// GetPosition returns node positions -func (n *Object) GetPosition() *position.Position { - return n.Position -} - -func (n *Object) GetFreeFloating() *freefloating.Collection { - return &n.FreeFloating -} - -// Attributes returns node attributes as map -func (n *Object) Attributes() map[string]interface{} { - return nil -} - -// Walk traverses nodes -// Walk is invoked recursively until v.EnterNode returns true -func (n *Object) Walk(v walker.Visitor) { - if v.EnterNode(n) == false { - return - } - - if n.Expr != nil { - v.EnterChildNode("Expr", n) - n.Expr.Walk(v) - v.LeaveChildNode("Expr", n) - } - - v.LeaveNode(n) -} diff --git a/node/expr/cast/n_cast_string.go b/node/expr/cast/n_cast_string.go deleted file mode 100644 index 68a09e2..0000000 --- a/node/expr/cast/n_cast_string.go +++ /dev/null @@ -1,58 +0,0 @@ -package cast - -import ( - "github.com/z7zmey/php-parser/freefloating" - "github.com/z7zmey/php-parser/node" - "github.com/z7zmey/php-parser/position" - "github.com/z7zmey/php-parser/walker" -) - -// String node -type String struct { - FreeFloating freefloating.Collection - Position *position.Position - Expr node.Node -} - -// NewString node constructor -func NewString(Expr node.Node) *String { - return &String{ - FreeFloating: nil, - Expr: Expr, - } -} - -// SetPosition sets node position -func (n *String) SetPosition(p *position.Position) { - n.Position = p -} - -// GetPosition returns node positions -func (n *String) GetPosition() *position.Position { - return n.Position -} - -func (n *String) GetFreeFloating() *freefloating.Collection { - return &n.FreeFloating -} - -// Attributes returns node attributes as map -func (n *String) Attributes() map[string]interface{} { - return nil -} - -// Walk traverses nodes -// Walk is invoked recursively until v.EnterNode returns true -func (n *String) Walk(v walker.Visitor) { - if v.EnterNode(n) == false { - return - } - - if n.Expr != nil { - v.EnterChildNode("Expr", n) - n.Expr.Walk(v) - v.LeaveChildNode("Expr", n) - } - - v.LeaveNode(n) -} diff --git a/node/expr/cast/n_cast_unset.go b/node/expr/cast/n_cast_unset.go deleted file mode 100644 index a792daa..0000000 --- a/node/expr/cast/n_cast_unset.go +++ /dev/null @@ -1,58 +0,0 @@ -package cast - -import ( - "github.com/z7zmey/php-parser/freefloating" - "github.com/z7zmey/php-parser/node" - "github.com/z7zmey/php-parser/position" - "github.com/z7zmey/php-parser/walker" -) - -// Unset node -type Unset struct { - FreeFloating freefloating.Collection - Position *position.Position - Expr node.Node -} - -// NewUnset node constructor -func NewUnset(Expr node.Node) *Unset { - return &Unset{ - FreeFloating: nil, - Expr: Expr, - } -} - -// SetPosition sets node position -func (n *Unset) SetPosition(p *position.Position) { - n.Position = p -} - -// GetPosition returns node positions -func (n *Unset) GetPosition() *position.Position { - return n.Position -} - -func (n *Unset) GetFreeFloating() *freefloating.Collection { - return &n.FreeFloating -} - -// Attributes returns node attributes as map -func (n *Unset) Attributes() map[string]interface{} { - return nil -} - -// Walk traverses nodes -// Walk is invoked recursively until v.EnterNode returns true -func (n *Unset) Walk(v walker.Visitor) { - if v.EnterNode(n) == false { - return - } - - if n.Expr != nil { - v.EnterChildNode("Expr", n) - n.Expr.Walk(v) - v.LeaveChildNode("Expr", n) - } - - v.LeaveNode(n) -} diff --git a/node/expr/cast/t_cast_test.go b/node/expr/cast/t_cast_test.go deleted file mode 100644 index 0314800..0000000 --- a/node/expr/cast/t_cast_test.go +++ /dev/null @@ -1,653 +0,0 @@ -package cast_test - -import ( - "testing" - - "gotest.tools/assert" - - "github.com/z7zmey/php-parser/node" - "github.com/z7zmey/php-parser/node/expr" - "github.com/z7zmey/php-parser/node/expr/cast" - "github.com/z7zmey/php-parser/node/stmt" - "github.com/z7zmey/php-parser/php5" - "github.com/z7zmey/php-parser/php7" - "github.com/z7zmey/php-parser/position" -) - -func TestArray(t *testing.T) { - src := `1, &$b,);` - - expected := &node.Root{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 21, - }, - Stmts: []node.Node{ - &stmt.Expression{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 21, - }, - Expr: &expr.Array{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 20, - }, - Items: []node.Node{ - &expr.ArrayItem{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 9, - EndPos: 13, - }, - Key: &scalar.Lnumber{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 9, - EndPos: 10, - }, - Value: "1", - }, - Val: &scalar.Lnumber{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 12, - EndPos: 13, - }, - Value: "1", - }, - }, - &expr.ArrayItem{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 15, - EndPos: 18, - }, - Val: &expr.Reference{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 15, - EndPos: 18, - }, - Variable: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 16, - EndPos: 18, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 16, - EndPos: 18, - }, - Value: "b", - }, - }, - }, - }, - &expr.ArrayItem{}, - }, - }, - }, - }, - } - - php7parser := php7.NewParser([]byte(src), "7.4") - php7parser.Parse() - actual := php7parser.GetRootNode() - assert.DeepEqual(t, expected, actual) - - php5parser := php5.NewParser([]byte(src), "5.6") - php5parser.Parse() - actual = php5parser.GetRootNode() - assert.DeepEqual(t, expected, actual) -} - -func TestArrayItemUnpack(t *testing.T) { - src := ` $a;` - - expected := &node.Root{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 14, - }, - Stmts: []node.Node{ - &stmt.Expression{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 14, - }, - Expr: &expr.ArrowFunction{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 13, - }, - ReturnsRef: false, - Static: false, - PhpDocComment: "", - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 11, - EndPos: 13, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 11, - EndPos: 13, - }, - Value: "a", - }, - }, - }, - }, - }, - } - - php7parser := php7.NewParser([]byte(src), "7.4") - php7parser.Parse() - actual := php7parser.GetRootNode() - assert.DeepEqual(t, expected, actual) -} - -func TestArrowFunctionReturnType(t *testing.T) { - src := ` $a;` - - expected := &node.Root{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 23, - }, - Stmts: []node.Node{ - &stmt.Expression{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 23, - }, - Expr: &expr.ArrowFunction{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 22, - }, - Static: false, - PhpDocComment: "", - ReturnsRef: true, - ReturnType: &name.Name{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 13, - EndPos: 16, - }, - Parts: []node.Node{ - &name.NamePart{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 13, - EndPos: 16, - }, - Value: "foo", - }, - }, - }, - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 20, - EndPos: 22, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 20, - EndPos: 22, - }, - Value: "a", - }, - }, - }, - }, - }, - } - - php7parser := php7.NewParser([]byte(src), "7.4") - php7parser.Parse() - actual := php7parser.GetRootNode() - assert.DeepEqual(t, expected, actual) -} diff --git a/node/expr/t_bitwise_not_test.go b/node/expr/t_bitwise_not_test.go deleted file mode 100644 index a5688b0..0000000 --- a/node/expr/t_bitwise_not_test.go +++ /dev/null @@ -1,73 +0,0 @@ -package expr_test - -import ( - "testing" - - "gotest.tools/assert" - - "github.com/z7zmey/php-parser/node/expr" - "github.com/z7zmey/php-parser/position" - - "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 TestBitwiseNot(t *testing.T) { - src := `foo();` - - expected := &node.Root{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 13, - }, - Stmts: []node.Node{ - &stmt.Expression{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 13, - }, - Expr: &expr.MethodCall{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 12, - }, - Variable: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 5, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 5, - }, - Value: "a", - }, - }, - Method: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 10, - }, - Value: "foo", - }, - ArgumentList: &node.ArgumentList{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 10, - EndPos: 12, - }, - }, - }, - }, - }, - } - - php7parser := php7.NewParser([]byte(src), "7.4") - php7parser.Parse() - actual := php7parser.GetRootNode() - assert.DeepEqual(t, expected, actual) - - php5parser := php5.NewParser([]byte(src), "5.6") - php5parser.Parse() - actual = php5parser.GetRootNode() - assert.DeepEqual(t, expected, actual) -} diff --git a/node/expr/t_new_test.go b/node/expr/t_new_test.go deleted file mode 100644 index d0670f8..0000000 --- a/node/expr/t_new_test.go +++ /dev/null @@ -1,323 +0,0 @@ -package expr_test - -import ( - "testing" - - "gotest.tools/assert" - - "github.com/z7zmey/php-parser/node/name" - "github.com/z7zmey/php-parser/position" - - "github.com/z7zmey/php-parser/node/expr" - - "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 TestNew(t *testing.T) { - src := `foo;` - - expected := &node.Root{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 11, - }, - Stmts: []node.Node{ - &stmt.Expression{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 11, - }, - Expr: &expr.PropertyFetch{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 10, - }, - Variable: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 5, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 5, - }, - Value: "a", - }, - }, - Property: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 10, - }, - Value: "foo", - }, - }, - }, - }, - } - - php7parser := php7.NewParser([]byte(src), "7.4") - php7parser.Parse() - actual := php7parser.GetRootNode() - assert.DeepEqual(t, expected, actual) - - php5parser := php5.NewParser([]byte(src), "5.6") - php5parser.Parse() - actual = php5parser.GetRootNode() - assert.DeepEqual(t, expected, actual) -} diff --git a/node/expr/t_reference_test.go b/node/expr/t_reference_test.go deleted file mode 100644 index 8a9c38e..0000000 --- a/node/expr/t_reference_test.go +++ /dev/null @@ -1,117 +0,0 @@ -package expr_test - -import ( - "testing" - - "gotest.tools/assert" - - "github.com/z7zmey/php-parser/node/expr" - "github.com/z7zmey/php-parser/position" - - "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 TestForeachWithRef(t *testing.T) { - t.Helper() - src := ` &$v) {}` - - expected := &node.Root{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 31, - }, - Stmts: []node.Node{ - &stmt.Foreach{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 31, - }, - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 12, - EndPos: 14, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 12, - EndPos: 14, - }, - Value: "a", - }, - }, - Key: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 18, - EndPos: 20, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 18, - EndPos: 20, - }, - Value: "k", - }, - }, - Variable: &expr.Reference{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 24, - EndPos: 27, - }, - Variable: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 25, - EndPos: 27, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 25, - EndPos: 27, - }, - Value: "v", - }, - }, - }, - Stmt: &stmt.StmtList{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 29, - EndPos: 31, - }, - Stmts: []node.Node{}, - }, - }, - }, - } - - php7parser := php7.NewParser([]byte(src), "7.4") - php7parser.Parse() - actual := php7parser.GetRootNode() - assert.DeepEqual(t, expected, actual) - - php5parser := php5.NewParser([]byte(src), "5.6") - php5parser.Parse() - actual = php5parser.GetRootNode() - assert.DeepEqual(t, expected, actual) -} diff --git a/node/expr/t_shell_exec_test.go b/node/expr/t_shell_exec_test.go deleted file mode 100644 index 4932334..0000000 --- a/node/expr/t_shell_exec_test.go +++ /dev/null @@ -1,86 +0,0 @@ -package expr_test - -import ( - "testing" - - "gotest.tools/assert" - - "github.com/z7zmey/php-parser/node/scalar" - "github.com/z7zmey/php-parser/position" - - "github.com/z7zmey/php-parser/node/expr" - - "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 TestShellExec(t *testing.T) { - src := "1, &$b,];` - - expected := &node.Root{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 16, - }, - Stmts: []node.Node{ - &stmt.Expression{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 16, - }, - Expr: &expr.ShortArray{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 15, - }, - Items: []node.Node{ - &expr.ArrayItem{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 4, - EndPos: 8, - }, - Key: &scalar.Lnumber{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 4, - EndPos: 5, - }, - Value: "1", - }, - Val: &scalar.Lnumber{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 8, - }, - Value: "1", - }, - }, - &expr.ArrayItem{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 10, - EndPos: 13, - }, - Val: &expr.Reference{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 10, - EndPos: 13, - }, - Variable: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 11, - EndPos: 13, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 11, - EndPos: 13, - }, - Value: "b", - }, - }, - }, - }, - &expr.ArrayItem{}, - }, - }, - }, - }, - } - - php7parser := php7.NewParser([]byte(src), "7.4") - php7parser.Parse() - actual := php7parser.GetRootNode() - assert.DeepEqual(t, expected, actual) - - php5parser := php5.NewParser([]byte(src), "5.6") - php5parser.Parse() - actual = php5parser.GetRootNode() - assert.DeepEqual(t, expected, actual) -} diff --git a/node/expr/t_short_list_test.go b/node/expr/t_short_list_test.go deleted file mode 100644 index 76f0bbe..0000000 --- a/node/expr/t_short_list_test.go +++ /dev/null @@ -1,304 +0,0 @@ -package expr_test - -import ( - "testing" - - "gotest.tools/assert" - - "github.com/z7zmey/php-parser/node" - "github.com/z7zmey/php-parser/node/expr" - "github.com/z7zmey/php-parser/node/expr/assign" - "github.com/z7zmey/php-parser/node/stmt" - "github.com/z7zmey/php-parser/php7" - "github.com/z7zmey/php-parser/position" -) - -func TestShortList(t *testing.T) { - src := ` $b;` - - expected := &node.Root{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 18, - }, - Stmts: []node.Node{ - &stmt.Expression{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 18, - }, - Expr: &expr.Yield{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 17, - }, - Key: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 9, - EndPos: 11, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 9, - EndPos: 11, - }, - Value: "a", - }, - }, - Value: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 15, - EndPos: 17, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 15, - EndPos: 17, - }, - Value: "b", - }, - }, - }, - }, - }, - } - - php7parser := php7.NewParser([]byte(src), "7.4") - php7parser.Parse() - actual := php7parser.GetRootNode() - assert.DeepEqual(t, expected, actual) - - php5parser := php5.NewParser([]byte(src), "5.6") - php5parser.Parse() - actual = php5parser.GetRootNode() - assert.DeepEqual(t, expected, actual) -} - -func TestYieldExpr(t *testing.T) { - src := ` 1;` - - expected := &node.Root{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 17, - }, - Stmts: []node.Node{ - &stmt.Expression{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 17, - }, - Expr: &expr.Yield{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 16, - }, - Key: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 9, - EndPos: 11, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 9, - EndPos: 11, - }, - Value: "a", - }, - }, - Value: &scalar.Lnumber{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 15, - EndPos: 16, - }, - Value: "1", - }, - }, - }, - }, - } - - php7parser := php7.NewParser([]byte(src), "7.4") - php7parser.Parse() - actual := php7parser.GetRootNode() - assert.DeepEqual(t, expected, actual) - - php5parser := php5.NewParser([]byte(src), "5.6") - php5parser.Parse() - actual = php5parser.GetRootNode() - assert.DeepEqual(t, expected, actual) -} - -func TestYieldFrom(t *testing.T) { - src := `bar()";` - - expected := &node.Root{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 22, - }, - Stmts: []node.Node{ - &stmt.Expression{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 22, - }, - Expr: &scalar.Encapsed{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 21, - }, - Parts: []node.Node{ - &scalar.EncapsedStringPart{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 4, - EndPos: 9, - }, - Value: "test ", - }, - &expr.PropertyFetch{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 9, - EndPos: 18, - }, - Variable: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 9, - EndPos: 13, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 9, - EndPos: 13, - }, - Value: "foo", - }, - }, - Property: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 15, - EndPos: 18, - }, - Value: "bar", - }, - }, - &scalar.EncapsedStringPart{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 18, - EndPos: 20, - }, - Value: "()", - }, - }, - }, - }, - }, - } - - php7parser := php7.NewParser([]byte(src), "7.4") - php7parser.Parse() - actual := php7parser.GetRootNode() - assert.DeepEqual(t, expected, actual) - - php5parser := php5.NewParser([]byte(src), "5.6") - php5parser.Parse() - actual = php5parser.GetRootNode() - assert.DeepEqual(t, expected, actual) -} - -func TestDollarOpenCurlyBraces(t *testing.T) { - src := `bar()}";` - - expected := &node.Root{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 24, - }, - Stmts: []node.Node{ - &stmt.Expression{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 24, - }, - Expr: &scalar.Encapsed{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 23, - }, - Parts: []node.Node{ - &scalar.EncapsedStringPart{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 4, - EndPos: 9, - }, - Value: "test ", - }, - &expr.MethodCall{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 10, - EndPos: 21, - }, - Variable: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 10, - EndPos: 14, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 10, - EndPos: 14, - }, - Value: "foo", - }, - }, - Method: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 16, - EndPos: 19, - }, - Value: "bar", - }, - ArgumentList: &node.ArgumentList{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 19, - EndPos: 21, - }, - }, - }, - }, - }, - }, - }, - } - - php7parser := php7.NewParser([]byte(src), "7.4") - php7parser.Parse() - actual := php7parser.GetRootNode() - assert.DeepEqual(t, expected, actual) - - php5parser := php5.NewParser([]byte(src), "5.6") - php5parser.Parse() - actual = php5parser.GetRootNode() - assert.DeepEqual(t, expected, actual) -} diff --git a/node/scalar/t_freefloating_test.go b/node/scalar/t_freefloating_test.go deleted file mode 100644 index c30e2ff..0000000 --- a/node/scalar/t_freefloating_test.go +++ /dev/null @@ -1,57 +0,0 @@ -package scalar_test - -import ( - "testing" - - "gotest.tools/assert" - - "github.com/z7zmey/php-parser/freefloating" - "github.com/z7zmey/php-parser/node" - "github.com/z7zmey/php-parser/node/scalar" -) - -var expected freefloating.Collection = freefloating.Collection{ - freefloating.Start: []freefloating.String{ - { - StringType: freefloating.WhiteSpaceType, - Value: " ", - Position: nil, - }, - { - StringType: freefloating.CommentType, - Value: "//comment\n", - Position: nil, - }, - }, -} - -var nodes = []node.Node{ - &scalar.Dnumber{ - FreeFloating: expected, - }, - &scalar.EncapsedStringPart{ - FreeFloating: expected, - }, - &scalar.Encapsed{ - FreeFloating: expected, - }, - &scalar.Heredoc{ - FreeFloating: expected, - }, - &scalar.Lnumber{ - FreeFloating: expected, - }, - &scalar.MagicConstant{ - FreeFloating: expected, - }, - &scalar.String{ - FreeFloating: expected, - }, -} - -func TestMeta(t *testing.T) { - for _, n := range nodes { - actual := *n.GetFreeFloating() - assert.DeepEqual(t, expected, actual) - } -} diff --git a/node/scalar/t_heredoc_test.go b/node/scalar/t_heredoc_test.go deleted file mode 100644 index ae0ce1f..0000000 --- a/node/scalar/t_heredoc_test.go +++ /dev/null @@ -1,336 +0,0 @@ -package scalar_test - -import ( - "testing" - - "gotest.tools/assert" - - "github.com/z7zmey/php-parser/node/expr" - "github.com/z7zmey/php-parser/position" - - "github.com/z7zmey/php-parser/node" - "github.com/z7zmey/php-parser/node/scalar" - "github.com/z7zmey/php-parser/node/stmt" - "github.com/z7zmey/php-parser/php5" - "github.com/z7zmey/php-parser/php7" -) - -func TestHeredocSimpleLabel(t *testing.T) { - src := ` $v) {}` - - expected := &node.Root{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 30, - }, - Stmts: []node.Node{ - &stmt.Foreach{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 30, - }, - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 12, - EndPos: 14, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 12, - EndPos: 14, - }, - Value: "a", - }, - }, - Key: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 18, - EndPos: 20, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 18, - EndPos: 20, - }, - Value: "k", - }, - }, - Variable: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 24, - EndPos: 26, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 24, - EndPos: 26, - }, - Value: "v", - }, - }, - Stmt: &stmt.StmtList{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 28, - EndPos: 30, - }, - Stmts: []node.Node{}, - }, - }, - }, - } - - php7parser := php7.NewParser([]byte(src), "7.4") - php7parser.Parse() - actual := php7parser.GetRootNode() - assert.DeepEqual(t, expected, actual) - - php5parser := php5.NewParser([]byte(src), "5.6") - php5parser.Parse() - actual = php5parser.GetRootNode() - assert.DeepEqual(t, expected, actual) -} - -func TestForeachExprWithKey(t *testing.T) { - src := ` $v) {}` - - expected := &node.Root{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 30, - }, - Stmts: []node.Node{ - &stmt.Foreach{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 30, - }, - Expr: &expr.ShortArray{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 12, - EndPos: 14, - }, - Items: []node.Node{}, - }, - Key: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 18, - EndPos: 20, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 18, - EndPos: 20, - }, - Value: "k", - }, - }, - Variable: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 24, - EndPos: 26, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 24, - EndPos: 26, - }, - Value: "v", - }, - }, - Stmt: &stmt.StmtList{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 28, - EndPos: 30, - }, - Stmts: []node.Node{}, - }, - }, - }, - } - - php7parser := php7.NewParser([]byte(src), "7.4") - php7parser.Parse() - actual := php7parser.GetRootNode() - assert.DeepEqual(t, expected, actual) - - php5parser := php5.NewParser([]byte(src), "5.6") - php5parser.Parse() - actual = php5parser.GetRootNode() - assert.DeepEqual(t, expected, actual) -} - -func TestForeachWithRef(t *testing.T) { - src := ` &$v) {}` - - expected := &node.Root{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 31, - }, - Stmts: []node.Node{ - &stmt.Foreach{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 31, - }, - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 12, - EndPos: 14, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 12, - EndPos: 14, - }, - Value: "a", - }, - }, - Key: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 18, - EndPos: 20, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 18, - EndPos: 20, - }, - Value: "k", - }, - }, - Variable: &expr.Reference{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 24, - EndPos: 27, - }, - Variable: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 25, - EndPos: 27, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 25, - EndPos: 27, - }, - Value: "v", - }, - }, - }, - Stmt: &stmt.StmtList{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 29, - EndPos: 31, - }, - Stmts: []node.Node{}, - }, - }, - }, - } - - php7parser := php7.NewParser([]byte(src), "7.4") - php7parser.Parse() - actual := php7parser.GetRootNode() - assert.DeepEqual(t, expected, actual) - - php5parser := php5.NewParser([]byte(src), "5.6") - php5parser.Parse() - actual = php5parser.GetRootNode() - assert.DeepEqual(t, expected, actual) -} - -func TestForeachWithList(t *testing.T) { - src := ` list($v)) {}` - - expected := &node.Root{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 36, - }, - Stmts: []node.Node{ - &stmt.Foreach{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 36, - }, - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 12, - EndPos: 14, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 12, - EndPos: 14, - }, - Value: "a", - }, - }, - Key: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 18, - EndPos: 20, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 18, - EndPos: 20, - }, - Value: "k", - }, - }, - Variable: &expr.List{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 24, - EndPos: 32, - }, - Items: []node.Node{ - &expr.ArrayItem{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 29, - EndPos: 31, - }, - Val: &expr.Variable{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 29, - EndPos: 31, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 29, - EndPos: 31, - }, - Value: "v", - }, - }, - }, - }, - }, - Stmt: &stmt.StmtList{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 34, - EndPos: 36, - }, - Stmts: []node.Node{}, - }, - }, - }, - } - - php7parser := php7.NewParser([]byte(src), "7.4") - php7parser.Parse() - actual := php7parser.GetRootNode() - assert.DeepEqual(t, expected, actual) - - php5parser := php5.NewParser([]byte(src), "5.6") - php5parser.Parse() - actual = php5parser.GetRootNode() - assert.DeepEqual(t, expected, actual) -} diff --git a/node/stmt/t_freefloating_test.go b/node/stmt/t_freefloating_test.go deleted file mode 100644 index 182c5d9..0000000 --- a/node/stmt/t_freefloating_test.go +++ /dev/null @@ -1,216 +0,0 @@ -package stmt_test - -import ( - "testing" - - "gotest.tools/assert" - - "github.com/z7zmey/php-parser/freefloating" - "github.com/z7zmey/php-parser/node" - "github.com/z7zmey/php-parser/node/stmt" -) - -var expected freefloating.Collection = freefloating.Collection{ - freefloating.Start: []freefloating.String{ - { - StringType: freefloating.WhiteSpaceType, - Value: " ", - Position: nil, - }, - { - StringType: freefloating.CommentType, - Value: "//comment\n", - Position: nil, - }, - }, -} - -var nodes = []node.Node{ - &stmt.AltElseIf{ - FreeFloating: expected, - }, - &stmt.AltElse{ - FreeFloating: expected, - }, - &stmt.AltFor{ - FreeFloating: expected, - }, - &stmt.AltForeach{ - FreeFloating: expected, - }, - &stmt.AltIf{ - FreeFloating: expected, - }, - &stmt.AltSwitch{ - FreeFloating: expected, - }, - &stmt.AltWhile{ - FreeFloating: expected, - }, - &stmt.Break{ - FreeFloating: expected, - }, - &stmt.CaseList{ - FreeFloating: expected, - }, - &stmt.Case{ - FreeFloating: expected, - }, - &stmt.Catch{ - FreeFloating: expected, - }, - &stmt.ClassConstList{ - FreeFloating: expected, - }, - &stmt.ClassExtends{ - FreeFloating: expected, - }, - &stmt.ClassImplements{ - FreeFloating: expected, - }, - &stmt.ClassMethod{ - FreeFloating: expected, - }, - &stmt.Class{ - FreeFloating: expected, - }, - &stmt.ConstList{ - FreeFloating: expected, - }, - &stmt.Constant{ - FreeFloating: expected, - }, - &stmt.Continue{ - FreeFloating: expected, - }, - &stmt.Declare{ - FreeFloating: expected, - }, - &stmt.Default{ - FreeFloating: expected, - }, - &stmt.Do{ - FreeFloating: expected, - }, - &stmt.Echo{ - FreeFloating: expected, - }, - &stmt.ElseIf{ - FreeFloating: expected, - }, - &stmt.Else{ - FreeFloating: expected, - }, - &stmt.Expression{ - FreeFloating: expected, - }, - &stmt.Finally{ - FreeFloating: expected, - }, - &stmt.For{ - FreeFloating: expected, - }, - &stmt.Foreach{ - FreeFloating: expected, - }, - &stmt.Function{ - FreeFloating: expected, - }, - &stmt.Global{ - FreeFloating: expected, - }, - &stmt.Goto{ - FreeFloating: expected, - }, - &stmt.GroupUse{ - FreeFloating: expected, - }, - &stmt.HaltCompiler{ - FreeFloating: expected, - }, - &stmt.If{ - FreeFloating: expected, - }, - &stmt.InlineHtml{ - FreeFloating: expected, - }, - &stmt.InterfaceExtends{ - FreeFloating: expected, - }, - &stmt.Interface{ - FreeFloating: expected, - }, - &stmt.Label{ - FreeFloating: expected, - }, - &stmt.Namespace{ - FreeFloating: expected, - }, - &stmt.Nop{ - FreeFloating: expected, - }, - &stmt.PropertyList{ - FreeFloating: expected, - }, - &stmt.Property{ - FreeFloating: expected, - }, - &stmt.Return{ - FreeFloating: expected, - }, - &stmt.StaticVar{ - FreeFloating: expected, - }, - &stmt.Static{ - FreeFloating: expected, - }, - &stmt.StmtList{ - FreeFloating: expected, - }, - &stmt.Switch{ - FreeFloating: expected, - }, - &stmt.Throw{ - FreeFloating: expected, - }, - &stmt.TraitAdaptationList{ - FreeFloating: expected, - }, - &stmt.TraitMethodRef{ - FreeFloating: expected, - }, - &stmt.TraitUseAlias{ - FreeFloating: expected, - }, - &stmt.TraitUsePrecedence{ - FreeFloating: expected, - }, - &stmt.TraitUse{ - FreeFloating: expected, - }, - &stmt.Trait{ - FreeFloating: expected, - }, - &stmt.Try{ - FreeFloating: expected, - }, - &stmt.Unset{ - FreeFloating: expected, - }, - &stmt.UseList{ - FreeFloating: expected, - }, - &stmt.Use{ - FreeFloating: expected, - }, - &stmt.While{ - FreeFloating: expected, - }, -} - -func TestMeta(t *testing.T) { - for _, n := range nodes { - actual := *n.GetFreeFloating() - assert.DeepEqual(t, expected, actual) - } -} diff --git a/node/stmt/t_function_test.go b/node/stmt/t_function_test.go deleted file mode 100644 index 4b8fbe3..0000000 --- a/node/stmt/t_function_test.go +++ /dev/null @@ -1,383 +0,0 @@ -package stmt_test - -import ( - "testing" - - "gotest.tools/assert" - - "github.com/z7zmey/php-parser/node/name" - "github.com/z7zmey/php-parser/node/scalar" - "github.com/z7zmey/php-parser/position" - - "github.com/z7zmey/php-parser/node" - "github.com/z7zmey/php-parser/node/expr" - "github.com/z7zmey/php-parser/node/stmt" - "github.com/z7zmey/php-parser/php5" - "github.com/z7zmey/php-parser/php7" -) - -func TestSimpleFunction(t *testing.T) { - src := `
` - - expected := &node.Root{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 17, - }, - Stmts: []node.Node{ - &stmt.Nop{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 3, - EndPos: 5, - }, - }, - &stmt.InlineHtml{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 5, - EndPos: 17, - }, - Value: "
", - }, - }, - } - - php7parser := php7.NewParser([]byte(src), "7.4") - php7parser.Parse() - actual := php7parser.GetRootNode() - assert.DeepEqual(t, expected, actual) - - php5parser := php5.NewParser([]byte(src), "5.6") - php5parser.Parse() - actual = php5parser.GetRootNode() - assert.DeepEqual(t, expected, actual) -} diff --git a/node/stmt/t_interface_test.go b/node/stmt/t_interface_test.go deleted file mode 100644 index 5b018ec..0000000 --- a/node/stmt/t_interface_test.go +++ /dev/null @@ -1,224 +0,0 @@ -package stmt_test - -import ( - "testing" - - "gotest.tools/assert" - - "github.com/z7zmey/php-parser/node/name" - "github.com/z7zmey/php-parser/position" - - "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 TestInterface(t *testing.T) { - src := `bar($a, ...$b); - foo::bar($a, ...$b); - $foo::bar($a, ...$b); - new foo($a, ...$b); - /** anonymous class */ - new class ($a, ...$b) {}; - ` - - expected := &node.Root{ - Position: &position.Position{ - StartLine: 2, - EndLine: 9, - StartPos: 6, - EndPos: 186, - }, - Stmts: []node.Node{ - &stmt.Expression{ - Position: &position.Position{ - StartLine: 2, - EndLine: 2, - StartPos: 6, - EndPos: 21, - }, - Expr: &expr.FunctionCall{ - Position: &position.Position{ - StartLine: 2, - EndLine: 2, - StartPos: 6, - EndPos: 20, - }, - Function: &name.Name{ - Position: &position.Position{ - StartLine: 2, - EndLine: 2, - StartPos: 6, - EndPos: 9, - }, - Parts: []node.Node{ - &name.NamePart{ - Position: &position.Position{ - StartLine: 2, - EndLine: 2, - StartPos: 6, - EndPos: 9, - }, - Value: "foo", - }, - }, - }, - ArgumentList: &node.ArgumentList{ - Position: &position.Position{ - StartLine: 2, - EndLine: 2, - StartPos: 9, - EndPos: 20, - }, - Arguments: []node.Node{ - &node.Argument{ - Position: &position.Position{ - StartLine: 2, - EndLine: 2, - StartPos: 10, - EndPos: 12, - }, - Variadic: false, - IsReference: false, - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 2, - EndLine: 2, - StartPos: 10, - EndPos: 12, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 2, - EndLine: 2, - StartPos: 10, - EndPos: 12, - }, - Value: "a", - }, - }, - }, - &node.Argument{ - Position: &position.Position{ - StartLine: 2, - EndLine: 2, - StartPos: 14, - EndPos: 19, - }, - Variadic: true, - IsReference: false, - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 2, - EndLine: 2, - StartPos: 17, - EndPos: 19, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 2, - EndLine: 2, - StartPos: 17, - EndPos: 19, - }, - Value: "b", - }, - }, - }, - }, - }, - }, - }, - &stmt.Expression{ - Position: &position.Position{ - StartLine: 3, - EndLine: 3, - StartPos: 24, - EndPos: 40, - }, - Expr: &expr.FunctionCall{ - Position: &position.Position{ - StartLine: 3, - EndLine: 3, - StartPos: 24, - EndPos: 39, - }, - Function: &expr.Variable{ - Position: &position.Position{ - StartLine: 3, - EndLine: 3, - StartPos: 24, - EndPos: 28, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 3, - EndLine: 3, - StartPos: 24, - EndPos: 28, - }, - Value: "foo", - }, - }, - ArgumentList: &node.ArgumentList{ - Position: &position.Position{ - StartLine: 3, - EndLine: 3, - StartPos: 28, - EndPos: 39, - }, - Arguments: []node.Node{ - &node.Argument{ - Position: &position.Position{ - StartLine: 3, - EndLine: 3, - StartPos: 29, - EndPos: 31, - }, - Variadic: false, - IsReference: false, - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 3, - EndLine: 3, - StartPos: 29, - EndPos: 31, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 3, - EndLine: 3, - StartPos: 29, - EndPos: 31, - }, - Value: "a", - }, - }, - }, - &node.Argument{ - Position: &position.Position{ - StartLine: 3, - EndLine: 3, - StartPos: 33, - EndPos: 38, - }, - Variadic: true, - IsReference: false, - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 3, - EndLine: 3, - StartPos: 36, - EndPos: 38, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 3, - EndLine: 3, - StartPos: 36, - EndPos: 38, - }, - Value: "b", - }, - }, - }, - }, - }, - }, - }, - &stmt.Expression{ - Position: &position.Position{ - StartLine: 4, - EndLine: 4, - StartPos: 43, - EndPos: 64, - }, - Expr: &expr.MethodCall{ - Position: &position.Position{ - StartLine: 4, - EndLine: 4, - StartPos: 43, - EndPos: 63, - }, - Variable: &expr.Variable{ - Position: &position.Position{ - StartLine: 4, - EndLine: 4, - StartPos: 43, - EndPos: 47, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 4, - EndLine: 4, - StartPos: 43, - EndPos: 47, - }, - Value: "foo", - }, - }, - Method: &node.Identifier{ - Position: &position.Position{ - StartLine: 4, - EndLine: 4, - StartPos: 49, - EndPos: 52, - }, - Value: "bar", - }, - ArgumentList: &node.ArgumentList{ - Position: &position.Position{ - StartLine: 4, - EndLine: 4, - StartPos: 52, - EndPos: 63, - }, - Arguments: []node.Node{ - &node.Argument{ - Position: &position.Position{ - StartLine: 4, - EndLine: 4, - StartPos: 53, - EndPos: 55, - }, - IsReference: false, - Variadic: false, - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 4, - EndLine: 4, - StartPos: 53, - EndPos: 55, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 4, - EndLine: 4, - StartPos: 53, - EndPos: 55, - }, - Value: "a", - }, - }, - }, - &node.Argument{ - Position: &position.Position{ - StartLine: 4, - EndLine: 4, - StartPos: 57, - EndPos: 62, - }, - Variadic: true, - IsReference: false, - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 4, - EndLine: 4, - StartPos: 60, - EndPos: 62, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 4, - EndLine: 4, - StartPos: 60, - EndPos: 62, - }, - Value: "b", - }, - }, - }, - }, - }, - }, - }, - &stmt.Expression{ - Position: &position.Position{ - StartLine: 5, - EndLine: 5, - StartPos: 67, - EndPos: 87, - }, - Expr: &expr.StaticCall{ - Position: &position.Position{ - StartLine: 5, - EndLine: 5, - StartPos: 67, - EndPos: 86, - }, - Class: &name.Name{ - Position: &position.Position{ - StartLine: 5, - EndLine: 5, - StartPos: 67, - EndPos: 70, - }, - Parts: []node.Node{ - &name.NamePart{ - Position: &position.Position{ - StartLine: 5, - EndLine: 5, - StartPos: 67, - EndPos: 70, - }, - Value: "foo", - }, - }, - }, - Call: &node.Identifier{ - Position: &position.Position{ - StartLine: 5, - EndLine: 5, - StartPos: 72, - EndPos: 75, - }, - Value: "bar", - }, - ArgumentList: &node.ArgumentList{ - Position: &position.Position{ - StartLine: 5, - EndLine: 5, - StartPos: 75, - EndPos: 86, - }, - Arguments: []node.Node{ - &node.Argument{ - Position: &position.Position{ - StartLine: 5, - EndLine: 5, - StartPos: 76, - EndPos: 78, - }, - Variadic: false, - IsReference: false, - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 5, - EndLine: 5, - StartPos: 76, - EndPos: 78, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 5, - EndLine: 5, - StartPos: 76, - EndPos: 78, - }, - Value: "a", - }, - }, - }, - &node.Argument{ - Position: &position.Position{ - StartLine: 5, - EndLine: 5, - StartPos: 80, - EndPos: 85, - }, - Variadic: true, - IsReference: false, - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 5, - EndLine: 5, - StartPos: 83, - EndPos: 85, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 5, - EndLine: 5, - StartPos: 83, - EndPos: 85, - }, - Value: "b", - }, - }, - }, - }, - }, - }, - }, - &stmt.Expression{ - Position: &position.Position{ - StartLine: 6, - EndLine: 6, - StartPos: 90, - EndPos: 111, - }, - Expr: &expr.StaticCall{ - Position: &position.Position{ - StartLine: 6, - EndLine: 6, - StartPos: 90, - EndPos: 110, - }, - Class: &expr.Variable{ - Position: &position.Position{ - StartLine: 6, - EndLine: 6, - StartPos: 90, - EndPos: 94, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 6, - EndLine: 6, - StartPos: 90, - EndPos: 94, - }, - Value: "foo", - }, - }, - Call: &node.Identifier{ - Position: &position.Position{ - StartLine: 6, - EndLine: 6, - StartPos: 96, - EndPos: 99, - }, - Value: "bar", - }, - ArgumentList: &node.ArgumentList{ - Position: &position.Position{ - StartLine: 6, - EndLine: 6, - StartPos: 99, - EndPos: 110, - }, - Arguments: []node.Node{ - &node.Argument{ - Position: &position.Position{ - StartLine: 6, - EndLine: 6, - StartPos: 100, - EndPos: 102, - }, - Variadic: false, - IsReference: false, - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 6, - EndLine: 6, - StartPos: 100, - EndPos: 102, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 6, - EndLine: 6, - StartPos: 100, - EndPos: 102, - }, - Value: "a", - }, - }, - }, - &node.Argument{ - Position: &position.Position{ - StartLine: 6, - EndLine: 6, - StartPos: 104, - EndPos: 109, - }, - Variadic: true, - IsReference: false, - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 6, - EndLine: 6, - StartPos: 107, - EndPos: 109, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 6, - EndLine: 6, - StartPos: 107, - EndPos: 109, - }, - Value: "b", - }, - }, - }, - }, - }, - }, - }, - &stmt.Expression{ - Position: &position.Position{ - StartLine: 7, - EndLine: 7, - StartPos: 114, - EndPos: 133, - }, - Expr: &expr.New{ - Position: &position.Position{ - StartLine: 7, - EndLine: 7, - StartPos: 114, - EndPos: 132, - }, - Class: &name.Name{ - Position: &position.Position{ - StartLine: 7, - EndLine: 7, - StartPos: 118, - EndPos: 121, - }, - Parts: []node.Node{ - &name.NamePart{ - Position: &position.Position{ - StartLine: 7, - EndLine: 7, - StartPos: 118, - EndPos: 121, - }, - Value: "foo", - }, - }, - }, - ArgumentList: &node.ArgumentList{ - Position: &position.Position{ - StartLine: 7, - EndLine: 7, - StartPos: 121, - EndPos: 132, - }, - Arguments: []node.Node{ - &node.Argument{ - Position: &position.Position{ - StartLine: 7, - EndLine: 7, - StartPos: 122, - EndPos: 124, - }, - Variadic: false, - IsReference: false, - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 7, - EndLine: 7, - StartPos: 122, - EndPos: 124, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 7, - EndLine: 7, - StartPos: 122, - EndPos: 124, - }, - Value: "a", - }, - }, - }, - &node.Argument{ - Position: &position.Position{ - StartLine: 7, - EndLine: 7, - StartPos: 126, - EndPos: 131, - }, - Variadic: true, - IsReference: false, - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 7, - EndLine: 7, - StartPos: 129, - EndPos: 131, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 7, - EndLine: 7, - StartPos: 129, - EndPos: 131, - }, - Value: "b", - }, - }, - }, - }, - }, - }, - }, - &stmt.Expression{ - Position: &position.Position{ - StartLine: 9, - EndLine: 9, - StartPos: 161, - EndPos: 186, - }, - Expr: &expr.New{ - Position: &position.Position{ - StartLine: 9, - EndLine: 9, - StartPos: 161, - EndPos: 185, - }, - Class: &stmt.Class{ - Position: &position.Position{ - StartLine: 9, - EndLine: 9, - StartPos: 165, - EndPos: 185, - }, - PhpDocComment: "/** anonymous class */", - ArgumentList: &node.ArgumentList{ - Position: &position.Position{ - StartLine: 9, - EndLine: 9, - StartPos: 171, - EndPos: 182, - }, - Arguments: []node.Node{ - &node.Argument{ - Position: &position.Position{ - StartLine: 9, - EndLine: 9, - StartPos: 172, - EndPos: 174, - }, - Variadic: false, - IsReference: false, - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 9, - EndLine: 9, - StartPos: 172, - EndPos: 174, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 9, - EndLine: 9, - StartPos: 172, - EndPos: 174, - }, - Value: "a", - }, - }, - }, - &node.Argument{ - Position: &position.Position{ - StartLine: 9, - EndLine: 9, - StartPos: 176, - EndPos: 181, - }, - Variadic: true, - IsReference: false, - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 9, - EndLine: 9, - StartPos: 179, - EndPos: 181, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 9, - EndLine: 9, - StartPos: 179, - EndPos: 181, - }, - Value: "b", - }, - }, - }, - }, - }, - Stmts: []node.Node{}, - }, - }, - }, - }, - } - - php7parser := php7.NewParser([]byte(src), "7.4") - php7parser.Parse() - actual := php7parser.GetRootNode() - assert.DeepEqual(t, expected, actual) -} - -func TestPhp5ArgumentNode(t *testing.T) { - src := `bar($a, ...$b); - foo::bar($a, ...$b); - $foo::bar($a, ...$b); - new foo($a, ...$b); - ` - - expected := &node.Root{ - Position: &position.Position{ - StartLine: 2, - EndLine: 7, - StartPos: 6, - EndPos: 133, - }, - Stmts: []node.Node{ - &stmt.Expression{ - Position: &position.Position{ - StartLine: 2, - EndLine: 2, - StartPos: 6, - EndPos: 21, - }, - Expr: &expr.FunctionCall{ - Position: &position.Position{ - StartLine: 2, - EndLine: 2, - StartPos: 6, - EndPos: 20, - }, - Function: &name.Name{ - Position: &position.Position{ - StartLine: 2, - EndLine: 2, - StartPos: 6, - EndPos: 9, - }, - Parts: []node.Node{ - &name.NamePart{ - Position: &position.Position{ - StartLine: 2, - EndLine: 2, - StartPos: 6, - EndPos: 9, - }, - Value: "foo", - }, - }, - }, - ArgumentList: &node.ArgumentList{ - Position: &position.Position{ - StartLine: 2, - EndLine: 2, - StartPos: 9, - EndPos: 20, - }, - Arguments: []node.Node{ - &node.Argument{ - Position: &position.Position{ - StartLine: 2, - EndLine: 2, - StartPos: 10, - EndPos: 12, - }, - Variadic: false, - IsReference: false, - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 2, - EndLine: 2, - StartPos: 10, - EndPos: 12, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 2, - EndLine: 2, - StartPos: 10, - EndPos: 12, - }, - Value: "a", - }, - }, - }, - &node.Argument{ - Position: &position.Position{ - StartLine: 2, - EndLine: 2, - StartPos: 14, - EndPos: 19, - }, - Variadic: true, - IsReference: false, - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 2, - EndLine: 2, - StartPos: 17, - EndPos: 19, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 2, - EndLine: 2, - StartPos: 17, - EndPos: 19, - }, - Value: "b", - }, - }, - }, - }, - }, - }, - }, - &stmt.Expression{ - Position: &position.Position{ - StartLine: 3, - EndLine: 3, - StartPos: 24, - EndPos: 40, - }, - Expr: &expr.FunctionCall{ - Position: &position.Position{ - StartLine: 3, - EndLine: 3, - StartPos: 24, - EndPos: 39, - }, - Function: &expr.Variable{ - Position: &position.Position{ - StartLine: 3, - EndLine: 3, - StartPos: 24, - EndPos: 28, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 3, - EndLine: 3, - StartPos: 24, - EndPos: 28, - }, - Value: "foo", - }, - }, - ArgumentList: &node.ArgumentList{ - Position: &position.Position{ - StartLine: 3, - EndLine: 3, - StartPos: 28, - EndPos: 39, - }, - Arguments: []node.Node{ - &node.Argument{ - Position: &position.Position{ - StartLine: 3, - EndLine: 3, - StartPos: 29, - EndPos: 31, - }, - Variadic: false, - IsReference: false, - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 3, - EndLine: 3, - StartPos: 29, - EndPos: 31, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 3, - EndLine: 3, - StartPos: 29, - EndPos: 31, - }, - Value: "a", - }, - }, - }, - &node.Argument{ - Position: &position.Position{ - StartLine: 3, - EndLine: 3, - StartPos: 33, - EndPos: 38, - }, - Variadic: true, - IsReference: false, - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 3, - EndLine: 3, - StartPos: 36, - EndPos: 38, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 3, - EndLine: 3, - StartPos: 36, - EndPos: 38, - }, - Value: "b", - }, - }, - }, - }, - }, - }, - }, - &stmt.Expression{ - Position: &position.Position{ - StartLine: 4, - EndLine: 4, - StartPos: 43, - EndPos: 64, - }, - Expr: &expr.MethodCall{ - Position: &position.Position{ - StartLine: 4, - EndLine: 4, - StartPos: 43, - EndPos: 63, - }, - Variable: &expr.Variable{ - Position: &position.Position{ - StartLine: 4, - EndLine: 4, - StartPos: 43, - EndPos: 47, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 4, - EndLine: 4, - StartPos: 43, - EndPos: 47, - }, - Value: "foo", - }, - }, - Method: &node.Identifier{ - Position: &position.Position{ - StartLine: 4, - EndLine: 4, - StartPos: 49, - EndPos: 52, - }, - Value: "bar", - }, - ArgumentList: &node.ArgumentList{ - Position: &position.Position{ - StartLine: 4, - EndLine: 4, - StartPos: 52, - EndPos: 63, - }, - Arguments: []node.Node{ - &node.Argument{ - Position: &position.Position{ - StartLine: 4, - EndLine: 4, - StartPos: 53, - EndPos: 55, - }, - Variadic: false, - IsReference: false, - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 4, - EndLine: 4, - StartPos: 53, - EndPos: 55, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 4, - EndLine: 4, - StartPos: 53, - EndPos: 55, - }, - Value: "a", - }, - }, - }, - &node.Argument{ - Position: &position.Position{ - StartLine: 4, - EndLine: 4, - StartPos: 57, - EndPos: 62, - }, - IsReference: false, - Variadic: true, - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 4, - EndLine: 4, - StartPos: 60, - EndPos: 62, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 4, - EndLine: 4, - StartPos: 60, - EndPos: 62, - }, - Value: "b", - }, - }, - }, - }, - }, - }, - }, - &stmt.Expression{ - Position: &position.Position{ - StartLine: 5, - EndLine: 5, - StartPos: 67, - EndPos: 87, - }, - Expr: &expr.StaticCall{ - Position: &position.Position{ - StartLine: 5, - EndLine: 5, - StartPos: 67, - EndPos: 86, - }, - Class: &name.Name{ - Position: &position.Position{ - StartLine: 5, - EndLine: 5, - StartPos: 67, - EndPos: 70, - }, - Parts: []node.Node{ - &name.NamePart{ - Position: &position.Position{ - StartLine: 5, - EndLine: 5, - StartPos: 67, - EndPos: 70, - }, - Value: "foo", - }, - }, - }, - Call: &node.Identifier{ - Position: &position.Position{ - StartLine: 5, - EndLine: 5, - StartPos: 72, - EndPos: 75, - }, - Value: "bar", - }, - ArgumentList: &node.ArgumentList{ - Position: &position.Position{ - StartLine: 5, - EndLine: 5, - StartPos: 75, - EndPos: 86, - }, - Arguments: []node.Node{ - &node.Argument{ - Position: &position.Position{ - StartLine: 5, - EndLine: 5, - StartPos: 76, - EndPos: 78, - }, - Variadic: false, - IsReference: false, - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 5, - EndLine: 5, - StartPos: 76, - EndPos: 78, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 5, - EndLine: 5, - StartPos: 76, - EndPos: 78, - }, - Value: "a", - }, - }, - }, - &node.Argument{ - Position: &position.Position{ - StartLine: 5, - EndLine: 5, - StartPos: 80, - EndPos: 85, - }, - Variadic: true, - IsReference: false, - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 5, - EndLine: 5, - StartPos: 83, - EndPos: 85, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 5, - EndLine: 5, - StartPos: 83, - EndPos: 85, - }, - Value: "b", - }, - }, - }, - }, - }, - }, - }, - &stmt.Expression{ - Position: &position.Position{ - StartLine: 6, - EndLine: 6, - StartPos: 90, - EndPos: 111, - }, - Expr: &expr.StaticCall{ - Position: &position.Position{ - StartLine: 6, - EndLine: 6, - StartPos: 90, - EndPos: 110, - }, - Class: &expr.Variable{ - Position: &position.Position{ - StartLine: 6, - EndLine: 6, - StartPos: 90, - EndPos: 94, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 6, - EndLine: 6, - StartPos: 90, - EndPos: 94, - }, - Value: "foo", - }, - }, - Call: &node.Identifier{ - Position: &position.Position{ - StartLine: 6, - EndLine: 6, - StartPos: 96, - EndPos: 99, - }, - Value: "bar", - }, - ArgumentList: &node.ArgumentList{ - Position: &position.Position{ - StartLine: 6, - EndLine: 6, - StartPos: 99, - EndPos: 110, - }, - Arguments: []node.Node{ - &node.Argument{ - Position: &position.Position{ - StartLine: 6, - EndLine: 6, - StartPos: 100, - EndPos: 102, - }, - Variadic: false, - IsReference: false, - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 6, - EndLine: 6, - StartPos: 100, - EndPos: 102, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 6, - EndLine: 6, - StartPos: 100, - EndPos: 102, - }, - Value: "a", - }, - }, - }, - &node.Argument{ - Position: &position.Position{ - StartLine: 6, - EndLine: 6, - StartPos: 104, - EndPos: 109, - }, - Variadic: true, - IsReference: false, - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 6, - EndLine: 6, - StartPos: 107, - EndPos: 109, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 6, - EndLine: 6, - StartPos: 107, - EndPos: 109, - }, - Value: "b", - }, - }, - }, - }, - }, - }, - }, - &stmt.Expression{ - Position: &position.Position{ - StartLine: 7, - EndLine: 7, - StartPos: 114, - EndPos: 133, - }, - Expr: &expr.New{ - Position: &position.Position{ - StartLine: 7, - EndLine: 7, - StartPos: 114, - EndPos: 132, - }, - Class: &name.Name{ - Position: &position.Position{ - StartLine: 7, - EndLine: 7, - StartPos: 118, - EndPos: 121, - }, - Parts: []node.Node{ - &name.NamePart{ - Position: &position.Position{ - StartLine: 7, - EndLine: 7, - StartPos: 118, - EndPos: 121, - }, - Value: "foo", - }, - }, - }, - ArgumentList: &node.ArgumentList{ - Position: &position.Position{ - StartLine: 7, - EndLine: 7, - StartPos: 121, - EndPos: 132, - }, - Arguments: []node.Node{ - &node.Argument{ - Position: &position.Position{ - StartLine: 7, - EndLine: 7, - StartPos: 122, - EndPos: 124, - }, - Variadic: false, - IsReference: false, - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 7, - EndLine: 7, - StartPos: 122, - EndPos: 124, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 7, - EndLine: 7, - StartPos: 122, - EndPos: 124, - }, - Value: "a", - }, - }, - }, - &node.Argument{ - Position: &position.Position{ - StartLine: 7, - EndLine: 7, - StartPos: 126, - EndPos: 131, - }, - Variadic: true, - IsReference: false, - Expr: &expr.Variable{ - Position: &position.Position{ - StartLine: 7, - EndLine: 7, - StartPos: 129, - EndPos: 131, - }, - VarName: &node.Identifier{ - Position: &position.Position{ - StartLine: 7, - EndLine: 7, - StartPos: 129, - EndPos: 131, - }, - Value: "b", - }, - }, - }, - }, - }, - }, - }, - }, - } - - php5parser := php5.NewParser([]byte(src), "5.6") - php5parser.Parse() - actual := php5parser.GetRootNode() - assert.DeepEqual(t, expected, actual) -} - -func TestPhp7ParameterNode(t *testing.T) { - src := `