summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2022-12-26 13:10:36 -0800
committerTakashi Kokubun <takashikkbn@gmail.com>2022-12-26 13:10:37 -0800
commitd5985049c7a0907f2f00388d29fc0f499adf09f2 (patch)
treedfbbeb5c913eb86ed61f503cc16b948ec9e09455
parentd01bcf378bf39e4a9da2fab85f5f589b218c3080 (diff)
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.
-rw-r--r--test/irb/test_cmd.rb44
-rw-r--r--test/irb/test_ruby_lex.rb63
2 files changed, 63 insertions, 44 deletions
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)