Sync IRB master: tool/sync_default_gems.rb irb

It looks like tool/sync_default_gems.rb is not capable of cherry-picking
commits from ruby/irb. I just executed `tool/sync_default_gems.rb irb`
to fix the sync status.

I'm not sure if what's the cause. It could be related to some diff that
doesn't exist in ruby/ruby, or it might be related to non-linear history
due to merge commits. For next time, I'd like to at least exclude the
second possibility, so I disabled merge commits in ruby/irb.
This commit is contained in:
Takashi Kokubun 2022-12-26 13:10:36 -08:00
parent d01bcf378b
commit d5985049c7
2 changed files with 63 additions and 44 deletions

View File

@ -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(

View File

@ -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)