From a77f3aea03aebce97cc78fc5152bc538e5fb61e6 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Mon, 21 Aug 2023 11:16:44 -0400 Subject: [PATCH] Import the test fixtures --- .gitignore | 1 + Gemfile | 2 + Gemfile.lock | 6 + README.md | 3 + Rakefile | 95 ++++++++++ bin/{whitequark => parse} | 0 test/fixtures/LICENSE | 25 +++ test/fixtures/__ENCODING__.rb | 1 + test/fixtures/__ENCODING___legacy_.rb | 1 + test/fixtures/alias.rb | 1 + test/fixtures/alias_gvar.rb | 3 + ...biuous_quoted_label_in_ternary_operator.rb | 1 + test/fixtures/and.rb | 3 + test/fixtures/and_asgn.rb | 3 + test/fixtures/and_or_masgn.rb | 3 + test/fixtures/anonymous_blockarg.rb | 1 + test/fixtures/arg.rb | 3 + test/fixtures/arg_duplicate_ignored.rb | 3 + test/fixtures/arg_label.rb | 6 + test/fixtures/arg_scope.rb | 1 + test/fixtures/args.rb | 63 +++++++ test/fixtures/args_args_assocs.rb | 3 + test/fixtures/args_args_assocs_comma.rb | 1 + test/fixtures/args_args_comma.rb | 1 + test/fixtures/args_args_star.rb | 3 + test/fixtures/args_assocs.rb | 11 ++ test/fixtures/args_assocs_comma.rb | 1 + test/fixtures/args_assocs_legacy.rb | 11 ++ test/fixtures/args_block_pass.rb | 1 + test/fixtures/args_cmd.rb | 1 + test/fixtures/args_star.rb | 3 + test/fixtures/array_assocs.rb | 3 + test/fixtures/array_plain.rb | 1 + test/fixtures/array_splat.rb | 5 + test/fixtures/array_symbols.rb | 1 + test/fixtures/array_symbols_empty.rb | 3 + test/fixtures/array_symbols_interp.rb | 3 + test/fixtures/array_words.rb | 1 + test/fixtures/array_words_empty.rb | 3 + test/fixtures/array_words_interp.rb | 3 + test/fixtures/asgn_cmd.rb | 3 + test/fixtures/asgn_mrhs.rb | 5 + test/fixtures/back_ref.rb | 1 + test/fixtures/bang.rb | 1 + test/fixtures/bang_cmd.rb | 1 + test/fixtures/begin_cmdarg.rb | 1 + .../beginless_erange_after_newline.rb | 2 + .../beginless_irange_after_newline.rb | 2 + test/fixtures/beginless_range.rb | 3 + test/fixtures/blockarg.rb | 1 + test/fixtures/blockargs.rb | 71 +++++++ test/fixtures/break.rb | 7 + test/fixtures/break_block.rb | 1 + test/fixtures/bug_435.rb | 1 + test/fixtures/bug_447.rb | 3 + test/fixtures/bug_452.rb | 1 + test/fixtures/bug_466.rb | 1 + test/fixtures/bug_473.rb | 1 + test/fixtures/bug_480.rb | 1 + test/fixtures/bug_481.rb | 1 + test/fixtures/bug_ascii_8bit_in_literal.rb | 2 + test/fixtures/bug_cmd_string_lookahead.rb | 1 + test/fixtures/bug_cmdarg.rb | 5 + test/fixtures/bug_def_no_paren_eql_begin.rb | 4 + test/fixtures/bug_do_block_in_call_args.rb | 1 + test/fixtures/bug_do_block_in_cmdarg.rb | 1 + test/fixtures/bug_do_block_in_hash_brace.rb | 9 + test/fixtures/bug_heredoc_do.rb | 3 + test/fixtures/bug_interp_single.rb | 3 + test/fixtures/bug_lambda_leakage.rb | 1 + test/fixtures/bug_regex_verification.rb | 1 + test/fixtures/bug_rescue_empty_else.rb | 1 + test/fixtures/bug_while_not_parens_do.rb | 1 + test/fixtures/case_cond.rb | 1 + test/fixtures/case_cond_else.rb | 1 + test/fixtures/case_expr.rb | 1 + test/fixtures/case_expr_else.rb | 1 + test/fixtures/casgn_scoped.rb | 1 + test/fixtures/casgn_toplevel.rb | 1 + test/fixtures/casgn_unscoped.rb | 1 + test/fixtures/character.rb | 1 + test/fixtures/class.rb | 3 + .../class_definition_in_while_cond.rb | 7 + test/fixtures/class_super.rb | 1 + test/fixtures/class_super_label.rb | 1 + .../comments_before_leading_dot__27.rb | 19 ++ test/fixtures/complex.rb | 7 + test/fixtures/cond_begin.rb | 1 + test/fixtures/cond_begin_masgn.rb | 1 + test/fixtures/cond_eflipflop.rb | 3 + test/fixtures/cond_iflipflop.rb | 3 + test/fixtures/cond_match_current_line.rb | 3 + test/fixtures/const_op_asgn.rb | 9 + test/fixtures/const_scoped.rb | 1 + test/fixtures/const_toplevel.rb | 1 + test/fixtures/const_unscoped.rb | 1 + ...l_meta_escape_chars_in_regexp__since_31.rb | 13 ++ test/fixtures/cpath.rb | 3 + test/fixtures/cvar.rb | 1 + test/fixtures/cvasgn.rb | 1 + test/fixtures/dedenting_heredoc.rb | 75 ++++++++ ...polating_heredoc_fake_line_continuation.rb | 4 + ...interpolating_heredoc_line_continuation.rb | 4 + test/fixtures/def.rb | 11 ++ test/fixtures/defined.rb | 5 + test/fixtures/defs.rb | 9 + test/fixtures/empty_stmt.rb | 1 + test/fixtures/endless_comparison_method.rb | 11 ++ test/fixtures/endless_method.rb | 7 + .../fixtures/endless_method_command_syntax.rb | 15 ++ .../endless_method_forwarded_args_legacy.rb | 1 + .../endless_method_with_rescue_mod.rb | 3 + test/fixtures/endless_method_without_args.rb | 7 + test/fixtures/ensure.rb | 1 + test/fixtures/ensure_empty.rb | 1 + test/fixtures/false.rb | 1 + test/fixtures/float.rb | 3 + test/fixtures/for.rb | 3 + test/fixtures/for_mlhs.rb | 1 + test/fixtures/forward_arg.rb | 1 + test/fixtures/forward_arg_with_open_args.rb | 27 +++ test/fixtures/forward_args_legacy.rb | 5 + .../forwarded_argument_with_kwrestarg.rb | 1 + .../forwarded_argument_with_restarg.rb | 1 + test/fixtures/forwarded_kwrestarg.rb | 1 + ...rwarded_kwrestarg_with_additional_kwarg.rb | 1 + test/fixtures/forwarded_restarg.rb | 1 + test/fixtures/gvar.rb | 1 + test/fixtures/gvasgn.rb | 1 + test/fixtures/hash_empty.rb | 1 + test/fixtures/hash_hashrocket.rb | 3 + test/fixtures/hash_kwsplat.rb | 1 + test/fixtures/hash_label.rb | 1 + test/fixtures/hash_label_end.rb | 5 + test/fixtures/hash_pair_value_omission.rb | 5 + test/fixtures/heredoc.rb | 14 ++ test/fixtures/if.rb | 3 + test/fixtures/if_else.rb | 3 + test/fixtures/if_elsif.rb | 1 + test/fixtures/if_masgn__24.rb | 1 + test/fixtures/if_mod.rb | 1 + test/fixtures/if_nl_then.rb | 2 + .../if_while_after_class__since_32.rb | 7 + test/fixtures/int.rb | 5 + test/fixtures/int___LINE__.rb | 1 + test/fixtures/interp_digit_var.rb | 87 +++++++++ test/fixtures/ivar.rb | 1 + test/fixtures/ivasgn.rb | 1 + test/fixtures/keyword_argument_omission.rb | 1 + test/fixtures/kwarg.rb | 1 + test/fixtures/kwbegin_compstmt.rb | 1 + test/fixtures/kwnilarg.rb | 5 + test/fixtures/kwoptarg.rb | 1 + ...ptarg_with_kwrestarg_and_forwarded_args.rb | 1 + test/fixtures/kwrestarg_named.rb | 1 + test/fixtures/kwrestarg_unnamed.rb | 1 + .../fixtures/lbrace_arg_after_command_args.rb | 1 + .../lparenarg_after_lvar__since_25.rb | 3 + test/fixtures/lvar.rb | 1 + test/fixtures/lvar_injecting_match.rb | 1 + test/fixtures/lvasgn.rb | 1 + test/fixtures/masgn.rb | 5 + test/fixtures/masgn_attr.rb | 5 + test/fixtures/masgn_cmd.rb | 1 + test/fixtures/masgn_const.rb | 3 + test/fixtures/masgn_nested.rb | 3 + test/fixtures/masgn_splat.rb | 19 ++ .../method_definition_in_while_cond.rb | 7 + test/fixtures/module.rb | 1 + test/fixtures/multiple_pattern_matches.rb | 5 + test/fixtures/newline_in_hash_argument.rb | 14 ++ test/fixtures/next.rb | 7 + test/fixtures/next_block.rb | 1 + test/fixtures/nil.rb | 1 + test/fixtures/nil_expression.rb | 3 + test/fixtures/non_lvar_injecting_match.rb | 1 + test/fixtures/not.rb | 5 + test/fixtures/not_cmd.rb | 1 + test/fixtures/not_masgn__24.rb | 1 + test/fixtures/nth_ref.rb | 1 + test/fixtures/numbered_args_after_27.rb | 7 + test/fixtures/numparam_outside_block.rb | 9 + test/fixtures/op_asgn.rb | 5 + test/fixtures/op_asgn_cmd.rb | 7 + test/fixtures/op_asgn_index.rb | 1 + test/fixtures/op_asgn_index_cmd.rb | 1 + test/fixtures/optarg.rb | 3 + test/fixtures/or.rb | 3 + test/fixtures/or_asgn.rb | 3 + test/fixtures/parser_bug_272.rb | 1 + test/fixtures/parser_bug_490.rb | 5 + test/fixtures/parser_bug_507.rb | 1 + test/fixtures/parser_bug_518.rb | 2 + test/fixtures/parser_bug_525.rb | 1 + test/fixtures/parser_bug_604.rb | 1 + test/fixtures/parser_bug_640.rb | 4 + test/fixtures/parser_bug_645.rb | 1 + test/fixtures/parser_bug_830.rb | 1 + ...ops_truncated_parts_of_squiggly_heredoc.rb | 3 + ...rser_slash_slash_n_escaping_in_literals.rb | 62 +++++++ test/fixtures/pattern_match.rb | 175 ++++++++++++++++++ .../pattern_matching__FILE__LINE_literals.rb | 4 + test/fixtures/pattern_matching_blank_else.rb | 1 + test/fixtures/pattern_matching_else.rb | 1 + test/fixtures/pattern_matching_single_line.rb | 3 + ...le_line_allowed_omission_of_parentheses.rb | 11 ++ test/fixtures/postexe.rb | 1 + test/fixtures/preexe.rb | 1 + test/fixtures/procarg0.rb | 3 + test/fixtures/range_endless.rb | 3 + test/fixtures/range_exclusive.rb | 1 + test/fixtures/range_inclusive.rb | 1 + test/fixtures/rational.rb | 3 + test/fixtures/redo.rb | 1 + test/fixtures/regex_interp.rb | 1 + test/fixtures/regex_plain.rb | 1 + test/fixtures/resbody_list.rb | 1 + test/fixtures/resbody_list_mrhs.rb | 1 + test/fixtures/resbody_list_var.rb | 1 + test/fixtures/resbody_var.rb | 3 + test/fixtures/rescue.rb | 1 + test/fixtures/rescue_else.rb | 1 + test/fixtures/rescue_else_ensure.rb | 1 + test/fixtures/rescue_ensure.rb | 1 + test/fixtures/rescue_in_lambda_block.rb | 1 + test/fixtures/rescue_mod.rb | 1 + test/fixtures/rescue_mod_asgn.rb | 1 + test/fixtures/rescue_mod_masgn.rb | 1 + test/fixtures/rescue_mod_op_assign.rb | 1 + test/fixtures/rescue_without_begin_end.rb | 1 + test/fixtures/restarg_named.rb | 1 + test/fixtures/restarg_unnamed.rb | 1 + test/fixtures/retry.rb | 1 + test/fixtures/return.rb | 7 + test/fixtures/return_block.rb | 1 + test/fixtures/ruby_bug_10279.rb | 1 + test/fixtures/ruby_bug_10653.rb | 5 + test/fixtures/ruby_bug_11107.rb | 1 + test/fixtures/ruby_bug_11380.rb | 1 + test/fixtures/ruby_bug_11873.rb | 23 +++ test/fixtures/ruby_bug_11873_a.rb | 39 ++++ test/fixtures/ruby_bug_11873_b.rb | 1 + test/fixtures/ruby_bug_11989.rb | 3 + test/fixtures/ruby_bug_11990.rb | 3 + test/fixtures/ruby_bug_12073.rb | 3 + test/fixtures/ruby_bug_12402.rb | 27 +++ test/fixtures/ruby_bug_12669.rb | 7 + test/fixtures/ruby_bug_12686.rb | 1 + test/fixtures/ruby_bug_13547.rb | 1 + test/fixtures/ruby_bug_14690.rb | 1 + test/fixtures/ruby_bug_15789.rb | 3 + test/fixtures/ruby_bug_9669.rb | 8 + test/fixtures/sclass.rb | 1 + test/fixtures/self.rb | 1 + test/fixtures/send_attr_asgn.rb | 7 + test/fixtures/send_attr_asgn_conditional.rb | 1 + test/fixtures/send_binary_op.rb | 41 ++++ test/fixtures/send_block_chain_cmd.rb | 13 ++ test/fixtures/send_block_conditional.rb | 1 + test/fixtures/send_call.rb | 3 + test/fixtures/send_conditional.rb | 1 + test/fixtures/send_index.rb | 1 + test/fixtures/send_index_asgn.rb | 1 + test/fixtures/send_index_asgn_legacy.rb | 1 + test/fixtures/send_index_cmd.rb | 1 + test/fixtures/send_index_legacy.rb | 1 + test/fixtures/send_lambda.rb | 5 + test/fixtures/send_lambda_args.rb | 3 + test/fixtures/send_lambda_args_noparen.rb | 3 + test/fixtures/send_lambda_args_shadow.rb | 1 + test/fixtures/send_lambda_legacy.rb | 1 + test/fixtures/send_op_asgn_conditional.rb | 1 + test/fixtures/send_plain.rb | 5 + test/fixtures/send_plain_cmd.rb | 5 + test/fixtures/send_self.rb | 5 + test/fixtures/send_self_block.rb | 7 + test/fixtures/send_unary_op.rb | 5 + test/fixtures/slash_newline_in_heredocs.rb | 13 ++ test/fixtures/space_args_arg.rb | 1 + test/fixtures/space_args_arg_block.rb | 5 + test/fixtures/space_args_arg_call.rb | 1 + test/fixtures/space_args_arg_newline.rb | 2 + test/fixtures/space_args_block.rb | 1 + test/fixtures/space_args_cmd.rb | 1 + test/fixtures/string___FILE__.rb | 1 + test/fixtures/string_concat.rb | 1 + test/fixtures/string_dvar.rb | 1 + test/fixtures/string_interp.rb | 1 + test/fixtures/string_plain.rb | 3 + test/fixtures/super.rb | 5 + test/fixtures/super_block.rb | 3 + test/fixtures/symbol_interp.rb | 1 + test/fixtures/symbol_plain.rb | 3 + test/fixtures/ternary.rb | 1 + test/fixtures/ternary_ambiguous_symbol.rb | 1 + test/fixtures/trailing_forward_arg.rb | 1 + test/fixtures/true.rb | 1 + test/fixtures/unary_num_pow_precedence.rb | 5 + test/fixtures/undef.rb | 1 + test/fixtures/unless.rb | 3 + test/fixtures/unless_else.rb | 3 + test/fixtures/unless_mod.rb | 1 + test/fixtures/until.rb | 3 + test/fixtures/until_mod.rb | 1 + test/fixtures/until_post.rb | 1 + test/fixtures/var_and_asgn.rb | 1 + test/fixtures/var_op_asgn.rb | 7 + test/fixtures/var_op_asgn_cmd.rb | 1 + test/fixtures/var_or_asgn.rb | 1 + test/fixtures/when_multi.rb | 1 + test/fixtures/when_splat.rb | 1 + test/fixtures/when_then.rb | 1 + test/fixtures/while.rb | 3 + test/fixtures/while_mod.rb | 1 + test/fixtures/while_post.rb | 1 + test/fixtures/xstring_interp.rb | 1 + test/fixtures/xstring_plain.rb | 1 + test/fixtures/yield.rb | 7 + test/fixtures/zsuper.rb | 1 + test/yarp_test.rb | 63 +++++++ 320 files changed, 1719 insertions(+) create mode 100644 README.md create mode 100644 Rakefile rename bin/{whitequark => parse} (100%) create mode 100644 test/fixtures/LICENSE create mode 100644 test/fixtures/__ENCODING__.rb create mode 100644 test/fixtures/__ENCODING___legacy_.rb create mode 100644 test/fixtures/alias.rb create mode 100644 test/fixtures/alias_gvar.rb create mode 100644 test/fixtures/ambiuous_quoted_label_in_ternary_operator.rb create mode 100644 test/fixtures/and.rb create mode 100644 test/fixtures/and_asgn.rb create mode 100644 test/fixtures/and_or_masgn.rb create mode 100644 test/fixtures/anonymous_blockarg.rb create mode 100644 test/fixtures/arg.rb create mode 100644 test/fixtures/arg_duplicate_ignored.rb create mode 100644 test/fixtures/arg_label.rb create mode 100644 test/fixtures/arg_scope.rb create mode 100644 test/fixtures/args.rb create mode 100644 test/fixtures/args_args_assocs.rb create mode 100644 test/fixtures/args_args_assocs_comma.rb create mode 100644 test/fixtures/args_args_comma.rb create mode 100644 test/fixtures/args_args_star.rb create mode 100644 test/fixtures/args_assocs.rb create mode 100644 test/fixtures/args_assocs_comma.rb create mode 100644 test/fixtures/args_assocs_legacy.rb create mode 100644 test/fixtures/args_block_pass.rb create mode 100644 test/fixtures/args_cmd.rb create mode 100644 test/fixtures/args_star.rb create mode 100644 test/fixtures/array_assocs.rb create mode 100644 test/fixtures/array_plain.rb create mode 100644 test/fixtures/array_splat.rb create mode 100644 test/fixtures/array_symbols.rb create mode 100644 test/fixtures/array_symbols_empty.rb create mode 100644 test/fixtures/array_symbols_interp.rb create mode 100644 test/fixtures/array_words.rb create mode 100644 test/fixtures/array_words_empty.rb create mode 100644 test/fixtures/array_words_interp.rb create mode 100644 test/fixtures/asgn_cmd.rb create mode 100644 test/fixtures/asgn_mrhs.rb create mode 100644 test/fixtures/back_ref.rb create mode 100644 test/fixtures/bang.rb create mode 100644 test/fixtures/bang_cmd.rb create mode 100644 test/fixtures/begin_cmdarg.rb create mode 100644 test/fixtures/beginless_erange_after_newline.rb create mode 100644 test/fixtures/beginless_irange_after_newline.rb create mode 100644 test/fixtures/beginless_range.rb create mode 100644 test/fixtures/blockarg.rb create mode 100644 test/fixtures/blockargs.rb create mode 100644 test/fixtures/break.rb create mode 100644 test/fixtures/break_block.rb create mode 100644 test/fixtures/bug_435.rb create mode 100644 test/fixtures/bug_447.rb create mode 100644 test/fixtures/bug_452.rb create mode 100644 test/fixtures/bug_466.rb create mode 100644 test/fixtures/bug_473.rb create mode 100644 test/fixtures/bug_480.rb create mode 100644 test/fixtures/bug_481.rb create mode 100644 test/fixtures/bug_ascii_8bit_in_literal.rb create mode 100644 test/fixtures/bug_cmd_string_lookahead.rb create mode 100644 test/fixtures/bug_cmdarg.rb create mode 100644 test/fixtures/bug_def_no_paren_eql_begin.rb create mode 100644 test/fixtures/bug_do_block_in_call_args.rb create mode 100644 test/fixtures/bug_do_block_in_cmdarg.rb create mode 100644 test/fixtures/bug_do_block_in_hash_brace.rb create mode 100644 test/fixtures/bug_heredoc_do.rb create mode 100644 test/fixtures/bug_interp_single.rb create mode 100644 test/fixtures/bug_lambda_leakage.rb create mode 100644 test/fixtures/bug_regex_verification.rb create mode 100644 test/fixtures/bug_rescue_empty_else.rb create mode 100644 test/fixtures/bug_while_not_parens_do.rb create mode 100644 test/fixtures/case_cond.rb create mode 100644 test/fixtures/case_cond_else.rb create mode 100644 test/fixtures/case_expr.rb create mode 100644 test/fixtures/case_expr_else.rb create mode 100644 test/fixtures/casgn_scoped.rb create mode 100644 test/fixtures/casgn_toplevel.rb create mode 100644 test/fixtures/casgn_unscoped.rb create mode 100644 test/fixtures/character.rb create mode 100644 test/fixtures/class.rb create mode 100644 test/fixtures/class_definition_in_while_cond.rb create mode 100644 test/fixtures/class_super.rb create mode 100644 test/fixtures/class_super_label.rb create mode 100644 test/fixtures/comments_before_leading_dot__27.rb create mode 100644 test/fixtures/complex.rb create mode 100644 test/fixtures/cond_begin.rb create mode 100644 test/fixtures/cond_begin_masgn.rb create mode 100644 test/fixtures/cond_eflipflop.rb create mode 100644 test/fixtures/cond_iflipflop.rb create mode 100644 test/fixtures/cond_match_current_line.rb create mode 100644 test/fixtures/const_op_asgn.rb create mode 100644 test/fixtures/const_scoped.rb create mode 100644 test/fixtures/const_toplevel.rb create mode 100644 test/fixtures/const_unscoped.rb create mode 100644 test/fixtures/control_meta_escape_chars_in_regexp__since_31.rb create mode 100644 test/fixtures/cpath.rb create mode 100644 test/fixtures/cvar.rb create mode 100644 test/fixtures/cvasgn.rb create mode 100644 test/fixtures/dedenting_heredoc.rb create mode 100644 test/fixtures/dedenting_interpolating_heredoc_fake_line_continuation.rb create mode 100644 test/fixtures/dedenting_non_interpolating_heredoc_line_continuation.rb create mode 100644 test/fixtures/def.rb create mode 100644 test/fixtures/defined.rb create mode 100644 test/fixtures/defs.rb create mode 100644 test/fixtures/empty_stmt.rb create mode 100644 test/fixtures/endless_comparison_method.rb create mode 100644 test/fixtures/endless_method.rb create mode 100644 test/fixtures/endless_method_command_syntax.rb create mode 100644 test/fixtures/endless_method_forwarded_args_legacy.rb create mode 100644 test/fixtures/endless_method_with_rescue_mod.rb create mode 100644 test/fixtures/endless_method_without_args.rb create mode 100644 test/fixtures/ensure.rb create mode 100644 test/fixtures/ensure_empty.rb create mode 100644 test/fixtures/false.rb create mode 100644 test/fixtures/float.rb create mode 100644 test/fixtures/for.rb create mode 100644 test/fixtures/for_mlhs.rb create mode 100644 test/fixtures/forward_arg.rb create mode 100644 test/fixtures/forward_arg_with_open_args.rb create mode 100644 test/fixtures/forward_args_legacy.rb create mode 100644 test/fixtures/forwarded_argument_with_kwrestarg.rb create mode 100644 test/fixtures/forwarded_argument_with_restarg.rb create mode 100644 test/fixtures/forwarded_kwrestarg.rb create mode 100644 test/fixtures/forwarded_kwrestarg_with_additional_kwarg.rb create mode 100644 test/fixtures/forwarded_restarg.rb create mode 100644 test/fixtures/gvar.rb create mode 100644 test/fixtures/gvasgn.rb create mode 100644 test/fixtures/hash_empty.rb create mode 100644 test/fixtures/hash_hashrocket.rb create mode 100644 test/fixtures/hash_kwsplat.rb create mode 100644 test/fixtures/hash_label.rb create mode 100644 test/fixtures/hash_label_end.rb create mode 100644 test/fixtures/hash_pair_value_omission.rb create mode 100644 test/fixtures/heredoc.rb create mode 100644 test/fixtures/if.rb create mode 100644 test/fixtures/if_else.rb create mode 100644 test/fixtures/if_elsif.rb create mode 100644 test/fixtures/if_masgn__24.rb create mode 100644 test/fixtures/if_mod.rb create mode 100644 test/fixtures/if_nl_then.rb create mode 100644 test/fixtures/if_while_after_class__since_32.rb create mode 100644 test/fixtures/int.rb create mode 100644 test/fixtures/int___LINE__.rb create mode 100644 test/fixtures/interp_digit_var.rb create mode 100644 test/fixtures/ivar.rb create mode 100644 test/fixtures/ivasgn.rb create mode 100644 test/fixtures/keyword_argument_omission.rb create mode 100644 test/fixtures/kwarg.rb create mode 100644 test/fixtures/kwbegin_compstmt.rb create mode 100644 test/fixtures/kwnilarg.rb create mode 100644 test/fixtures/kwoptarg.rb create mode 100644 test/fixtures/kwoptarg_with_kwrestarg_and_forwarded_args.rb create mode 100644 test/fixtures/kwrestarg_named.rb create mode 100644 test/fixtures/kwrestarg_unnamed.rb create mode 100644 test/fixtures/lbrace_arg_after_command_args.rb create mode 100644 test/fixtures/lparenarg_after_lvar__since_25.rb create mode 100644 test/fixtures/lvar.rb create mode 100644 test/fixtures/lvar_injecting_match.rb create mode 100644 test/fixtures/lvasgn.rb create mode 100644 test/fixtures/masgn.rb create mode 100644 test/fixtures/masgn_attr.rb create mode 100644 test/fixtures/masgn_cmd.rb create mode 100644 test/fixtures/masgn_const.rb create mode 100644 test/fixtures/masgn_nested.rb create mode 100644 test/fixtures/masgn_splat.rb create mode 100644 test/fixtures/method_definition_in_while_cond.rb create mode 100644 test/fixtures/module.rb create mode 100644 test/fixtures/multiple_pattern_matches.rb create mode 100644 test/fixtures/newline_in_hash_argument.rb create mode 100644 test/fixtures/next.rb create mode 100644 test/fixtures/next_block.rb create mode 100644 test/fixtures/nil.rb create mode 100644 test/fixtures/nil_expression.rb create mode 100644 test/fixtures/non_lvar_injecting_match.rb create mode 100644 test/fixtures/not.rb create mode 100644 test/fixtures/not_cmd.rb create mode 100644 test/fixtures/not_masgn__24.rb create mode 100644 test/fixtures/nth_ref.rb create mode 100644 test/fixtures/numbered_args_after_27.rb create mode 100644 test/fixtures/numparam_outside_block.rb create mode 100644 test/fixtures/op_asgn.rb create mode 100644 test/fixtures/op_asgn_cmd.rb create mode 100644 test/fixtures/op_asgn_index.rb create mode 100644 test/fixtures/op_asgn_index_cmd.rb create mode 100644 test/fixtures/optarg.rb create mode 100644 test/fixtures/or.rb create mode 100644 test/fixtures/or_asgn.rb create mode 100644 test/fixtures/parser_bug_272.rb create mode 100644 test/fixtures/parser_bug_490.rb create mode 100644 test/fixtures/parser_bug_507.rb create mode 100644 test/fixtures/parser_bug_518.rb create mode 100644 test/fixtures/parser_bug_525.rb create mode 100644 test/fixtures/parser_bug_604.rb create mode 100644 test/fixtures/parser_bug_640.rb create mode 100644 test/fixtures/parser_bug_645.rb create mode 100644 test/fixtures/parser_bug_830.rb create mode 100644 test/fixtures/parser_drops_truncated_parts_of_squiggly_heredoc.rb create mode 100644 test/fixtures/parser_slash_slash_n_escaping_in_literals.rb create mode 100644 test/fixtures/pattern_match.rb create mode 100644 test/fixtures/pattern_matching__FILE__LINE_literals.rb create mode 100644 test/fixtures/pattern_matching_blank_else.rb create mode 100644 test/fixtures/pattern_matching_else.rb create mode 100644 test/fixtures/pattern_matching_single_line.rb create mode 100644 test/fixtures/pattern_matching_single_line_allowed_omission_of_parentheses.rb create mode 100644 test/fixtures/postexe.rb create mode 100644 test/fixtures/preexe.rb create mode 100644 test/fixtures/procarg0.rb create mode 100644 test/fixtures/range_endless.rb create mode 100644 test/fixtures/range_exclusive.rb create mode 100644 test/fixtures/range_inclusive.rb create mode 100644 test/fixtures/rational.rb create mode 100644 test/fixtures/redo.rb create mode 100644 test/fixtures/regex_interp.rb create mode 100644 test/fixtures/regex_plain.rb create mode 100644 test/fixtures/resbody_list.rb create mode 100644 test/fixtures/resbody_list_mrhs.rb create mode 100644 test/fixtures/resbody_list_var.rb create mode 100644 test/fixtures/resbody_var.rb create mode 100644 test/fixtures/rescue.rb create mode 100644 test/fixtures/rescue_else.rb create mode 100644 test/fixtures/rescue_else_ensure.rb create mode 100644 test/fixtures/rescue_ensure.rb create mode 100644 test/fixtures/rescue_in_lambda_block.rb create mode 100644 test/fixtures/rescue_mod.rb create mode 100644 test/fixtures/rescue_mod_asgn.rb create mode 100644 test/fixtures/rescue_mod_masgn.rb create mode 100644 test/fixtures/rescue_mod_op_assign.rb create mode 100644 test/fixtures/rescue_without_begin_end.rb create mode 100644 test/fixtures/restarg_named.rb create mode 100644 test/fixtures/restarg_unnamed.rb create mode 100644 test/fixtures/retry.rb create mode 100644 test/fixtures/return.rb create mode 100644 test/fixtures/return_block.rb create mode 100644 test/fixtures/ruby_bug_10279.rb create mode 100644 test/fixtures/ruby_bug_10653.rb create mode 100644 test/fixtures/ruby_bug_11107.rb create mode 100644 test/fixtures/ruby_bug_11380.rb create mode 100644 test/fixtures/ruby_bug_11873.rb create mode 100644 test/fixtures/ruby_bug_11873_a.rb create mode 100644 test/fixtures/ruby_bug_11873_b.rb create mode 100644 test/fixtures/ruby_bug_11989.rb create mode 100644 test/fixtures/ruby_bug_11990.rb create mode 100644 test/fixtures/ruby_bug_12073.rb create mode 100644 test/fixtures/ruby_bug_12402.rb create mode 100644 test/fixtures/ruby_bug_12669.rb create mode 100644 test/fixtures/ruby_bug_12686.rb create mode 100644 test/fixtures/ruby_bug_13547.rb create mode 100644 test/fixtures/ruby_bug_14690.rb create mode 100644 test/fixtures/ruby_bug_15789.rb create mode 100644 test/fixtures/ruby_bug_9669.rb create mode 100644 test/fixtures/sclass.rb create mode 100644 test/fixtures/self.rb create mode 100644 test/fixtures/send_attr_asgn.rb create mode 100644 test/fixtures/send_attr_asgn_conditional.rb create mode 100644 test/fixtures/send_binary_op.rb create mode 100644 test/fixtures/send_block_chain_cmd.rb create mode 100644 test/fixtures/send_block_conditional.rb create mode 100644 test/fixtures/send_call.rb create mode 100644 test/fixtures/send_conditional.rb create mode 100644 test/fixtures/send_index.rb create mode 100644 test/fixtures/send_index_asgn.rb create mode 100644 test/fixtures/send_index_asgn_legacy.rb create mode 100644 test/fixtures/send_index_cmd.rb create mode 100644 test/fixtures/send_index_legacy.rb create mode 100644 test/fixtures/send_lambda.rb create mode 100644 test/fixtures/send_lambda_args.rb create mode 100644 test/fixtures/send_lambda_args_noparen.rb create mode 100644 test/fixtures/send_lambda_args_shadow.rb create mode 100644 test/fixtures/send_lambda_legacy.rb create mode 100644 test/fixtures/send_op_asgn_conditional.rb create mode 100644 test/fixtures/send_plain.rb create mode 100644 test/fixtures/send_plain_cmd.rb create mode 100644 test/fixtures/send_self.rb create mode 100644 test/fixtures/send_self_block.rb create mode 100644 test/fixtures/send_unary_op.rb create mode 100644 test/fixtures/slash_newline_in_heredocs.rb create mode 100644 test/fixtures/space_args_arg.rb create mode 100644 test/fixtures/space_args_arg_block.rb create mode 100644 test/fixtures/space_args_arg_call.rb create mode 100644 test/fixtures/space_args_arg_newline.rb create mode 100644 test/fixtures/space_args_block.rb create mode 100644 test/fixtures/space_args_cmd.rb create mode 100644 test/fixtures/string___FILE__.rb create mode 100644 test/fixtures/string_concat.rb create mode 100644 test/fixtures/string_dvar.rb create mode 100644 test/fixtures/string_interp.rb create mode 100644 test/fixtures/string_plain.rb create mode 100644 test/fixtures/super.rb create mode 100644 test/fixtures/super_block.rb create mode 100644 test/fixtures/symbol_interp.rb create mode 100644 test/fixtures/symbol_plain.rb create mode 100644 test/fixtures/ternary.rb create mode 100644 test/fixtures/ternary_ambiguous_symbol.rb create mode 100644 test/fixtures/trailing_forward_arg.rb create mode 100644 test/fixtures/true.rb create mode 100644 test/fixtures/unary_num_pow_precedence.rb create mode 100644 test/fixtures/undef.rb create mode 100644 test/fixtures/unless.rb create mode 100644 test/fixtures/unless_else.rb create mode 100644 test/fixtures/unless_mod.rb create mode 100644 test/fixtures/until.rb create mode 100644 test/fixtures/until_mod.rb create mode 100644 test/fixtures/until_post.rb create mode 100644 test/fixtures/var_and_asgn.rb create mode 100644 test/fixtures/var_op_asgn.rb create mode 100644 test/fixtures/var_op_asgn_cmd.rb create mode 100644 test/fixtures/var_or_asgn.rb create mode 100644 test/fixtures/when_multi.rb create mode 100644 test/fixtures/when_splat.rb create mode 100644 test/fixtures/when_then.rb create mode 100644 test/fixtures/while.rb create mode 100644 test/fixtures/while_mod.rb create mode 100644 test/fixtures/while_post.rb create mode 100644 test/fixtures/xstring_interp.rb create mode 100644 test/fixtures/xstring_plain.rb create mode 100644 test/fixtures/yield.rb create mode 100644 test/fixtures/zsuper.rb create mode 100644 test/yarp_test.rb diff --git a/.gitignore b/.gitignore index f6e4e0d..d05b6f7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ test.rb +tmp diff --git a/Gemfile b/Gemfile index 577d871..572ec5e 100644 --- a/Gemfile +++ b/Gemfile @@ -3,4 +3,6 @@ source "https://rubygems.org" gem "parser" +gem "rake" +gem "test-unit" gem "yarp", "~> 0.8" diff --git a/Gemfile.lock b/Gemfile.lock index af603e5..1b89621 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -5,7 +5,11 @@ GEM parser (3.2.2.3) ast (~> 2.4.1) racc + power_assert (2.0.3) racc (1.7.1) + rake (13.0.6) + test-unit (3.6.1) + power_assert yarp (0.8.0) PLATFORMS @@ -13,6 +17,8 @@ PLATFORMS DEPENDENCIES parser + rake + test-unit yarp (~> 0.8) BUNDLED WITH diff --git a/README.md b/README.md new file mode 100644 index 0000000..e36525b --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# parser-yarp + +An experiment in translating the YARP AST into the whitequark/parser AST. diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..641b6fe --- /dev/null +++ b/Rakefile @@ -0,0 +1,95 @@ +# frozen_string_literal: true + +require "rake/testtask" + +Rake::TestTask.new(:test) do |t| + t.libs << "test" + t.libs << "lib" + t.test_files = FileList["test/**/*_test.rb"] +end + +task default: :test + +# This namespace's purpose is to extract the examples from the whitequark/parser +# gem and generate a test file that we can use to ensure that our parser +# generates equivalent syntax trees when translating. To do this, it runs the +# parser's test suite but overrides the `assert_parses` method to collect the +# examples into a hash. Then, it writes out the hash to a file that we can use +# to generate our own tests. +# +# To run the test suite, it's important to note that we have to mirror both any +# APIs provided to the test suite (for example the ParseHelper module below). +# This is obviously relatively brittle, but it's effective for now. +namespace :whitequark do + desc "Ensure there's a local copy of whitequark/parser" + file "tmp/whitequark" do + sh "git clone --depth=1 https://github.com/whitequark/parser tmp/whitequark" + end + + desc "Ensure we have a fixtures directory for the whitequark/parser tests" + directory "test/fixtures" + + desc "Import the whitequark/parser tests" + task import: ["tmp/whitequark", "test/fixtures"] do + cp "tmp/whitequark/LICENSE.txt", "test/fixtures/LICENSE" + + mkdir_p "tmp/whitequark/scratch" + touch "tmp/whitequark/scratch/helper.rb" + touch "tmp/whitequark/scratch/parse_helper.rb" + $:.unshift("tmp/whitequark/scratch") + + require "ast" + module ParseHelper + include AST::Sexp + + # This object is going to collect all of the examples from the parser gem + # into a hash that we can use to generate our own tests. + COLLECTED = Hash.new { |hash, key| hash[key] = [] } + ALL_VERSIONS = %w[3.1 3.2] + + private + + def assert_context(*) + end + + def assert_diagnoses(*) + end + + def assert_diagnoses_many(*) + end + + def refute_diagnoses(*) + end + + def with_versions(*) + end + + def assert_parses(_ast, code, _source_maps = "", versions = ALL_VERSIONS) + # We're going to skip any examples that are for older Ruby versions + # that we do not support. + return if (versions & %w[3.1 3.2]).empty? + + entry = caller.find { _1.include?("test_parser.rb") } + _, name = *entry.match(/\d+:in `(?:block in )?(?:test_|assert_parses_)?(.+)'/) + + COLLECTED[name] << code + end + end + + require "parser/current" + require "minitest/autorun" + require_relative "tmp/whitequark/test/test_parser" + + Minitest.after_run do + ParseHelper::COLLECTED.each do |(name, codes)| + File.write("test/fixtures/#{name}.rb", "#{codes.sort.join("\n\n")}\n") + end + end + end + + desc "Clean up tmp files related to whitequark/parser" + task :clean do + rm_rf "tmp/whitequark" + rm_rf "test/fixtures" + end +end diff --git a/bin/whitequark b/bin/parse similarity index 100% rename from bin/whitequark rename to bin/parse diff --git a/test/fixtures/LICENSE b/test/fixtures/LICENSE new file mode 100644 index 0000000..971310e --- /dev/null +++ b/test/fixtures/LICENSE @@ -0,0 +1,25 @@ +Copyright (c) 2013-2016 whitequark + +Parts of the source are derived from ruby_parser: +Copyright (c) Ryan Davis, seattle.rb + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/test/fixtures/__ENCODING__.rb b/test/fixtures/__ENCODING__.rb new file mode 100644 index 0000000..d6debf2 --- /dev/null +++ b/test/fixtures/__ENCODING__.rb @@ -0,0 +1 @@ +__ENCODING__ diff --git a/test/fixtures/__ENCODING___legacy_.rb b/test/fixtures/__ENCODING___legacy_.rb new file mode 100644 index 0000000..d6debf2 --- /dev/null +++ b/test/fixtures/__ENCODING___legacy_.rb @@ -0,0 +1 @@ +__ENCODING__ diff --git a/test/fixtures/alias.rb b/test/fixtures/alias.rb new file mode 100644 index 0000000..e33b120 --- /dev/null +++ b/test/fixtures/alias.rb @@ -0,0 +1 @@ +alias :foo bar diff --git a/test/fixtures/alias_gvar.rb b/test/fixtures/alias_gvar.rb new file mode 100644 index 0000000..b975d97 --- /dev/null +++ b/test/fixtures/alias_gvar.rb @@ -0,0 +1,3 @@ +alias $a $+ + +alias $a $b diff --git a/test/fixtures/ambiuous_quoted_label_in_ternary_operator.rb b/test/fixtures/ambiuous_quoted_label_in_ternary_operator.rb new file mode 100644 index 0000000..9b2e3af --- /dev/null +++ b/test/fixtures/ambiuous_quoted_label_in_ternary_operator.rb @@ -0,0 +1 @@ +a ? b & '': nil diff --git a/test/fixtures/and.rb b/test/fixtures/and.rb new file mode 100644 index 0000000..43fa6a6 --- /dev/null +++ b/test/fixtures/and.rb @@ -0,0 +1,3 @@ +foo && bar + +foo and bar diff --git a/test/fixtures/and_asgn.rb b/test/fixtures/and_asgn.rb new file mode 100644 index 0000000..a979265 --- /dev/null +++ b/test/fixtures/and_asgn.rb @@ -0,0 +1,3 @@ +foo.a &&= 1 + +foo[0, 1] &&= 2 diff --git a/test/fixtures/and_or_masgn.rb b/test/fixtures/and_or_masgn.rb new file mode 100644 index 0000000..e346041 --- /dev/null +++ b/test/fixtures/and_or_masgn.rb @@ -0,0 +1,3 @@ +foo && (a, b = bar) + +foo || (a, b = bar) diff --git a/test/fixtures/anonymous_blockarg.rb b/test/fixtures/anonymous_blockarg.rb new file mode 100644 index 0000000..e3eaaad --- /dev/null +++ b/test/fixtures/anonymous_blockarg.rb @@ -0,0 +1 @@ +def foo(&); bar(&); end diff --git a/test/fixtures/arg.rb b/test/fixtures/arg.rb new file mode 100644 index 0000000..b1984ad --- /dev/null +++ b/test/fixtures/arg.rb @@ -0,0 +1,3 @@ +def f(foo); end + +def f(foo, bar); end diff --git a/test/fixtures/arg_duplicate_ignored.rb b/test/fixtures/arg_duplicate_ignored.rb new file mode 100644 index 0000000..0f5cc33 --- /dev/null +++ b/test/fixtures/arg_duplicate_ignored.rb @@ -0,0 +1,3 @@ +def foo(_, _); end + +def foo(_a, _a); end diff --git a/test/fixtures/arg_label.rb b/test/fixtures/arg_label.rb new file mode 100644 index 0000000..82db416 --- /dev/null +++ b/test/fixtures/arg_label.rb @@ -0,0 +1,6 @@ +def foo + a:b end + +def foo() a:b end + +f { || a:b } diff --git a/test/fixtures/arg_scope.rb b/test/fixtures/arg_scope.rb new file mode 100644 index 0000000..6c67ab7 --- /dev/null +++ b/test/fixtures/arg_scope.rb @@ -0,0 +1 @@ +lambda{|;a|a} diff --git a/test/fixtures/args.rb b/test/fixtures/args.rb new file mode 100644 index 0000000..773be47 --- /dev/null +++ b/test/fixtures/args.rb @@ -0,0 +1,63 @@ +def f &b; end + +def f (((a))); end + +def f ((*)); end + +def f ((*, p)); end + +def f ((*r)); end + +def f ((*r, p)); end + +def f ((a, *)); end + +def f ((a, *, p)); end + +def f ((a, *r)); end + +def f ((a, *r, p)); end + +def f ((a, a1)); end + +def f (foo: 1, &b); end + +def f (foo: 1, bar: 2, **baz, &b); end + +def f **baz, &b; end + +def f *, **; end + +def f *r, &b; end + +def f *r, p, &b; end + +def f ; end + +def f a, &b; end + +def f a, *r, &b; end + +def f a, *r, p, &b; end + +def f a, o=1, &b; end + +def f a, o=1, *r, &b; end + +def f a, o=1, *r, p, &b; end + +def f a, o=1, p, &b; end + +def f foo: +; end + +def f foo: -1 +; end + +def f o=1, &b; end + +def f o=1, *r, &b; end + +def f o=1, *r, p, &b; end + +def f o=1, p, &b; end diff --git a/test/fixtures/args_args_assocs.rb b/test/fixtures/args_args_assocs.rb new file mode 100644 index 0000000..445f899 --- /dev/null +++ b/test/fixtures/args_args_assocs.rb @@ -0,0 +1,3 @@ +fun(foo, :foo => 1) + +fun(foo, :foo => 1, &baz) diff --git a/test/fixtures/args_args_assocs_comma.rb b/test/fixtures/args_args_assocs_comma.rb new file mode 100644 index 0000000..b566a59 --- /dev/null +++ b/test/fixtures/args_args_assocs_comma.rb @@ -0,0 +1 @@ +foo[bar, :baz => 1,] diff --git a/test/fixtures/args_args_comma.rb b/test/fixtures/args_args_comma.rb new file mode 100644 index 0000000..8077071 --- /dev/null +++ b/test/fixtures/args_args_comma.rb @@ -0,0 +1 @@ +foo[bar,] diff --git a/test/fixtures/args_args_star.rb b/test/fixtures/args_args_star.rb new file mode 100644 index 0000000..d4dc9cc --- /dev/null +++ b/test/fixtures/args_args_star.rb @@ -0,0 +1,3 @@ +fun(foo, *bar) + +fun(foo, *bar, &baz) diff --git a/test/fixtures/args_assocs.rb b/test/fixtures/args_assocs.rb new file mode 100644 index 0000000..b33e131 --- /dev/null +++ b/test/fixtures/args_assocs.rb @@ -0,0 +1,11 @@ +fun(:foo => 1) + +fun(:foo => 1, &baz) + +self.[]= foo, :a => 1 + +self[:bar => 1] + +super(:foo => 42) + +yield(:foo => 42) diff --git a/test/fixtures/args_assocs_comma.rb b/test/fixtures/args_assocs_comma.rb new file mode 100644 index 0000000..15e5cd6 --- /dev/null +++ b/test/fixtures/args_assocs_comma.rb @@ -0,0 +1 @@ +foo[:baz => 1,] diff --git a/test/fixtures/args_assocs_legacy.rb b/test/fixtures/args_assocs_legacy.rb new file mode 100644 index 0000000..b33e131 --- /dev/null +++ b/test/fixtures/args_assocs_legacy.rb @@ -0,0 +1,11 @@ +fun(:foo => 1) + +fun(:foo => 1, &baz) + +self.[]= foo, :a => 1 + +self[:bar => 1] + +super(:foo => 42) + +yield(:foo => 42) diff --git a/test/fixtures/args_block_pass.rb b/test/fixtures/args_block_pass.rb new file mode 100644 index 0000000..35d7d23 --- /dev/null +++ b/test/fixtures/args_block_pass.rb @@ -0,0 +1 @@ +fun(&bar) diff --git a/test/fixtures/args_cmd.rb b/test/fixtures/args_cmd.rb new file mode 100644 index 0000000..dd0c889 --- /dev/null +++ b/test/fixtures/args_cmd.rb @@ -0,0 +1 @@ +fun(f bar) diff --git a/test/fixtures/args_star.rb b/test/fixtures/args_star.rb new file mode 100644 index 0000000..ce1e6f8 --- /dev/null +++ b/test/fixtures/args_star.rb @@ -0,0 +1,3 @@ +fun(*bar) + +fun(*bar, &baz) diff --git a/test/fixtures/array_assocs.rb b/test/fixtures/array_assocs.rb new file mode 100644 index 0000000..fcecfcd --- /dev/null +++ b/test/fixtures/array_assocs.rb @@ -0,0 +1,3 @@ +[ 1 => 2 ] + +[ 1, 2 => 3 ] diff --git a/test/fixtures/array_plain.rb b/test/fixtures/array_plain.rb new file mode 100644 index 0000000..44e2ace --- /dev/null +++ b/test/fixtures/array_plain.rb @@ -0,0 +1 @@ +[1, 2] diff --git a/test/fixtures/array_splat.rb b/test/fixtures/array_splat.rb new file mode 100644 index 0000000..144c1eb --- /dev/null +++ b/test/fixtures/array_splat.rb @@ -0,0 +1,5 @@ +[*foo] + +[1, *foo, 2] + +[1, *foo] diff --git a/test/fixtures/array_symbols.rb b/test/fixtures/array_symbols.rb new file mode 100644 index 0000000..a9f9df0 --- /dev/null +++ b/test/fixtures/array_symbols.rb @@ -0,0 +1 @@ +%i[foo bar] diff --git a/test/fixtures/array_symbols_empty.rb b/test/fixtures/array_symbols_empty.rb new file mode 100644 index 0000000..da3a89e --- /dev/null +++ b/test/fixtures/array_symbols_empty.rb @@ -0,0 +1,3 @@ +%I() + +%i[] diff --git a/test/fixtures/array_symbols_interp.rb b/test/fixtures/array_symbols_interp.rb new file mode 100644 index 0000000..d4950d0 --- /dev/null +++ b/test/fixtures/array_symbols_interp.rb @@ -0,0 +1,3 @@ +%I[foo #{bar}] + +%I[foo#{bar}] diff --git a/test/fixtures/array_words.rb b/test/fixtures/array_words.rb new file mode 100644 index 0000000..a07380c --- /dev/null +++ b/test/fixtures/array_words.rb @@ -0,0 +1 @@ +%w[foo bar] diff --git a/test/fixtures/array_words_empty.rb b/test/fixtures/array_words_empty.rb new file mode 100644 index 0000000..7568263 --- /dev/null +++ b/test/fixtures/array_words_empty.rb @@ -0,0 +1,3 @@ +%W() + +%w[] diff --git a/test/fixtures/array_words_interp.rb b/test/fixtures/array_words_interp.rb new file mode 100644 index 0000000..1460f7d --- /dev/null +++ b/test/fixtures/array_words_interp.rb @@ -0,0 +1,3 @@ +%W[foo #{bar}] + +%W[foo #{bar}foo#@baz] diff --git a/test/fixtures/asgn_cmd.rb b/test/fixtures/asgn_cmd.rb new file mode 100644 index 0000000..81f8cc1 --- /dev/null +++ b/test/fixtures/asgn_cmd.rb @@ -0,0 +1,3 @@ +foo = bar = m foo + +foo = m foo diff --git a/test/fixtures/asgn_mrhs.rb b/test/fixtures/asgn_mrhs.rb new file mode 100644 index 0000000..f0b0055 --- /dev/null +++ b/test/fixtures/asgn_mrhs.rb @@ -0,0 +1,5 @@ +foo = *bar + +foo = bar, 1 + +foo = baz, *bar diff --git a/test/fixtures/back_ref.rb b/test/fixtures/back_ref.rb new file mode 100644 index 0000000..03166e1 --- /dev/null +++ b/test/fixtures/back_ref.rb @@ -0,0 +1 @@ +$+ diff --git a/test/fixtures/bang.rb b/test/fixtures/bang.rb new file mode 100644 index 0000000..6cf9410 --- /dev/null +++ b/test/fixtures/bang.rb @@ -0,0 +1 @@ +!foo diff --git a/test/fixtures/bang_cmd.rb b/test/fixtures/bang_cmd.rb new file mode 100644 index 0000000..0a5252c --- /dev/null +++ b/test/fixtures/bang_cmd.rb @@ -0,0 +1 @@ +!m foo diff --git a/test/fixtures/begin_cmdarg.rb b/test/fixtures/begin_cmdarg.rb new file mode 100644 index 0000000..a587366 --- /dev/null +++ b/test/fixtures/begin_cmdarg.rb @@ -0,0 +1 @@ +p begin 1.times do 1 end end diff --git a/test/fixtures/beginless_erange_after_newline.rb b/test/fixtures/beginless_erange_after_newline.rb new file mode 100644 index 0000000..ae6c755 --- /dev/null +++ b/test/fixtures/beginless_erange_after_newline.rb @@ -0,0 +1,2 @@ +foo +...100 diff --git a/test/fixtures/beginless_irange_after_newline.rb b/test/fixtures/beginless_irange_after_newline.rb new file mode 100644 index 0000000..bfc8d5e --- /dev/null +++ b/test/fixtures/beginless_irange_after_newline.rb @@ -0,0 +1,2 @@ +foo +..100 diff --git a/test/fixtures/beginless_range.rb b/test/fixtures/beginless_range.rb new file mode 100644 index 0000000..ef52703 --- /dev/null +++ b/test/fixtures/beginless_range.rb @@ -0,0 +1,3 @@ +...100 + +..100 diff --git a/test/fixtures/blockarg.rb b/test/fixtures/blockarg.rb new file mode 100644 index 0000000..63552e9 --- /dev/null +++ b/test/fixtures/blockarg.rb @@ -0,0 +1 @@ +def f(&block); end diff --git a/test/fixtures/blockargs.rb b/test/fixtures/blockargs.rb new file mode 100644 index 0000000..cdd2c4f --- /dev/null +++ b/test/fixtures/blockargs.rb @@ -0,0 +1,71 @@ +f{ } + +f{ | | } + +f{ |&b| } + +f{ |**baz, &b| } + +f{ |*, &b| } + +f{ |*r, p, &b| } + +f{ |*s, &b| } + +f{ |*s| } + +f{ |*| } + +f{ |; +a +| } + +f{ |;a| } + +f{ |a, &b| } + +f{ |a, *, &b| } + +f{ |a, *r, p, &b| } + +f{ |a, *s, &b| } + +f{ |a, *s| } + +f{ |a, *| } + +f{ |a, b,| } + +f{ |a, c| } + +f{ |a, o=1, &b| } + +f{ |a, o=1, *r, p, &b| } + +f{ |a, o=1, o1=2, *r, &b| } + +f{ |a, o=1, p, &b| } + +f{ |a,| } + +f{ |a| } + +f{ |a| } + +f{ |a| } + +f{ |foo: 1, &b| } + +f{ |foo: 1, bar: 2, **baz, &b| } + +f{ |foo:| } + +f{ |o=1, &b| } + +f{ |o=1, *r, &b| } + +f{ |o=1, *r, p, &b| } + +f{ |o=1, p, &b| } + +f{ || } diff --git a/test/fixtures/break.rb b/test/fixtures/break.rb new file mode 100644 index 0000000..da51ec7 --- /dev/null +++ b/test/fixtures/break.rb @@ -0,0 +1,7 @@ +break + +break foo + +break() + +break(foo) diff --git a/test/fixtures/break_block.rb b/test/fixtures/break_block.rb new file mode 100644 index 0000000..4b58c58 --- /dev/null +++ b/test/fixtures/break_block.rb @@ -0,0 +1 @@ +break fun foo do end diff --git a/test/fixtures/bug_435.rb b/test/fixtures/bug_435.rb new file mode 100644 index 0000000..3e4e0d5 --- /dev/null +++ b/test/fixtures/bug_435.rb @@ -0,0 +1 @@ +"#{-> foo {}}" diff --git a/test/fixtures/bug_447.rb b/test/fixtures/bug_447.rb new file mode 100644 index 0000000..7da59bb --- /dev/null +++ b/test/fixtures/bug_447.rb @@ -0,0 +1,3 @@ +m [] do end + +m [], 1 do end diff --git a/test/fixtures/bug_452.rb b/test/fixtures/bug_452.rb new file mode 100644 index 0000000..8b41dd6 --- /dev/null +++ b/test/fixtures/bug_452.rb @@ -0,0 +1 @@ +td (1_500).toString(); td.num do; end diff --git a/test/fixtures/bug_466.rb b/test/fixtures/bug_466.rb new file mode 100644 index 0000000..ad02ad3 --- /dev/null +++ b/test/fixtures/bug_466.rb @@ -0,0 +1 @@ +foo "#{(1+1).to_i}" do; end diff --git a/test/fixtures/bug_473.rb b/test/fixtures/bug_473.rb new file mode 100644 index 0000000..0d2ea88 --- /dev/null +++ b/test/fixtures/bug_473.rb @@ -0,0 +1 @@ +m "#{[]}" diff --git a/test/fixtures/bug_480.rb b/test/fixtures/bug_480.rb new file mode 100644 index 0000000..0558b2c --- /dev/null +++ b/test/fixtures/bug_480.rb @@ -0,0 +1 @@ +m "#{}#{()}" diff --git a/test/fixtures/bug_481.rb b/test/fixtures/bug_481.rb new file mode 100644 index 0000000..6328e9d --- /dev/null +++ b/test/fixtures/bug_481.rb @@ -0,0 +1 @@ +m def x(); end; 1.tap do end diff --git a/test/fixtures/bug_ascii_8bit_in_literal.rb b/test/fixtures/bug_ascii_8bit_in_literal.rb new file mode 100644 index 0000000..85399bd --- /dev/null +++ b/test/fixtures/bug_ascii_8bit_in_literal.rb @@ -0,0 +1,2 @@ +# coding:utf-8 + "\xD0\xBF\xD1\x80\xD0\xBE\xD0\xB2\xD0\xB5\xD1\x80\xD0\xBA\xD0\xB0" diff --git a/test/fixtures/bug_cmd_string_lookahead.rb b/test/fixtures/bug_cmd_string_lookahead.rb new file mode 100644 index 0000000..7e9e54c --- /dev/null +++ b/test/fixtures/bug_cmd_string_lookahead.rb @@ -0,0 +1 @@ +desc "foo" do end diff --git a/test/fixtures/bug_cmdarg.rb b/test/fixtures/bug_cmdarg.rb new file mode 100644 index 0000000..0281cd6 --- /dev/null +++ b/test/fixtures/bug_cmdarg.rb @@ -0,0 +1,5 @@ +assert do: true + +assert dogs + +f x: -> do meth do end end diff --git a/test/fixtures/bug_def_no_paren_eql_begin.rb b/test/fixtures/bug_def_no_paren_eql_begin.rb new file mode 100644 index 0000000..615dc88 --- /dev/null +++ b/test/fixtures/bug_def_no_paren_eql_begin.rb @@ -0,0 +1,4 @@ +def foo +=begin +=end +end diff --git a/test/fixtures/bug_do_block_in_call_args.rb b/test/fixtures/bug_do_block_in_call_args.rb new file mode 100644 index 0000000..21340fd --- /dev/null +++ b/test/fixtures/bug_do_block_in_call_args.rb @@ -0,0 +1 @@ +bar def foo; self.each do end end diff --git a/test/fixtures/bug_do_block_in_cmdarg.rb b/test/fixtures/bug_do_block_in_cmdarg.rb new file mode 100644 index 0000000..7dece50 --- /dev/null +++ b/test/fixtures/bug_do_block_in_cmdarg.rb @@ -0,0 +1 @@ +tap (proc do end) diff --git a/test/fixtures/bug_do_block_in_hash_brace.rb b/test/fixtures/bug_do_block_in_hash_brace.rb new file mode 100644 index 0000000..6c4dd20 --- /dev/null +++ b/test/fixtures/bug_do_block_in_hash_brace.rb @@ -0,0 +1,9 @@ +p :foo, {"a": proc do end, b: proc do end} + +p :foo, {** proc do end, b: proc do end} + +p :foo, {:a => proc do end, b: proc do end} + +p :foo, {a: proc do end, b: proc do end} + +p :foo, {proc do end => proc do end, b: proc do end} diff --git a/test/fixtures/bug_heredoc_do.rb b/test/fixtures/bug_heredoc_do.rb new file mode 100644 index 0000000..06fef0a --- /dev/null +++ b/test/fixtures/bug_heredoc_do.rb @@ -0,0 +1,3 @@ +f <<-TABLE do +TABLE +end diff --git a/test/fixtures/bug_interp_single.rb b/test/fixtures/bug_interp_single.rb new file mode 100644 index 0000000..be0b1a8 --- /dev/null +++ b/test/fixtures/bug_interp_single.rb @@ -0,0 +1,3 @@ +"#{1}" + +%W"#{1}" diff --git a/test/fixtures/bug_lambda_leakage.rb b/test/fixtures/bug_lambda_leakage.rb new file mode 100644 index 0000000..372b369 --- /dev/null +++ b/test/fixtures/bug_lambda_leakage.rb @@ -0,0 +1 @@ +->(scope) {}; scope diff --git a/test/fixtures/bug_regex_verification.rb b/test/fixtures/bug_regex_verification.rb new file mode 100644 index 0000000..f8483c8 --- /dev/null +++ b/test/fixtures/bug_regex_verification.rb @@ -0,0 +1 @@ +/#)/x diff --git a/test/fixtures/bug_rescue_empty_else.rb b/test/fixtures/bug_rescue_empty_else.rb new file mode 100644 index 0000000..e8c81ed --- /dev/null +++ b/test/fixtures/bug_rescue_empty_else.rb @@ -0,0 +1 @@ +begin; rescue LoadError; else; end diff --git a/test/fixtures/bug_while_not_parens_do.rb b/test/fixtures/bug_while_not_parens_do.rb new file mode 100644 index 0000000..628c36e --- /dev/null +++ b/test/fixtures/bug_while_not_parens_do.rb @@ -0,0 +1 @@ +while not (true) do end diff --git a/test/fixtures/case_cond.rb b/test/fixtures/case_cond.rb new file mode 100644 index 0000000..a236b27 --- /dev/null +++ b/test/fixtures/case_cond.rb @@ -0,0 +1 @@ +case; when foo; 'foo'; end diff --git a/test/fixtures/case_cond_else.rb b/test/fixtures/case_cond_else.rb new file mode 100644 index 0000000..06eefa4 --- /dev/null +++ b/test/fixtures/case_cond_else.rb @@ -0,0 +1 @@ +case; when foo; 'foo'; else 'bar'; end diff --git a/test/fixtures/case_expr.rb b/test/fixtures/case_expr.rb new file mode 100644 index 0000000..472672c --- /dev/null +++ b/test/fixtures/case_expr.rb @@ -0,0 +1 @@ +case foo; when 'bar'; bar; end diff --git a/test/fixtures/case_expr_else.rb b/test/fixtures/case_expr_else.rb new file mode 100644 index 0000000..3c55826 --- /dev/null +++ b/test/fixtures/case_expr_else.rb @@ -0,0 +1 @@ +case foo; when 'bar'; bar; else baz; end diff --git a/test/fixtures/casgn_scoped.rb b/test/fixtures/casgn_scoped.rb new file mode 100644 index 0000000..964d0f4 --- /dev/null +++ b/test/fixtures/casgn_scoped.rb @@ -0,0 +1 @@ +Bar::Foo = 10 diff --git a/test/fixtures/casgn_toplevel.rb b/test/fixtures/casgn_toplevel.rb new file mode 100644 index 0000000..047a3b6 --- /dev/null +++ b/test/fixtures/casgn_toplevel.rb @@ -0,0 +1 @@ +::Foo = 10 diff --git a/test/fixtures/casgn_unscoped.rb b/test/fixtures/casgn_unscoped.rb new file mode 100644 index 0000000..5632cf6 --- /dev/null +++ b/test/fixtures/casgn_unscoped.rb @@ -0,0 +1 @@ +Foo = 10 diff --git a/test/fixtures/character.rb b/test/fixtures/character.rb new file mode 100644 index 0000000..b22ffbb --- /dev/null +++ b/test/fixtures/character.rb @@ -0,0 +1 @@ +?a diff --git a/test/fixtures/class.rb b/test/fixtures/class.rb new file mode 100644 index 0000000..a30a248 --- /dev/null +++ b/test/fixtures/class.rb @@ -0,0 +1,3 @@ +class Foo end + +class Foo; end diff --git a/test/fixtures/class_definition_in_while_cond.rb b/test/fixtures/class_definition_in_while_cond.rb new file mode 100644 index 0000000..1042731 --- /dev/null +++ b/test/fixtures/class_definition_in_while_cond.rb @@ -0,0 +1,7 @@ +while class << self; a = tap do end; end; break; end + +while class << self; tap do end; end; break; end + +while class Foo a = tap do end; end; break; end + +while class Foo; tap do end; end; break; end diff --git a/test/fixtures/class_super.rb b/test/fixtures/class_super.rb new file mode 100644 index 0000000..8829d82 --- /dev/null +++ b/test/fixtures/class_super.rb @@ -0,0 +1 @@ +class Foo < Bar; end diff --git a/test/fixtures/class_super_label.rb b/test/fixtures/class_super_label.rb new file mode 100644 index 0000000..5d47897 --- /dev/null +++ b/test/fixtures/class_super_label.rb @@ -0,0 +1 @@ +class Foo < a:b; end diff --git a/test/fixtures/comments_before_leading_dot__27.rb b/test/fixtures/comments_before_leading_dot__27.rb new file mode 100644 index 0000000..208f2d8 --- /dev/null +++ b/test/fixtures/comments_before_leading_dot__27.rb @@ -0,0 +1,19 @@ +a # + # +&.foo + + +a # + # +.foo + + +a # +# +&.foo + + +a # +# +.foo + diff --git a/test/fixtures/complex.rb b/test/fixtures/complex.rb new file mode 100644 index 0000000..1dbf2c1 --- /dev/null +++ b/test/fixtures/complex.rb @@ -0,0 +1,7 @@ +42.1i + +42.1ri + +42i + +42ri diff --git a/test/fixtures/cond_begin.rb b/test/fixtures/cond_begin.rb new file mode 100644 index 0000000..49d709b --- /dev/null +++ b/test/fixtures/cond_begin.rb @@ -0,0 +1 @@ +if (bar); foo; end diff --git a/test/fixtures/cond_begin_masgn.rb b/test/fixtures/cond_begin_masgn.rb new file mode 100644 index 0000000..f9b6502 --- /dev/null +++ b/test/fixtures/cond_begin_masgn.rb @@ -0,0 +1 @@ +if (bar; a, b = foo); end diff --git a/test/fixtures/cond_eflipflop.rb b/test/fixtures/cond_eflipflop.rb new file mode 100644 index 0000000..1236c2d --- /dev/null +++ b/test/fixtures/cond_eflipflop.rb @@ -0,0 +1,3 @@ +!(foo...bar) + +if foo...bar; end diff --git a/test/fixtures/cond_iflipflop.rb b/test/fixtures/cond_iflipflop.rb new file mode 100644 index 0000000..84bee71 --- /dev/null +++ b/test/fixtures/cond_iflipflop.rb @@ -0,0 +1,3 @@ +!(foo..bar) + +if foo..bar; end diff --git a/test/fixtures/cond_match_current_line.rb b/test/fixtures/cond_match_current_line.rb new file mode 100644 index 0000000..21878c7 --- /dev/null +++ b/test/fixtures/cond_match_current_line.rb @@ -0,0 +1,3 @@ +!/wat/ + +if /wat/; end diff --git a/test/fixtures/const_op_asgn.rb b/test/fixtures/const_op_asgn.rb new file mode 100644 index 0000000..e72e7ad --- /dev/null +++ b/test/fixtures/const_op_asgn.rb @@ -0,0 +1,9 @@ +::A += 1 + +A += 1 + +B::A += 1 + +def x; ::A ||= 1; end + +def x; self::A ||= 1; end diff --git a/test/fixtures/const_scoped.rb b/test/fixtures/const_scoped.rb new file mode 100644 index 0000000..4b03d85 --- /dev/null +++ b/test/fixtures/const_scoped.rb @@ -0,0 +1 @@ +Bar::Foo diff --git a/test/fixtures/const_toplevel.rb b/test/fixtures/const_toplevel.rb new file mode 100644 index 0000000..f783ae7 --- /dev/null +++ b/test/fixtures/const_toplevel.rb @@ -0,0 +1 @@ +::Foo diff --git a/test/fixtures/const_unscoped.rb b/test/fixtures/const_unscoped.rb new file mode 100644 index 0000000..bc56c4d --- /dev/null +++ b/test/fixtures/const_unscoped.rb @@ -0,0 +1 @@ +Foo diff --git a/test/fixtures/control_meta_escape_chars_in_regexp__since_31.rb b/test/fixtures/control_meta_escape_chars_in_regexp__since_31.rb new file mode 100644 index 0000000..99e9fa7 --- /dev/null +++ b/test/fixtures/control_meta_escape_chars_in_regexp__since_31.rb @@ -0,0 +1,13 @@ +/\C-\M-\xFF/ + +/\C-\xFF/ + +/\M-\C-\xFF/ + +/\M-\c\xFF/ + +/\M-\xFF/ + +/\c\M-\xFF/ + +/\c\xFF/ diff --git a/test/fixtures/cpath.rb b/test/fixtures/cpath.rb new file mode 100644 index 0000000..a404169 --- /dev/null +++ b/test/fixtures/cpath.rb @@ -0,0 +1,3 @@ +module ::Foo; end + +module Bar::Foo; end diff --git a/test/fixtures/cvar.rb b/test/fixtures/cvar.rb new file mode 100644 index 0000000..4997896 --- /dev/null +++ b/test/fixtures/cvar.rb @@ -0,0 +1 @@ +@@foo diff --git a/test/fixtures/cvasgn.rb b/test/fixtures/cvasgn.rb new file mode 100644 index 0000000..8f7e19c --- /dev/null +++ b/test/fixtures/cvasgn.rb @@ -0,0 +1 @@ +@@var = 10 diff --git a/test/fixtures/dedenting_heredoc.rb b/test/fixtures/dedenting_heredoc.rb new file mode 100644 index 0000000..84937d8 --- /dev/null +++ b/test/fixtures/dedenting_heredoc.rb @@ -0,0 +1,75 @@ +p <<~"E" + x + #{" y"} +E + +p <<~"E" + x + #{foo} +E + +p <<~E + x + y +E + +p <<~E + x + y +E + +p <<~E + x + y +E + +p <<~E + x + y +E + +p <<~E + x + \ y +E + +p <<~E + x + \ y +E + +p <<~E + E + +p <<~E + x + +y +E + +p <<~E + x + + y +E + +p <<~E + x + y +E + +p <<~E + x +E + +p <<~E + ð +E + +p <<~E +E + +p <<~`E` + x + #{foo} +E diff --git a/test/fixtures/dedenting_interpolating_heredoc_fake_line_continuation.rb b/test/fixtures/dedenting_interpolating_heredoc_fake_line_continuation.rb new file mode 100644 index 0000000..0427715 --- /dev/null +++ b/test/fixtures/dedenting_interpolating_heredoc_fake_line_continuation.rb @@ -0,0 +1,4 @@ +<<~'FOO' + baz\\ + qux +FOO diff --git a/test/fixtures/dedenting_non_interpolating_heredoc_line_continuation.rb b/test/fixtures/dedenting_non_interpolating_heredoc_line_continuation.rb new file mode 100644 index 0000000..fd7bc02 --- /dev/null +++ b/test/fixtures/dedenting_non_interpolating_heredoc_line_continuation.rb @@ -0,0 +1,4 @@ +<<~'FOO' + baz\ + qux +FOO diff --git a/test/fixtures/def.rb b/test/fixtures/def.rb new file mode 100644 index 0000000..d96a423 --- /dev/null +++ b/test/fixtures/def.rb @@ -0,0 +1,11 @@ +def BEGIN; end + +def END; end + +def String; end + +def String=; end + +def foo; end + +def until; end diff --git a/test/fixtures/defined.rb b/test/fixtures/defined.rb new file mode 100644 index 0000000..5cf93e2 --- /dev/null +++ b/test/fixtures/defined.rb @@ -0,0 +1,5 @@ +defined? @foo + +defined? foo + +defined?(foo) diff --git a/test/fixtures/defs.rb b/test/fixtures/defs.rb new file mode 100644 index 0000000..e0b7aa8 --- /dev/null +++ b/test/fixtures/defs.rb @@ -0,0 +1,9 @@ +def (foo).foo; end + +def String.foo; end + +def String::foo; end + +def self.foo; end + +def self::foo; end diff --git a/test/fixtures/empty_stmt.rb b/test/fixtures/empty_stmt.rb new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/test/fixtures/empty_stmt.rb @@ -0,0 +1 @@ + diff --git a/test/fixtures/endless_comparison_method.rb b/test/fixtures/endless_comparison_method.rb new file mode 100644 index 0000000..e10c3a6 --- /dev/null +++ b/test/fixtures/endless_comparison_method.rb @@ -0,0 +1,11 @@ +def !=(other) = do_something + +def !=(other) = do_something + +def <=(other) = do_something + +def ==(other) = do_something + +def ===(other) = do_something + +def >=(other) = do_something diff --git a/test/fixtures/endless_method.rb b/test/fixtures/endless_method.rb new file mode 100644 index 0000000..7002526 --- /dev/null +++ b/test/fixtures/endless_method.rb @@ -0,0 +1,7 @@ +def foo() = 42 + +def inc(x) = x + 1 + +def obj.foo() = 42 + +def obj.inc(x) = x + 1 diff --git a/test/fixtures/endless_method_command_syntax.rb b/test/fixtures/endless_method_command_syntax.rb new file mode 100644 index 0000000..d9dad2d --- /dev/null +++ b/test/fixtures/endless_method_command_syntax.rb @@ -0,0 +1,15 @@ +def foo = puts "Hello" + +def foo() = puts "Hello" + +def foo(x) = puts x + +def obj.foo = puts "Hello" + +def obj.foo() = puts "Hello" + +def obj.foo(x) = puts x + +def rescued(x) = raise "to be caught" rescue "instance #{x}" + +def self.rescued(x) = raise "to be caught" rescue "class #{x}" diff --git a/test/fixtures/endless_method_forwarded_args_legacy.rb b/test/fixtures/endless_method_forwarded_args_legacy.rb new file mode 100644 index 0000000..5955e40 --- /dev/null +++ b/test/fixtures/endless_method_forwarded_args_legacy.rb @@ -0,0 +1 @@ +def foo(...) = bar(...) diff --git a/test/fixtures/endless_method_with_rescue_mod.rb b/test/fixtures/endless_method_with_rescue_mod.rb new file mode 100644 index 0000000..93dc63a --- /dev/null +++ b/test/fixtures/endless_method_with_rescue_mod.rb @@ -0,0 +1,3 @@ +def m() = 1 rescue 2 + +def self.m() = 1 rescue 2 diff --git a/test/fixtures/endless_method_without_args.rb b/test/fixtures/endless_method_without_args.rb new file mode 100644 index 0000000..90ea8f7 --- /dev/null +++ b/test/fixtures/endless_method_without_args.rb @@ -0,0 +1,7 @@ +def foo = 42 + +def foo = 42 rescue nil + +def self.foo = 42 + +def self.foo = 42 rescue nil diff --git a/test/fixtures/ensure.rb b/test/fixtures/ensure.rb new file mode 100644 index 0000000..6c4b47c --- /dev/null +++ b/test/fixtures/ensure.rb @@ -0,0 +1 @@ +begin; meth; ensure; bar; end diff --git a/test/fixtures/ensure_empty.rb b/test/fixtures/ensure_empty.rb new file mode 100644 index 0000000..39a175c --- /dev/null +++ b/test/fixtures/ensure_empty.rb @@ -0,0 +1 @@ +begin ensure end diff --git a/test/fixtures/false.rb b/test/fixtures/false.rb new file mode 100644 index 0000000..c508d53 --- /dev/null +++ b/test/fixtures/false.rb @@ -0,0 +1 @@ +false diff --git a/test/fixtures/float.rb b/test/fixtures/float.rb new file mode 100644 index 0000000..8c7592a --- /dev/null +++ b/test/fixtures/float.rb @@ -0,0 +1,3 @@ +-1.33 + +1.33 diff --git a/test/fixtures/for.rb b/test/fixtures/for.rb new file mode 100644 index 0000000..a27ae57 --- /dev/null +++ b/test/fixtures/for.rb @@ -0,0 +1,3 @@ +for a in foo do p a; end + +for a in foo; p a; end diff --git a/test/fixtures/for_mlhs.rb b/test/fixtures/for_mlhs.rb new file mode 100644 index 0000000..53cd522 --- /dev/null +++ b/test/fixtures/for_mlhs.rb @@ -0,0 +1 @@ +for a, b in foo; p a, b; end diff --git a/test/fixtures/forward_arg.rb b/test/fixtures/forward_arg.rb new file mode 100644 index 0000000..c7590a8 --- /dev/null +++ b/test/fixtures/forward_arg.rb @@ -0,0 +1 @@ +def foo(...); bar(...); end diff --git a/test/fixtures/forward_arg_with_open_args.rb b/test/fixtures/forward_arg_with_open_args.rb new file mode 100644 index 0000000..fd4c06b --- /dev/null +++ b/test/fixtures/forward_arg_with_open_args.rb @@ -0,0 +1,27 @@ +(def foo ... + bar(...) +end) + +(def foo ...; bar(...); end) + +def foo ... +end + +def foo ...; bar(...); end + +def foo a, ... + bar(...) +end + +def foo a, ...; bar(...); end + +def foo a, b = 1, ... +end + +def foo b = 1, ... + bar(...) +end + +def foo b = 1, ...; bar(...); end + +def foo(a, ...) bar(...) end diff --git a/test/fixtures/forward_args_legacy.rb b/test/fixtures/forward_args_legacy.rb new file mode 100644 index 0000000..0d91624 --- /dev/null +++ b/test/fixtures/forward_args_legacy.rb @@ -0,0 +1,5 @@ +def foo(...); bar(...); end + +def foo(...); end + +def foo(...); super(...); end diff --git a/test/fixtures/forwarded_argument_with_kwrestarg.rb b/test/fixtures/forwarded_argument_with_kwrestarg.rb new file mode 100644 index 0000000..7dbf472 --- /dev/null +++ b/test/fixtures/forwarded_argument_with_kwrestarg.rb @@ -0,0 +1 @@ +def foo(argument, **); bar(argument, **); end diff --git a/test/fixtures/forwarded_argument_with_restarg.rb b/test/fixtures/forwarded_argument_with_restarg.rb new file mode 100644 index 0000000..f734bfd --- /dev/null +++ b/test/fixtures/forwarded_argument_with_restarg.rb @@ -0,0 +1 @@ +def foo(argument, *); bar(argument, *); end diff --git a/test/fixtures/forwarded_kwrestarg.rb b/test/fixtures/forwarded_kwrestarg.rb new file mode 100644 index 0000000..16cd8b2 --- /dev/null +++ b/test/fixtures/forwarded_kwrestarg.rb @@ -0,0 +1 @@ +def foo(**); bar(**); end diff --git a/test/fixtures/forwarded_kwrestarg_with_additional_kwarg.rb b/test/fixtures/forwarded_kwrestarg_with_additional_kwarg.rb new file mode 100644 index 0000000..52759b8 --- /dev/null +++ b/test/fixtures/forwarded_kwrestarg_with_additional_kwarg.rb @@ -0,0 +1 @@ +def foo(**); bar(**, from_foo: true); end diff --git a/test/fixtures/forwarded_restarg.rb b/test/fixtures/forwarded_restarg.rb new file mode 100644 index 0000000..65ac2cc --- /dev/null +++ b/test/fixtures/forwarded_restarg.rb @@ -0,0 +1 @@ +def foo(*); bar(*); end diff --git a/test/fixtures/gvar.rb b/test/fixtures/gvar.rb new file mode 100644 index 0000000..bbf1348 --- /dev/null +++ b/test/fixtures/gvar.rb @@ -0,0 +1 @@ +$foo diff --git a/test/fixtures/gvasgn.rb b/test/fixtures/gvasgn.rb new file mode 100644 index 0000000..2bcc22c --- /dev/null +++ b/test/fixtures/gvasgn.rb @@ -0,0 +1 @@ +$var = 10 diff --git a/test/fixtures/hash_empty.rb b/test/fixtures/hash_empty.rb new file mode 100644 index 0000000..ffcd441 --- /dev/null +++ b/test/fixtures/hash_empty.rb @@ -0,0 +1 @@ +{ } diff --git a/test/fixtures/hash_hashrocket.rb b/test/fixtures/hash_hashrocket.rb new file mode 100644 index 0000000..2cbb3bd --- /dev/null +++ b/test/fixtures/hash_hashrocket.rb @@ -0,0 +1,3 @@ +{ 1 => 2 } + +{ 1 => 2, :foo => "bar" } diff --git a/test/fixtures/hash_kwsplat.rb b/test/fixtures/hash_kwsplat.rb new file mode 100644 index 0000000..921aa97 --- /dev/null +++ b/test/fixtures/hash_kwsplat.rb @@ -0,0 +1 @@ +{ foo: 2, **bar } diff --git a/test/fixtures/hash_label.rb b/test/fixtures/hash_label.rb new file mode 100644 index 0000000..3aacae4 --- /dev/null +++ b/test/fixtures/hash_label.rb @@ -0,0 +1 @@ +{ foo: 2 } diff --git a/test/fixtures/hash_label_end.rb b/test/fixtures/hash_label_end.rb new file mode 100644 index 0000000..ac9f7c4 --- /dev/null +++ b/test/fixtures/hash_label_end.rb @@ -0,0 +1,5 @@ +f(a ? "a":1) + +{ 'foo': 2 } + +{ 'foo': 2, 'bar': {}} diff --git a/test/fixtures/hash_pair_value_omission.rb b/test/fixtures/hash_pair_value_omission.rb new file mode 100644 index 0000000..9d8ccb5 --- /dev/null +++ b/test/fixtures/hash_pair_value_omission.rb @@ -0,0 +1,5 @@ +{BAR:} + +{a:, b:} + +{puts:} diff --git a/test/fixtures/heredoc.rb b/test/fixtures/heredoc.rb new file mode 100644 index 0000000..1bfc963 --- /dev/null +++ b/test/fixtures/heredoc.rb @@ -0,0 +1,14 @@ +<<'HERE' +foo +bar +HERE + +<(**nil) {} + +def f(**nil); end + +m { |**nil| } diff --git a/test/fixtures/kwoptarg.rb b/test/fixtures/kwoptarg.rb new file mode 100644 index 0000000..dc3ce72 --- /dev/null +++ b/test/fixtures/kwoptarg.rb @@ -0,0 +1 @@ +def f(foo: 1); end diff --git a/test/fixtures/kwoptarg_with_kwrestarg_and_forwarded_args.rb b/test/fixtures/kwoptarg_with_kwrestarg_and_forwarded_args.rb new file mode 100644 index 0000000..99dcc72 --- /dev/null +++ b/test/fixtures/kwoptarg_with_kwrestarg_and_forwarded_args.rb @@ -0,0 +1 @@ +def f(a: nil, **); b(**) end diff --git a/test/fixtures/kwrestarg_named.rb b/test/fixtures/kwrestarg_named.rb new file mode 100644 index 0000000..e17a661 --- /dev/null +++ b/test/fixtures/kwrestarg_named.rb @@ -0,0 +1 @@ +def f(**foo); end diff --git a/test/fixtures/kwrestarg_unnamed.rb b/test/fixtures/kwrestarg_unnamed.rb new file mode 100644 index 0000000..1b26b1d --- /dev/null +++ b/test/fixtures/kwrestarg_unnamed.rb @@ -0,0 +1 @@ +def f(**); end diff --git a/test/fixtures/lbrace_arg_after_command_args.rb b/test/fixtures/lbrace_arg_after_command_args.rb new file mode 100644 index 0000000..277c200 --- /dev/null +++ b/test/fixtures/lbrace_arg_after_command_args.rb @@ -0,0 +1 @@ +let (:a) { m do; end } diff --git a/test/fixtures/lparenarg_after_lvar__since_25.rb b/test/fixtures/lparenarg_after_lvar__since_25.rb new file mode 100644 index 0000000..dc3a98b --- /dev/null +++ b/test/fixtures/lparenarg_after_lvar__since_25.rb @@ -0,0 +1,3 @@ +foo (-1.3).abs + +meth (-1.3).abs diff --git a/test/fixtures/lvar.rb b/test/fixtures/lvar.rb new file mode 100644 index 0000000..257cc56 --- /dev/null +++ b/test/fixtures/lvar.rb @@ -0,0 +1 @@ +foo diff --git a/test/fixtures/lvar_injecting_match.rb b/test/fixtures/lvar_injecting_match.rb new file mode 100644 index 0000000..ba814a1 --- /dev/null +++ b/test/fixtures/lvar_injecting_match.rb @@ -0,0 +1 @@ +/(?bar)/ =~ 'bar'; match diff --git a/test/fixtures/lvasgn.rb b/test/fixtures/lvasgn.rb new file mode 100644 index 0000000..330b8ef --- /dev/null +++ b/test/fixtures/lvasgn.rb @@ -0,0 +1 @@ +var = 10; var diff --git a/test/fixtures/masgn.rb b/test/fixtures/masgn.rb new file mode 100644 index 0000000..0321242 --- /dev/null +++ b/test/fixtures/masgn.rb @@ -0,0 +1,5 @@ +(foo, bar) = 1, 2 + +foo, bar = 1, 2 + +foo, bar, baz = 1, 2 diff --git a/test/fixtures/masgn_attr.rb b/test/fixtures/masgn_attr.rb new file mode 100644 index 0000000..91a703e --- /dev/null +++ b/test/fixtures/masgn_attr.rb @@ -0,0 +1,5 @@ +self.A, foo = foo + +self.a, self[1, 2] = foo + +self::a, foo = foo diff --git a/test/fixtures/masgn_cmd.rb b/test/fixtures/masgn_cmd.rb new file mode 100644 index 0000000..18e096f --- /dev/null +++ b/test/fixtures/masgn_cmd.rb @@ -0,0 +1 @@ +foo, bar = m foo diff --git a/test/fixtures/masgn_const.rb b/test/fixtures/masgn_const.rb new file mode 100644 index 0000000..3b6fba5 --- /dev/null +++ b/test/fixtures/masgn_const.rb @@ -0,0 +1,3 @@ +::A, foo = foo + +self::A, foo = foo diff --git a/test/fixtures/masgn_nested.rb b/test/fixtures/masgn_nested.rb new file mode 100644 index 0000000..a1ccf4e --- /dev/null +++ b/test/fixtures/masgn_nested.rb @@ -0,0 +1,3 @@ +((b, )) = foo + +a, (b, c) = foo diff --git a/test/fixtures/masgn_splat.rb b/test/fixtures/masgn_splat.rb new file mode 100644 index 0000000..a15dab1 --- /dev/null +++ b/test/fixtures/masgn_splat.rb @@ -0,0 +1,19 @@ +* = bar + +*, c, d = bar + +*b = bar + +*b, c = bar + +@foo, @@bar = *foo + +a, * = bar + +a, *, c = bar + +a, *b = bar + +a, *b, c = bar + +a, b = *foo, bar diff --git a/test/fixtures/method_definition_in_while_cond.rb b/test/fixtures/method_definition_in_while_cond.rb new file mode 100644 index 0000000..6ec3890 --- /dev/null +++ b/test/fixtures/method_definition_in_while_cond.rb @@ -0,0 +1,7 @@ +while def foo a = tap do end; end; break; end + +while def foo; tap do end; end; break; end + +while def self.foo a = tap do end; end; break; end + +while def self.foo; tap do end; end; break; end diff --git a/test/fixtures/module.rb b/test/fixtures/module.rb new file mode 100644 index 0000000..f999df3 --- /dev/null +++ b/test/fixtures/module.rb @@ -0,0 +1 @@ +module Foo; end diff --git a/test/fixtures/multiple_pattern_matches.rb b/test/fixtures/multiple_pattern_matches.rb new file mode 100644 index 0000000..54a4bb4 --- /dev/null +++ b/test/fixtures/multiple_pattern_matches.rb @@ -0,0 +1,5 @@ +{a: 0} => a: +{a: 0} => a: + +{a: 0} in a: +{a: 0} in a: diff --git a/test/fixtures/newline_in_hash_argument.rb b/test/fixtures/newline_in_hash_argument.rb new file mode 100644 index 0000000..1681844 --- /dev/null +++ b/test/fixtures/newline_in_hash_argument.rb @@ -0,0 +1,14 @@ +case foo +in a: +0 +true +in "b": +0 +true +end + +obj.set "foo": +1 + +obj.set foo: +1 diff --git a/test/fixtures/next.rb b/test/fixtures/next.rb new file mode 100644 index 0000000..7556ac2 --- /dev/null +++ b/test/fixtures/next.rb @@ -0,0 +1,7 @@ +next + +next foo + +next() + +next(foo) diff --git a/test/fixtures/next_block.rb b/test/fixtures/next_block.rb new file mode 100644 index 0000000..d3b51df --- /dev/null +++ b/test/fixtures/next_block.rb @@ -0,0 +1 @@ +next fun foo do end diff --git a/test/fixtures/nil.rb b/test/fixtures/nil.rb new file mode 100644 index 0000000..607602c --- /dev/null +++ b/test/fixtures/nil.rb @@ -0,0 +1 @@ +nil diff --git a/test/fixtures/nil_expression.rb b/test/fixtures/nil_expression.rb new file mode 100644 index 0000000..aabf53f --- /dev/null +++ b/test/fixtures/nil_expression.rb @@ -0,0 +1,3 @@ +() + +begin end diff --git a/test/fixtures/non_lvar_injecting_match.rb b/test/fixtures/non_lvar_injecting_match.rb new file mode 100644 index 0000000..f1eb7d3 --- /dev/null +++ b/test/fixtures/non_lvar_injecting_match.rb @@ -0,0 +1 @@ +/#{1}(?bar)/ =~ 'bar' diff --git a/test/fixtures/not.rb b/test/fixtures/not.rb new file mode 100644 index 0000000..d87f68f --- /dev/null +++ b/test/fixtures/not.rb @@ -0,0 +1,5 @@ +not foo + +not() + +not(foo) diff --git a/test/fixtures/not_cmd.rb b/test/fixtures/not_cmd.rb new file mode 100644 index 0000000..685ec20 --- /dev/null +++ b/test/fixtures/not_cmd.rb @@ -0,0 +1 @@ +not m foo diff --git a/test/fixtures/not_masgn__24.rb b/test/fixtures/not_masgn__24.rb new file mode 100644 index 0000000..cb93b91 --- /dev/null +++ b/test/fixtures/not_masgn__24.rb @@ -0,0 +1 @@ +!(a, b = foo) diff --git a/test/fixtures/nth_ref.rb b/test/fixtures/nth_ref.rb new file mode 100644 index 0000000..16ef65b --- /dev/null +++ b/test/fixtures/nth_ref.rb @@ -0,0 +1 @@ +$10 diff --git a/test/fixtures/numbered_args_after_27.rb b/test/fixtures/numbered_args_after_27.rb new file mode 100644 index 0000000..96fe7a3 --- /dev/null +++ b/test/fixtures/numbered_args_after_27.rb @@ -0,0 +1,7 @@ +-> do _1 + _9 end + +-> { _1 + _9} + +m do _1 + _9 end + +m { _1 + _9 } diff --git a/test/fixtures/numparam_outside_block.rb b/test/fixtures/numparam_outside_block.rb new file mode 100644 index 0000000..37cbce1 --- /dev/null +++ b/test/fixtures/numparam_outside_block.rb @@ -0,0 +1,9 @@ +_1 + +class << foo; _1; end + +class A; _1; end + +def self.m; _1; end + +module A; _1; end diff --git a/test/fixtures/op_asgn.rb b/test/fixtures/op_asgn.rb new file mode 100644 index 0000000..a5a28b1 --- /dev/null +++ b/test/fixtures/op_asgn.rb @@ -0,0 +1,5 @@ +foo.A += 1 + +foo.a += 1 + +foo::a += 1 diff --git a/test/fixtures/op_asgn_cmd.rb b/test/fixtures/op_asgn_cmd.rb new file mode 100644 index 0000000..017aa9b --- /dev/null +++ b/test/fixtures/op_asgn_cmd.rb @@ -0,0 +1,7 @@ +foo.A += m foo + +foo.a += m foo + +foo::A += m foo + +foo::a += m foo diff --git a/test/fixtures/op_asgn_index.rb b/test/fixtures/op_asgn_index.rb new file mode 100644 index 0000000..92cfb22 --- /dev/null +++ b/test/fixtures/op_asgn_index.rb @@ -0,0 +1 @@ +foo[0, 1] += 2 diff --git a/test/fixtures/op_asgn_index_cmd.rb b/test/fixtures/op_asgn_index_cmd.rb new file mode 100644 index 0000000..161b244 --- /dev/null +++ b/test/fixtures/op_asgn_index_cmd.rb @@ -0,0 +1 @@ +foo[0, 1] += m foo diff --git a/test/fixtures/optarg.rb b/test/fixtures/optarg.rb new file mode 100644 index 0000000..9d60609 --- /dev/null +++ b/test/fixtures/optarg.rb @@ -0,0 +1,3 @@ +def f foo = 1; end + +def f(foo=1, bar=2); end diff --git a/test/fixtures/or.rb b/test/fixtures/or.rb new file mode 100644 index 0000000..c2042eb --- /dev/null +++ b/test/fixtures/or.rb @@ -0,0 +1,3 @@ +foo or bar + +foo || bar diff --git a/test/fixtures/or_asgn.rb b/test/fixtures/or_asgn.rb new file mode 100644 index 0000000..6e4ecc9 --- /dev/null +++ b/test/fixtures/or_asgn.rb @@ -0,0 +1,3 @@ +foo.a ||= 1 + +foo[0, 1] ||= 2 diff --git a/test/fixtures/parser_bug_272.rb b/test/fixtures/parser_bug_272.rb new file mode 100644 index 0000000..2f2f2b8 --- /dev/null +++ b/test/fixtures/parser_bug_272.rb @@ -0,0 +1 @@ +a @b do |c|;end diff --git a/test/fixtures/parser_bug_490.rb b/test/fixtures/parser_bug_490.rb new file mode 100644 index 0000000..cf544b1 --- /dev/null +++ b/test/fixtures/parser_bug_490.rb @@ -0,0 +1,5 @@ +def m; class << self; A = nil; end; end + +def m; class << self; class C; end; end; end + +def m; class << self; module M; end; end; end diff --git a/test/fixtures/parser_bug_507.rb b/test/fixtures/parser_bug_507.rb new file mode 100644 index 0000000..bf616b8 --- /dev/null +++ b/test/fixtures/parser_bug_507.rb @@ -0,0 +1 @@ +m = -> *args do end diff --git a/test/fixtures/parser_bug_518.rb b/test/fixtures/parser_bug_518.rb new file mode 100644 index 0000000..22f4afe --- /dev/null +++ b/test/fixtures/parser_bug_518.rb @@ -0,0 +1,2 @@ +class A < B +end diff --git a/test/fixtures/parser_bug_525.rb b/test/fixtures/parser_bug_525.rb new file mode 100644 index 0000000..59d0e73 --- /dev/null +++ b/test/fixtures/parser_bug_525.rb @@ -0,0 +1 @@ +m1 :k => m2 do; m3() do end; end diff --git a/test/fixtures/parser_bug_604.rb b/test/fixtures/parser_bug_604.rb new file mode 100644 index 0000000..7eb91c2 --- /dev/null +++ b/test/fixtures/parser_bug_604.rb @@ -0,0 +1 @@ +m a + b do end diff --git a/test/fixtures/parser_bug_640.rb b/test/fixtures/parser_bug_640.rb new file mode 100644 index 0000000..fb62ded --- /dev/null +++ b/test/fixtures/parser_bug_640.rb @@ -0,0 +1,4 @@ +<<~FOO + baz\ + qux +FOO diff --git a/test/fixtures/parser_bug_645.rb b/test/fixtures/parser_bug_645.rb new file mode 100644 index 0000000..cb1e5a0 --- /dev/null +++ b/test/fixtures/parser_bug_645.rb @@ -0,0 +1 @@ +-> (arg={}) {} diff --git a/test/fixtures/parser_bug_830.rb b/test/fixtures/parser_bug_830.rb new file mode 100644 index 0000000..e5865e9 --- /dev/null +++ b/test/fixtures/parser_bug_830.rb @@ -0,0 +1 @@ +/\(/ diff --git a/test/fixtures/parser_drops_truncated_parts_of_squiggly_heredoc.rb b/test/fixtures/parser_drops_truncated_parts_of_squiggly_heredoc.rb new file mode 100644 index 0000000..bddae8e --- /dev/null +++ b/test/fixtures/parser_drops_truncated_parts_of_squiggly_heredoc.rb @@ -0,0 +1,3 @@ +<<~HERE + #{} +HERE diff --git a/test/fixtures/parser_slash_slash_n_escaping_in_literals.rb b/test/fixtures/parser_slash_slash_n_escaping_in_literals.rb new file mode 100644 index 0000000..564cebd --- /dev/null +++ b/test/fixtures/parser_slash_slash_n_escaping_in_literals.rb @@ -0,0 +1,62 @@ +"a\ +b" + +%I{a\ +b} + +%Q{a\ +b} + +%W{a\ +b} + +%i{a\ +b} + +%q{a\ +b} + +%r{a\ +b} + +%s{a\ +b} + +%w{a\ +b} + +%x{a\ +b} + +%{a\ +b} + +'a\ +b' + +/a\ +b/ + +:"a\ +b" + +:'a\ +b' + +<<-"HERE" +a\ +b +HERE + +<<-'HERE' +a\ +b +HERE + +<<-`HERE` +a\ +b +HERE + +`a\ +b` diff --git a/test/fixtures/pattern_match.rb b/test/fixtures/pattern_match.rb new file mode 100644 index 0000000..6464d95 --- /dev/null +++ b/test/fixtures/pattern_match.rb @@ -0,0 +1,175 @@ +case foo; + in a: {b:}, c: + p c + ; end + +case foo; + in {Foo: 42 + } + false + ; end + +case foo; + in {a: + 2} + false + ; end + +case foo; + in {a: + } + true + ; end + +case foo; + in {a: 1 + } + false + ; end + +case foo; in "#{ %Q{a} }": 1 then true; end + +case foo; in "#{ %Q{a} }": then true; end + +case foo; in "#{ %q{a} }": 1 then true; end + +case foo; in "#{ %q{a} }": then true; end + +case foo; in "#{ 'a' }": 1 then true; end + +case foo; in "#{ 'a' }": then true; end + +case foo; in "a": 1 then true; end + +case foo; in "a": then true; end + +case foo; in (1) then true; end + +case foo; in * then nil; end + +case foo; in ** then true; end + +case foo; in **a then true; end + +case foo; in **nil then true; end + +case foo; in *, 42, * then true; end + +case foo; in *x then nil; end + +case foo; in *x, y, z then nil; end + +case foo; in ->{ 42 } then true; end + +case foo; in ...2 then true; end + +case foo; in ..2 then true; end + +case foo; in 1 => a then true; end + +case foo; in 1 | 2 then true; end + +case foo; in 1, "a", [], {} then nil; end + +case foo; in 1.. then true; end + +case foo; in 1... then true; end + +case foo; in 1...2 then true; end + +case foo; in 1..2 then true; end + +case foo; in 1; end + +case foo; in ::A then true; end + +case foo; in A then true; end + +case foo; in A() then true; end + +case foo; in A(1, 2) then true; end + +case foo; in A(x:) then true; end + +case foo; in A::B then true; end + +case foo; in A[1, 2] then true; end + +case foo; in A[] then true; end + +case foo; in A[x:] then true; end + +case foo; in Array[*, 1, *] then true; end + +case foo; in String(*, 1, *) then true; end + +case foo; in [*, x] then true; end + +case foo; in [*x, 1 => a, *y] then true; end + +case foo; in [*x, y] then true; end + +case foo; in [x, *, y] then true; end + +case foo; in [x, *y, z] then true; end + +case foo; in [x, y, *] then true; end + +case foo; in [x, y, *z] then true; end + +case foo; in [x, y,] then true; end + +case foo; in [x, y] then true; end + +case foo; in [x,] then nil; end + +case foo; in [x] then nil; end + +case foo; in ^$TestPatternMatching; end + +case foo; in ^(0+0) then nil; end + +case foo; in ^(1 +); end + +case foo; in ^(42) then nil; end + +case foo; in ^@@TestPatternMatching; end + +case foo; in ^@a; end + +case foo; in ^foo then nil; end + +case foo; in a: 1 then true; end + +case foo; in a: 1, _a:, ** then true; end + +case foo; in a: 1, b: 2 then true; end + +case foo; in a: then true; end + +case foo; in a:, b: then true; end + +case foo; in self then true; end + +case foo; in x if true; nil; end + +case foo; in x then x; end + +case foo; in x unless true; nil; end + +case foo; in x, *y, z then nil; end + +case foo; in x, then nil; end + +case foo; in x, y then nil; end + +case foo; in x, y, then nil; end + +case foo; in { a: 1 } then true; end + +case foo; in { a: 1, } then true; end + +case foo; in { foo: ^(42) } then nil; end + +case foo; in {} then true; end diff --git a/test/fixtures/pattern_matching__FILE__LINE_literals.rb b/test/fixtures/pattern_matching__FILE__LINE_literals.rb new file mode 100644 index 0000000..fe0edae --- /dev/null +++ b/test/fixtures/pattern_matching__FILE__LINE_literals.rb @@ -0,0 +1,4 @@ + case [__FILE__, __LINE__ + 1, __ENCODING__] + in [__FILE__, __LINE__, __ENCODING__] + end + diff --git a/test/fixtures/pattern_matching_blank_else.rb b/test/fixtures/pattern_matching_blank_else.rb new file mode 100644 index 0000000..6bf059a --- /dev/null +++ b/test/fixtures/pattern_matching_blank_else.rb @@ -0,0 +1 @@ +case 1; in 2; 3; else; end diff --git a/test/fixtures/pattern_matching_else.rb b/test/fixtures/pattern_matching_else.rb new file mode 100644 index 0000000..29f14c9 --- /dev/null +++ b/test/fixtures/pattern_matching_else.rb @@ -0,0 +1 @@ +case 1; in 2; 3; else; 4; end diff --git a/test/fixtures/pattern_matching_single_line.rb b/test/fixtures/pattern_matching_single_line.rb new file mode 100644 index 0000000..12279af --- /dev/null +++ b/test/fixtures/pattern_matching_single_line.rb @@ -0,0 +1,3 @@ +1 => [a]; a + +1 in [a]; a diff --git a/test/fixtures/pattern_matching_single_line_allowed_omission_of_parentheses.rb b/test/fixtures/pattern_matching_single_line_allowed_omission_of_parentheses.rb new file mode 100644 index 0000000..1e42933 --- /dev/null +++ b/test/fixtures/pattern_matching_single_line_allowed_omission_of_parentheses.rb @@ -0,0 +1,11 @@ +[1, 2] => a, b; a + +[1, 2] in a, b; a + +{a: 1} => a:; a + +{a: 1} in a:; a + +{key: :value} => key: value; value + +{key: :value} in key: value; value diff --git a/test/fixtures/postexe.rb b/test/fixtures/postexe.rb new file mode 100644 index 0000000..baee33a --- /dev/null +++ b/test/fixtures/postexe.rb @@ -0,0 +1 @@ +END { 1 } diff --git a/test/fixtures/preexe.rb b/test/fixtures/preexe.rb new file mode 100644 index 0000000..9e802f3 --- /dev/null +++ b/test/fixtures/preexe.rb @@ -0,0 +1 @@ +BEGIN { 1 } diff --git a/test/fixtures/procarg0.rb b/test/fixtures/procarg0.rb new file mode 100644 index 0000000..74cae2c --- /dev/null +++ b/test/fixtures/procarg0.rb @@ -0,0 +1,3 @@ +m { |(foo, bar)| } + +m { |foo| } diff --git a/test/fixtures/range_endless.rb b/test/fixtures/range_endless.rb new file mode 100644 index 0000000..9894d40 --- /dev/null +++ b/test/fixtures/range_endless.rb @@ -0,0 +1,3 @@ +1.. + +1... diff --git a/test/fixtures/range_exclusive.rb b/test/fixtures/range_exclusive.rb new file mode 100644 index 0000000..9e07fae --- /dev/null +++ b/test/fixtures/range_exclusive.rb @@ -0,0 +1 @@ +1...2 diff --git a/test/fixtures/range_inclusive.rb b/test/fixtures/range_inclusive.rb new file mode 100644 index 0000000..8c12abf --- /dev/null +++ b/test/fixtures/range_inclusive.rb @@ -0,0 +1 @@ +1..2 diff --git a/test/fixtures/rational.rb b/test/fixtures/rational.rb new file mode 100644 index 0000000..e11cacc --- /dev/null +++ b/test/fixtures/rational.rb @@ -0,0 +1,3 @@ +42.1r + +42r diff --git a/test/fixtures/redo.rb b/test/fixtures/redo.rb new file mode 100644 index 0000000..f49789c --- /dev/null +++ b/test/fixtures/redo.rb @@ -0,0 +1 @@ +redo diff --git a/test/fixtures/regex_interp.rb b/test/fixtures/regex_interp.rb new file mode 100644 index 0000000..f9ad7fc --- /dev/null +++ b/test/fixtures/regex_interp.rb @@ -0,0 +1 @@ +/foo#{bar}baz/ diff --git a/test/fixtures/regex_plain.rb b/test/fixtures/regex_plain.rb new file mode 100644 index 0000000..b86faec --- /dev/null +++ b/test/fixtures/regex_plain.rb @@ -0,0 +1 @@ +/source/im diff --git a/test/fixtures/resbody_list.rb b/test/fixtures/resbody_list.rb new file mode 100644 index 0000000..e40d45f --- /dev/null +++ b/test/fixtures/resbody_list.rb @@ -0,0 +1 @@ +begin; meth; rescue Exception; bar; end diff --git a/test/fixtures/resbody_list_mrhs.rb b/test/fixtures/resbody_list_mrhs.rb new file mode 100644 index 0000000..92b8bb2 --- /dev/null +++ b/test/fixtures/resbody_list_mrhs.rb @@ -0,0 +1 @@ +begin; meth; rescue Exception, foo; bar; end diff --git a/test/fixtures/resbody_list_var.rb b/test/fixtures/resbody_list_var.rb new file mode 100644 index 0000000..0a2fb90 --- /dev/null +++ b/test/fixtures/resbody_list_var.rb @@ -0,0 +1 @@ +begin; meth; rescue foo => ex; bar; end diff --git a/test/fixtures/resbody_var.rb b/test/fixtures/resbody_var.rb new file mode 100644 index 0000000..2104ac5 --- /dev/null +++ b/test/fixtures/resbody_var.rb @@ -0,0 +1,3 @@ +begin; meth; rescue => @ex; bar; end + +begin; meth; rescue => ex; bar; end diff --git a/test/fixtures/rescue.rb b/test/fixtures/rescue.rb new file mode 100644 index 0000000..2d3be9d --- /dev/null +++ b/test/fixtures/rescue.rb @@ -0,0 +1 @@ +begin; meth; rescue; foo; end diff --git a/test/fixtures/rescue_else.rb b/test/fixtures/rescue_else.rb new file mode 100644 index 0000000..a22f8d1 --- /dev/null +++ b/test/fixtures/rescue_else.rb @@ -0,0 +1 @@ +begin; meth; rescue; foo; else; bar; end diff --git a/test/fixtures/rescue_else_ensure.rb b/test/fixtures/rescue_else_ensure.rb new file mode 100644 index 0000000..167eee1 --- /dev/null +++ b/test/fixtures/rescue_else_ensure.rb @@ -0,0 +1 @@ +begin; meth; rescue; baz; else foo; ensure; bar end diff --git a/test/fixtures/rescue_ensure.rb b/test/fixtures/rescue_ensure.rb new file mode 100644 index 0000000..8237257 --- /dev/null +++ b/test/fixtures/rescue_ensure.rb @@ -0,0 +1 @@ +begin; meth; rescue; baz; ensure; bar; end diff --git a/test/fixtures/rescue_in_lambda_block.rb b/test/fixtures/rescue_in_lambda_block.rb new file mode 100644 index 0000000..ccd8ed7 --- /dev/null +++ b/test/fixtures/rescue_in_lambda_block.rb @@ -0,0 +1 @@ +-> do rescue; end diff --git a/test/fixtures/rescue_mod.rb b/test/fixtures/rescue_mod.rb new file mode 100644 index 0000000..06375d3 --- /dev/null +++ b/test/fixtures/rescue_mod.rb @@ -0,0 +1 @@ +meth rescue bar diff --git a/test/fixtures/rescue_mod_asgn.rb b/test/fixtures/rescue_mod_asgn.rb new file mode 100644 index 0000000..abf7cd9 --- /dev/null +++ b/test/fixtures/rescue_mod_asgn.rb @@ -0,0 +1 @@ +foo = meth rescue bar diff --git a/test/fixtures/rescue_mod_masgn.rb b/test/fixtures/rescue_mod_masgn.rb new file mode 100644 index 0000000..0716eb1 --- /dev/null +++ b/test/fixtures/rescue_mod_masgn.rb @@ -0,0 +1 @@ +foo, bar = meth rescue [1, 2] diff --git a/test/fixtures/rescue_mod_op_assign.rb b/test/fixtures/rescue_mod_op_assign.rb new file mode 100644 index 0000000..178efa3 --- /dev/null +++ b/test/fixtures/rescue_mod_op_assign.rb @@ -0,0 +1 @@ +foo += meth rescue bar diff --git a/test/fixtures/rescue_without_begin_end.rb b/test/fixtures/rescue_without_begin_end.rb new file mode 100644 index 0000000..8416569 --- /dev/null +++ b/test/fixtures/rescue_without_begin_end.rb @@ -0,0 +1 @@ +meth do; foo; rescue; bar; end diff --git a/test/fixtures/restarg_named.rb b/test/fixtures/restarg_named.rb new file mode 100644 index 0000000..355cd8f --- /dev/null +++ b/test/fixtures/restarg_named.rb @@ -0,0 +1 @@ +def f(*foo); end diff --git a/test/fixtures/restarg_unnamed.rb b/test/fixtures/restarg_unnamed.rb new file mode 100644 index 0000000..c9932dd --- /dev/null +++ b/test/fixtures/restarg_unnamed.rb @@ -0,0 +1 @@ +def f(*); end diff --git a/test/fixtures/retry.rb b/test/fixtures/retry.rb new file mode 100644 index 0000000..77428f7 --- /dev/null +++ b/test/fixtures/retry.rb @@ -0,0 +1 @@ +retry diff --git a/test/fixtures/return.rb b/test/fixtures/return.rb new file mode 100644 index 0000000..e3d966b --- /dev/null +++ b/test/fixtures/return.rb @@ -0,0 +1,7 @@ +return + +return foo + +return() + +return(foo) diff --git a/test/fixtures/return_block.rb b/test/fixtures/return_block.rb new file mode 100644 index 0000000..00723a7 --- /dev/null +++ b/test/fixtures/return_block.rb @@ -0,0 +1 @@ +return fun foo do end diff --git a/test/fixtures/ruby_bug_10279.rb b/test/fixtures/ruby_bug_10279.rb new file mode 100644 index 0000000..4d0fb21 --- /dev/null +++ b/test/fixtures/ruby_bug_10279.rb @@ -0,0 +1 @@ +{a: if true then 42 end} diff --git a/test/fixtures/ruby_bug_10653.rb b/test/fixtures/ruby_bug_10653.rb new file mode 100644 index 0000000..51354a1 --- /dev/null +++ b/test/fixtures/ruby_bug_10653.rb @@ -0,0 +1,5 @@ +false ? raise do end : tap do end + +false ? raise {} : tap {} + +true ? 1.tap do |n| p n end : 0 diff --git a/test/fixtures/ruby_bug_11107.rb b/test/fixtures/ruby_bug_11107.rb new file mode 100644 index 0000000..1f28cb0 --- /dev/null +++ b/test/fixtures/ruby_bug_11107.rb @@ -0,0 +1 @@ +p ->() do a() do end end diff --git a/test/fixtures/ruby_bug_11380.rb b/test/fixtures/ruby_bug_11380.rb new file mode 100644 index 0000000..1631548 --- /dev/null +++ b/test/fixtures/ruby_bug_11380.rb @@ -0,0 +1 @@ +p -> { :hello }, a: 1 do end diff --git a/test/fixtures/ruby_bug_11873.rb b/test/fixtures/ruby_bug_11873.rb new file mode 100644 index 0000000..a25aa9e --- /dev/null +++ b/test/fixtures/ruby_bug_11873.rb @@ -0,0 +1,23 @@ +a b(c d), "x" do end + +a b(c d), /x/ do end + +a b(c d), /x/m do end + +a b(c(d)), "x" do end + +a b(c(d)), /x/ do end + +a b(c(d)), /x/m do end + +a b{c d}, "x" do end + +a b{c d}, /x/ do end + +a b{c d}, /x/m do end + +a b{c(d)}, "x" do end + +a b{c(d)}, /x/ do end + +a b{c(d)}, /x/m do end diff --git a/test/fixtures/ruby_bug_11873_a.rb b/test/fixtures/ruby_bug_11873_a.rb new file mode 100644 index 0000000..1856235 --- /dev/null +++ b/test/fixtures/ruby_bug_11873_a.rb @@ -0,0 +1,39 @@ +a b(c d), 1 do end + +a b(c d), 1.0 do end + +a b(c d), 1.0i do end + +a b(c d), 1.0r do end + +a b(c d), :e do end + +a b(c(d)), 1 do end + +a b(c(d)), 1.0 do end + +a b(c(d)), 1.0i do end + +a b(c(d)), 1.0r do end + +a b(c(d)), :e do end + +a b{c d}, 1 do end + +a b{c d}, 1.0 do end + +a b{c d}, 1.0i do end + +a b{c d}, 1.0r do end + +a b{c d}, :e do end + +a b{c(d)}, 1 do end + +a b{c(d)}, 1.0 do end + +a b{c(d)}, 1.0i do end + +a b{c(d)}, 1.0r do end + +a b{c(d)}, :e do end diff --git a/test/fixtures/ruby_bug_11873_b.rb b/test/fixtures/ruby_bug_11873_b.rb new file mode 100644 index 0000000..1b86662 --- /dev/null +++ b/test/fixtures/ruby_bug_11873_b.rb @@ -0,0 +1 @@ +p p{p(p);p p}, tap do end diff --git a/test/fixtures/ruby_bug_11989.rb b/test/fixtures/ruby_bug_11989.rb new file mode 100644 index 0000000..d49b861 --- /dev/null +++ b/test/fixtures/ruby_bug_11989.rb @@ -0,0 +1,3 @@ +p <<~"E" + x\n y +E diff --git a/test/fixtures/ruby_bug_11990.rb b/test/fixtures/ruby_bug_11990.rb new file mode 100644 index 0000000..d0fe7b2 --- /dev/null +++ b/test/fixtures/ruby_bug_11990.rb @@ -0,0 +1,3 @@ +p <<~E " y" + x +E diff --git a/test/fixtures/ruby_bug_12073.rb b/test/fixtures/ruby_bug_12073.rb new file mode 100644 index 0000000..b2e3784 --- /dev/null +++ b/test/fixtures/ruby_bug_12073.rb @@ -0,0 +1,3 @@ +a = 1; a b: 1 + +def foo raise; raise A::B, ''; end diff --git a/test/fixtures/ruby_bug_12402.rb b/test/fixtures/ruby_bug_12402.rb new file mode 100644 index 0000000..060d5d9 --- /dev/null +++ b/test/fixtures/ruby_bug_12402.rb @@ -0,0 +1,27 @@ +foo += raise bar rescue nil + +foo += raise(bar) rescue nil + +foo = raise bar rescue nil + +foo = raise(bar) rescue nil + +foo.C += raise bar rescue nil + +foo.C += raise(bar) rescue nil + +foo.m += raise bar rescue nil + +foo.m += raise(bar) rescue nil + +foo::C ||= raise bar rescue nil + +foo::C ||= raise(bar) rescue nil + +foo::m += raise bar rescue nil + +foo::m += raise(bar) rescue nil + +foo[0] += raise bar rescue nil + +foo[0] += raise(bar) rescue nil diff --git a/test/fixtures/ruby_bug_12669.rb b/test/fixtures/ruby_bug_12669.rb new file mode 100644 index 0000000..cd89689 --- /dev/null +++ b/test/fixtures/ruby_bug_12669.rb @@ -0,0 +1,7 @@ +a += b += raise :x + +a += b = raise :x + +a = b += raise :x + +a = b = raise :x diff --git a/test/fixtures/ruby_bug_12686.rb b/test/fixtures/ruby_bug_12686.rb new file mode 100644 index 0000000..7742e79 --- /dev/null +++ b/test/fixtures/ruby_bug_12686.rb @@ -0,0 +1 @@ +f (g rescue nil) diff --git a/test/fixtures/ruby_bug_13547.rb b/test/fixtures/ruby_bug_13547.rb new file mode 100644 index 0000000..29eafc3 --- /dev/null +++ b/test/fixtures/ruby_bug_13547.rb @@ -0,0 +1 @@ +meth[] {} diff --git a/test/fixtures/ruby_bug_14690.rb b/test/fixtures/ruby_bug_14690.rb new file mode 100644 index 0000000..b73b1d8 --- /dev/null +++ b/test/fixtures/ruby_bug_14690.rb @@ -0,0 +1 @@ +let () { m(a) do; end } diff --git a/test/fixtures/ruby_bug_15789.rb b/test/fixtures/ruby_bug_15789.rb new file mode 100644 index 0000000..6324db5 --- /dev/null +++ b/test/fixtures/ruby_bug_15789.rb @@ -0,0 +1,3 @@ +m ->(a = ->{_1}) {a} + +m ->(a: ->{_1}) {a} diff --git a/test/fixtures/ruby_bug_9669.rb b/test/fixtures/ruby_bug_9669.rb new file mode 100644 index 0000000..60dfa09 --- /dev/null +++ b/test/fixtures/ruby_bug_9669.rb @@ -0,0 +1,8 @@ +def a b: +return +end + +o = { +a: +1 +} diff --git a/test/fixtures/sclass.rb b/test/fixtures/sclass.rb new file mode 100644 index 0000000..e6aadae --- /dev/null +++ b/test/fixtures/sclass.rb @@ -0,0 +1 @@ +class << foo; nil; end diff --git a/test/fixtures/self.rb b/test/fixtures/self.rb new file mode 100644 index 0000000..31f9efa --- /dev/null +++ b/test/fixtures/self.rb @@ -0,0 +1 @@ +self diff --git a/test/fixtures/send_attr_asgn.rb b/test/fixtures/send_attr_asgn.rb new file mode 100644 index 0000000..b477966 --- /dev/null +++ b/test/fixtures/send_attr_asgn.rb @@ -0,0 +1,7 @@ +foo.A = 1 + +foo.a = 1 + +foo::A = 1 + +foo::a = 1 diff --git a/test/fixtures/send_attr_asgn_conditional.rb b/test/fixtures/send_attr_asgn_conditional.rb new file mode 100644 index 0000000..1279e02 --- /dev/null +++ b/test/fixtures/send_attr_asgn_conditional.rb @@ -0,0 +1 @@ +a&.b = 1 diff --git a/test/fixtures/send_binary_op.rb b/test/fixtures/send_binary_op.rb new file mode 100644 index 0000000..3e3e930 --- /dev/null +++ b/test/fixtures/send_binary_op.rb @@ -0,0 +1,41 @@ +foo != 1 + +foo !~ 1 + +foo % 1 + +foo & 1 + +foo * 1 + +foo ** 1 + +foo + 1 + +foo - 1 + +foo / 1 + +foo < 1 + +foo << 1 + +foo <= 1 + +foo <=> 1 + +foo == 1 + +foo === 1 + +foo =~ 1 + +foo > 1 + +foo >= 1 + +foo >> 1 + +foo ^ 1 + +foo | 1 diff --git a/test/fixtures/send_block_chain_cmd.rb b/test/fixtures/send_block_chain_cmd.rb new file mode 100644 index 0000000..c6fe1aa --- /dev/null +++ b/test/fixtures/send_block_chain_cmd.rb @@ -0,0 +1,13 @@ +meth 1 do end.fun bar + +meth 1 do end.fun bar do end + +meth 1 do end.fun {} + +meth 1 do end.fun(bar) + +meth 1 do end.fun(bar) {} + +meth 1 do end::fun bar + +meth 1 do end::fun(bar) diff --git a/test/fixtures/send_block_conditional.rb b/test/fixtures/send_block_conditional.rb new file mode 100644 index 0000000..dcc8361 --- /dev/null +++ b/test/fixtures/send_block_conditional.rb @@ -0,0 +1 @@ +foo&.bar {} diff --git a/test/fixtures/send_call.rb b/test/fixtures/send_call.rb new file mode 100644 index 0000000..9970127 --- /dev/null +++ b/test/fixtures/send_call.rb @@ -0,0 +1,3 @@ +foo.(1) + +foo::(1) diff --git a/test/fixtures/send_conditional.rb b/test/fixtures/send_conditional.rb new file mode 100644 index 0000000..8ecd27e --- /dev/null +++ b/test/fixtures/send_conditional.rb @@ -0,0 +1 @@ +a&.b diff --git a/test/fixtures/send_index.rb b/test/fixtures/send_index.rb new file mode 100644 index 0000000..f9c4daf --- /dev/null +++ b/test/fixtures/send_index.rb @@ -0,0 +1 @@ +foo[1, 2] diff --git a/test/fixtures/send_index_asgn.rb b/test/fixtures/send_index_asgn.rb new file mode 100644 index 0000000..e232fa3 --- /dev/null +++ b/test/fixtures/send_index_asgn.rb @@ -0,0 +1 @@ +foo[1, 2] = 3 diff --git a/test/fixtures/send_index_asgn_legacy.rb b/test/fixtures/send_index_asgn_legacy.rb new file mode 100644 index 0000000..e232fa3 --- /dev/null +++ b/test/fixtures/send_index_asgn_legacy.rb @@ -0,0 +1 @@ +foo[1, 2] = 3 diff --git a/test/fixtures/send_index_cmd.rb b/test/fixtures/send_index_cmd.rb new file mode 100644 index 0000000..32090e7 --- /dev/null +++ b/test/fixtures/send_index_cmd.rb @@ -0,0 +1 @@ +foo[m bar] diff --git a/test/fixtures/send_index_legacy.rb b/test/fixtures/send_index_legacy.rb new file mode 100644 index 0000000..f9c4daf --- /dev/null +++ b/test/fixtures/send_index_legacy.rb @@ -0,0 +1 @@ +foo[1, 2] diff --git a/test/fixtures/send_lambda.rb b/test/fixtures/send_lambda.rb new file mode 100644 index 0000000..eadd6c9 --- /dev/null +++ b/test/fixtures/send_lambda.rb @@ -0,0 +1,5 @@ +-> * { } + +-> do end + +->{ } diff --git a/test/fixtures/send_lambda_args.rb b/test/fixtures/send_lambda_args.rb new file mode 100644 index 0000000..68392f2 --- /dev/null +++ b/test/fixtures/send_lambda_args.rb @@ -0,0 +1,3 @@ +-> (a) { } + +->(a) { } diff --git a/test/fixtures/send_lambda_args_noparen.rb b/test/fixtures/send_lambda_args_noparen.rb new file mode 100644 index 0000000..c0ae077 --- /dev/null +++ b/test/fixtures/send_lambda_args_noparen.rb @@ -0,0 +1,3 @@ +-> a: 1 { } + +-> a: { } diff --git a/test/fixtures/send_lambda_args_shadow.rb b/test/fixtures/send_lambda_args_shadow.rb new file mode 100644 index 0000000..230f35a --- /dev/null +++ b/test/fixtures/send_lambda_args_shadow.rb @@ -0,0 +1 @@ +->(a; foo, bar) { } diff --git a/test/fixtures/send_lambda_legacy.rb b/test/fixtures/send_lambda_legacy.rb new file mode 100644 index 0000000..a509407 --- /dev/null +++ b/test/fixtures/send_lambda_legacy.rb @@ -0,0 +1 @@ +->{ } diff --git a/test/fixtures/send_op_asgn_conditional.rb b/test/fixtures/send_op_asgn_conditional.rb new file mode 100644 index 0000000..906088d --- /dev/null +++ b/test/fixtures/send_op_asgn_conditional.rb @@ -0,0 +1 @@ +a&.b &&= 1 diff --git a/test/fixtures/send_plain.rb b/test/fixtures/send_plain.rb new file mode 100644 index 0000000..ebaf1d1 --- /dev/null +++ b/test/fixtures/send_plain.rb @@ -0,0 +1,5 @@ +foo.fun + +foo::Fun() + +foo::fun diff --git a/test/fixtures/send_plain_cmd.rb b/test/fixtures/send_plain_cmd.rb new file mode 100644 index 0000000..e3fd63f --- /dev/null +++ b/test/fixtures/send_plain_cmd.rb @@ -0,0 +1,5 @@ +foo.fun bar + +foo::Fun bar + +foo::fun bar diff --git a/test/fixtures/send_self.rb b/test/fixtures/send_self.rb new file mode 100644 index 0000000..f084b9b --- /dev/null +++ b/test/fixtures/send_self.rb @@ -0,0 +1,5 @@ +fun + +fun! + +fun(1) diff --git a/test/fixtures/send_self_block.rb b/test/fixtures/send_self_block.rb new file mode 100644 index 0000000..1cd6703 --- /dev/null +++ b/test/fixtures/send_self_block.rb @@ -0,0 +1,7 @@ +fun do end + +fun { } + +fun() { } + +fun(1) { } diff --git a/test/fixtures/send_unary_op.rb b/test/fixtures/send_unary_op.rb new file mode 100644 index 0000000..73814d1 --- /dev/null +++ b/test/fixtures/send_unary_op.rb @@ -0,0 +1,5 @@ ++foo + +-foo + +~foo diff --git a/test/fixtures/slash_newline_in_heredocs.rb b/test/fixtures/slash_newline_in_heredocs.rb new file mode 100644 index 0000000..4962a05 --- /dev/null +++ b/test/fixtures/slash_newline_in_heredocs.rb @@ -0,0 +1,13 @@ +<<-E + 1 \ + 2 + 3 +E + + +<<~E + 1 \ + 2 + 3 +E + diff --git a/test/fixtures/space_args_arg.rb b/test/fixtures/space_args_arg.rb new file mode 100644 index 0000000..47957cb --- /dev/null +++ b/test/fixtures/space_args_arg.rb @@ -0,0 +1 @@ +fun (1) diff --git a/test/fixtures/space_args_arg_block.rb b/test/fixtures/space_args_arg_block.rb new file mode 100644 index 0000000..5560a82 --- /dev/null +++ b/test/fixtures/space_args_arg_block.rb @@ -0,0 +1,5 @@ +foo.fun (1) {} + +foo::fun (1) {} + +fun (1) {} diff --git a/test/fixtures/space_args_arg_call.rb b/test/fixtures/space_args_arg_call.rb new file mode 100644 index 0000000..3b0ae83 --- /dev/null +++ b/test/fixtures/space_args_arg_call.rb @@ -0,0 +1 @@ +fun (1).to_i diff --git a/test/fixtures/space_args_arg_newline.rb b/test/fixtures/space_args_arg_newline.rb new file mode 100644 index 0000000..a6cdac6 --- /dev/null +++ b/test/fixtures/space_args_arg_newline.rb @@ -0,0 +1,2 @@ +fun (1 +) diff --git a/test/fixtures/space_args_block.rb b/test/fixtures/space_args_block.rb new file mode 100644 index 0000000..555a097 --- /dev/null +++ b/test/fixtures/space_args_block.rb @@ -0,0 +1 @@ +fun () {} diff --git a/test/fixtures/space_args_cmd.rb b/test/fixtures/space_args_cmd.rb new file mode 100644 index 0000000..a749695 --- /dev/null +++ b/test/fixtures/space_args_cmd.rb @@ -0,0 +1 @@ +fun (f bar) diff --git a/test/fixtures/string___FILE__.rb b/test/fixtures/string___FILE__.rb new file mode 100644 index 0000000..4815727 --- /dev/null +++ b/test/fixtures/string___FILE__.rb @@ -0,0 +1 @@ +__FILE__ diff --git a/test/fixtures/string_concat.rb b/test/fixtures/string_concat.rb new file mode 100644 index 0000000..30cc4f8 --- /dev/null +++ b/test/fixtures/string_concat.rb @@ -0,0 +1 @@ +"foo#@a" "bar" diff --git a/test/fixtures/string_dvar.rb b/test/fixtures/string_dvar.rb new file mode 100644 index 0000000..bbe5b61 --- /dev/null +++ b/test/fixtures/string_dvar.rb @@ -0,0 +1 @@ +"#@a #@@a #$a" diff --git a/test/fixtures/string_interp.rb b/test/fixtures/string_interp.rb new file mode 100644 index 0000000..5fdd803 --- /dev/null +++ b/test/fixtures/string_interp.rb @@ -0,0 +1 @@ +"foo#{bar}baz" diff --git a/test/fixtures/string_plain.rb b/test/fixtures/string_plain.rb new file mode 100644 index 0000000..4aca78d --- /dev/null +++ b/test/fixtures/string_plain.rb @@ -0,0 +1,3 @@ +%q(foobar) + +'foobar' diff --git a/test/fixtures/super.rb b/test/fixtures/super.rb new file mode 100644 index 0000000..9e68a9e --- /dev/null +++ b/test/fixtures/super.rb @@ -0,0 +1,5 @@ +super foo + +super() + +super(foo) diff --git a/test/fixtures/super_block.rb b/test/fixtures/super_block.rb new file mode 100644 index 0000000..05a7d7f --- /dev/null +++ b/test/fixtures/super_block.rb @@ -0,0 +1,3 @@ +super do end + +super foo, bar do end diff --git a/test/fixtures/symbol_interp.rb b/test/fixtures/symbol_interp.rb new file mode 100644 index 0000000..d5011b2 --- /dev/null +++ b/test/fixtures/symbol_interp.rb @@ -0,0 +1 @@ +:"foo#{bar}baz" diff --git a/test/fixtures/symbol_plain.rb b/test/fixtures/symbol_plain.rb new file mode 100644 index 0000000..fd1fd00 --- /dev/null +++ b/test/fixtures/symbol_plain.rb @@ -0,0 +1,3 @@ +:'foo' + +:foo diff --git a/test/fixtures/ternary.rb b/test/fixtures/ternary.rb new file mode 100644 index 0000000..3a149d4 --- /dev/null +++ b/test/fixtures/ternary.rb @@ -0,0 +1 @@ +foo ? 1 : 2 diff --git a/test/fixtures/ternary_ambiguous_symbol.rb b/test/fixtures/ternary_ambiguous_symbol.rb new file mode 100644 index 0000000..19aa523 --- /dev/null +++ b/test/fixtures/ternary_ambiguous_symbol.rb @@ -0,0 +1 @@ +t=1;(foo)?t:T diff --git a/test/fixtures/trailing_forward_arg.rb b/test/fixtures/trailing_forward_arg.rb new file mode 100644 index 0000000..043870a --- /dev/null +++ b/test/fixtures/trailing_forward_arg.rb @@ -0,0 +1 @@ +def foo(a, b, ...); bar(a, 42, ...); end diff --git a/test/fixtures/true.rb b/test/fixtures/true.rb new file mode 100644 index 0000000..27ba77d --- /dev/null +++ b/test/fixtures/true.rb @@ -0,0 +1 @@ +true diff --git a/test/fixtures/unary_num_pow_precedence.rb b/test/fixtures/unary_num_pow_precedence.rb new file mode 100644 index 0000000..f0343e3 --- /dev/null +++ b/test/fixtures/unary_num_pow_precedence.rb @@ -0,0 +1,5 @@ ++2.0 ** 10 + +-2 ** 10 + +-2.0 ** 10 diff --git a/test/fixtures/undef.rb b/test/fixtures/undef.rb new file mode 100644 index 0000000..3e88ec7 --- /dev/null +++ b/test/fixtures/undef.rb @@ -0,0 +1 @@ +undef foo, :bar, :"foo#{1}" diff --git a/test/fixtures/unless.rb b/test/fixtures/unless.rb new file mode 100644 index 0000000..d04043e --- /dev/null +++ b/test/fixtures/unless.rb @@ -0,0 +1,3 @@ +unless foo then bar; end + +unless foo; bar; end diff --git a/test/fixtures/unless_else.rb b/test/fixtures/unless_else.rb new file mode 100644 index 0000000..8243d42 --- /dev/null +++ b/test/fixtures/unless_else.rb @@ -0,0 +1,3 @@ +unless foo then bar; else baz; end + +unless foo; bar; else baz; end diff --git a/test/fixtures/unless_mod.rb b/test/fixtures/unless_mod.rb new file mode 100644 index 0000000..2d0376a --- /dev/null +++ b/test/fixtures/unless_mod.rb @@ -0,0 +1 @@ +bar unless foo diff --git a/test/fixtures/until.rb b/test/fixtures/until.rb new file mode 100644 index 0000000..0608223 --- /dev/null +++ b/test/fixtures/until.rb @@ -0,0 +1,3 @@ +until foo do meth end + +until foo; meth end diff --git a/test/fixtures/until_mod.rb b/test/fixtures/until_mod.rb new file mode 100644 index 0000000..46a85d2 --- /dev/null +++ b/test/fixtures/until_mod.rb @@ -0,0 +1 @@ +meth until foo diff --git a/test/fixtures/until_post.rb b/test/fixtures/until_post.rb new file mode 100644 index 0000000..988e43b --- /dev/null +++ b/test/fixtures/until_post.rb @@ -0,0 +1 @@ +begin meth end until foo diff --git a/test/fixtures/var_and_asgn.rb b/test/fixtures/var_and_asgn.rb new file mode 100644 index 0000000..2550296 --- /dev/null +++ b/test/fixtures/var_and_asgn.rb @@ -0,0 +1 @@ +a &&= 1 diff --git a/test/fixtures/var_op_asgn.rb b/test/fixtures/var_op_asgn.rb new file mode 100644 index 0000000..402d818 --- /dev/null +++ b/test/fixtures/var_op_asgn.rb @@ -0,0 +1,7 @@ +@@var |= 10 + +@a |= 1 + +a += 1 + +def a; @@var |= 10; end diff --git a/test/fixtures/var_op_asgn_cmd.rb b/test/fixtures/var_op_asgn_cmd.rb new file mode 100644 index 0000000..33f4bc0 --- /dev/null +++ b/test/fixtures/var_op_asgn_cmd.rb @@ -0,0 +1 @@ +foo += m foo diff --git a/test/fixtures/var_or_asgn.rb b/test/fixtures/var_or_asgn.rb new file mode 100644 index 0000000..aa30b3d --- /dev/null +++ b/test/fixtures/var_or_asgn.rb @@ -0,0 +1 @@ +a ||= 1 diff --git a/test/fixtures/when_multi.rb b/test/fixtures/when_multi.rb new file mode 100644 index 0000000..b4fbd33 --- /dev/null +++ b/test/fixtures/when_multi.rb @@ -0,0 +1 @@ +case foo; when 'bar', 'baz'; bar; end diff --git a/test/fixtures/when_splat.rb b/test/fixtures/when_splat.rb new file mode 100644 index 0000000..695e5da --- /dev/null +++ b/test/fixtures/when_splat.rb @@ -0,0 +1 @@ +case foo; when 1, *baz; bar; when *foo; end diff --git a/test/fixtures/when_then.rb b/test/fixtures/when_then.rb new file mode 100644 index 0000000..6329345 --- /dev/null +++ b/test/fixtures/when_then.rb @@ -0,0 +1 @@ +case foo; when 'bar' then bar; end diff --git a/test/fixtures/while.rb b/test/fixtures/while.rb new file mode 100644 index 0000000..28b204f --- /dev/null +++ b/test/fixtures/while.rb @@ -0,0 +1,3 @@ +while foo do meth end + +while foo; meth end diff --git a/test/fixtures/while_mod.rb b/test/fixtures/while_mod.rb new file mode 100644 index 0000000..ce3cf01 --- /dev/null +++ b/test/fixtures/while_mod.rb @@ -0,0 +1 @@ +meth while foo diff --git a/test/fixtures/while_post.rb b/test/fixtures/while_post.rb new file mode 100644 index 0000000..ac6e050 --- /dev/null +++ b/test/fixtures/while_post.rb @@ -0,0 +1 @@ +begin meth end while foo diff --git a/test/fixtures/xstring_interp.rb b/test/fixtures/xstring_interp.rb new file mode 100644 index 0000000..dfede81 --- /dev/null +++ b/test/fixtures/xstring_interp.rb @@ -0,0 +1 @@ +`foo#{bar}baz` diff --git a/test/fixtures/xstring_plain.rb b/test/fixtures/xstring_plain.rb new file mode 100644 index 0000000..fce2550 --- /dev/null +++ b/test/fixtures/xstring_plain.rb @@ -0,0 +1 @@ +`foobar` diff --git a/test/fixtures/yield.rb b/test/fixtures/yield.rb new file mode 100644 index 0000000..0ecf639 --- /dev/null +++ b/test/fixtures/yield.rb @@ -0,0 +1,7 @@ +yield + +yield foo + +yield() + +yield(foo) diff --git a/test/fixtures/zsuper.rb b/test/fixtures/zsuper.rb new file mode 100644 index 0000000..16f5c2d --- /dev/null +++ b/test/fixtures/zsuper.rb @@ -0,0 +1 @@ +super diff --git a/test/yarp_test.rb b/test/yarp_test.rb new file mode 100644 index 0000000..02aba6a --- /dev/null +++ b/test/yarp_test.rb @@ -0,0 +1,63 @@ +# frozen_string_literal: true + +require "bundler/setup" +require "test/unit" + +$:.unshift(File.expand_path("../lib", __dir__)) +require "parser/yarp" +require "parser/current" + +# First, opt in to every AST feature. +Parser::Builders::Default.modernize + +# Modify the source map == check so that it doesn't check against the node +# itself so we don't get into a recursive loop. +Parser::Source::Map.prepend( + Module.new { + def ==(other) + self.class == other.class && + (instance_variables - %i[@node]).map do |ivar| + instance_variable_get(ivar) == other.instance_variable_get(ivar) + end.reduce(:&) + end + } +) + +# Next, ensure that we're comparing the nodes and also comparing the source +# ranges so that we're getting all of the necessary information. +Parser::AST::Node.prepend( + Module.new { + def ==(other) + super && (location == other.location) + end + } +) + +class YARPTest < Test::Unit::TestCase + Dir[File.expand_path("fixtures/*.rb", __dir__)].each do |filepath| + define_method("test_#{filepath}") { assert_parses(filepath) } + end + + private + + def assert_parses(filepath) + parser = Parser::CurrentRuby.default_parser + parser.diagnostics.consumer = ->(*) {} + parser.diagnostics.all_errors_are_fatal = true + + buffer = Parser::Source::Buffer.new(filepath, 1) + buffer.source = File.read(filepath) + + expected = parser.parse(buffer) + actual = Parser::YARP.parse(buffer) + queue = [[expected, actual]] + + while (left, right = queue.shift) + assert_equal(left.location, right.location) + + left.children.zip(right.children).each do |left_child, right_child| + queue << [left_child, right_child] if left_child.is_a?(Parser::AST::Node) + end + end + end +end