diff --git a/test/irb/test_cmd.rb b/test/irb/test_cmd.rb index 908edc3349..719a2bbf8f 100644 --- a/test/irb/test_cmd.rb +++ b/test/irb/test_cmd.rb @@ -376,50 +376,6 @@ module TestIRB assert_match(/Please specify the file name./, out) end - def test_help - IRB.init_config(nil) - input = TestInputMethod.new([ - "help 'String#gsub'\n", - "\n", - ]) - IRB.conf[:PROMPT_MODE] = :SIMPLE - IRB.conf[:VERBOSE] = false - irb = IRB::Irb.new(IRB::WorkSpace.new(self), input) - out, err = capture_output do - irb.eval_input - end - - # the former is what we'd get without document content installed, like on CI - # the latter is what we may get locally - possible_rdoc_output = [/Nothing known about String#gsub/, /Returns a copy of self with all occurrences of the given pattern/] - assert(possible_rdoc_output.any? { |output| output.match?(out) }, "Expect the help command to match one of the possible outputs") - ensure - # this is the only way to reset the redefined method without coupling the test with its implementation - load "irb/cmd/help.rb" - end - - def test_help_without_rdoc - IRB.init_config(nil) - input = TestInputMethod.new([ - "help 'String#gsub'\n", - "\n", - ]) - IRB.conf[:PROMPT_MODE] = :SIMPLE - IRB.conf[:VERBOSE] = false - irb = IRB::Irb.new(IRB::WorkSpace.new(self), input) - out, err = capture_output do - without_rdoc do - irb.eval_input - end - end - - # if it fails to require rdoc, it only returns the command object - assert_match(/=> IRB::ExtendCommand::Help\n/, out) - ensure - # this is the only way to reset the redefined method without coupling the test with its implementation - load "irb/cmd/help.rb" - end - def test_irb_load File.write("#{@tmpdir}/a.rb", "a = 'hi'\n") out, err = execute_lines( diff --git a/test/irb/test_ruby_lex.rb b/test/irb/test_ruby_lex.rb index fa68a4632c..7802ffb4a6 100644 --- a/test/irb/test_ruby_lex.rb +++ b/test/irb/test_ruby_lex.rb @@ -706,6 +706,69 @@ module TestIRB end end + def test_corresponding_token_depth_with_heredoc_and_embdoc + reference_code = <<~EOC.chomp + if true + hello + p( + ) + EOC + code_with_heredoc = <<~EOC.chomp + if true + <<~A + A + p( + ) + EOC + code_with_embdoc = <<~EOC.chomp + if true + =begin + =end + p( + ) + EOC + [reference_code, code_with_heredoc, code_with_embdoc].each do |code| + lex = RubyLex.new + lines = code.lines + lex.instance_variable_set('@tokens', RubyLex.ripper_lex_without_warning(code)) + assert_equal 2, lex.check_corresponding_token_depth(lines, lines.size) + end + end + + def test_find_prev_spaces_with_multiline_literal + lex = RubyLex.new + reference_code = <<~EOC.chomp + if true + 1 + hello + 1 + world + end + EOC + code_with_percent_string = <<~EOC.chomp + if true + %w[ + hello + ] + world + end + EOC + code_with_quoted_string = <<~EOC.chomp + if true + ' + hello + ' + world + end + EOC + [reference_code, code_with_percent_string, code_with_quoted_string].each do |code| + lex = RubyLex.new + lex.instance_variable_set('@tokens', RubyLex.ripper_lex_without_warning(code)) + prev_spaces = (1..code.lines.size).map { |index| lex.find_prev_spaces index } + assert_equal [0, 2, 2, 2, 2, 0], prev_spaces + end + end + private def build_context(local_variables = nil)