summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2019-04-27 22:01:10 +0900
committerTakashi Kokubun <takashikkbn@gmail.com>2019-04-27 22:01:11 +0900
commit9348643575d7a744f3e404d9069a0d29f97960a0 (patch)
tree67bf06991e296298aed64d544effddc3e48148ea
parent3f9562015e651735bfc2fdd14e8f6963b673e22a (diff)
make sync-default-gems GEM=irb
Synced from https://github.com/ruby/irb/commit/5feb361ed80736efa5b2c2b629837ec2a5fc2cdb. This includes a support to colorize named Class instance on IRB inspect.
-rw-r--r--lib/irb/color.rb4
-rw-r--r--test/irb/test_color.rb5
-rw-r--r--test/irb/test_completion.rb2
-rw-r--r--test/irb/test_option.rb2
-rw-r--r--test/irb/test_raise_no_backtrace_exception.rb2
5 files changed, 10 insertions, 5 deletions
diff --git a/lib/irb/color.rb b/lib/irb/color.rb
index 2e7a3e8bab..201aecac30 100644
--- a/lib/irb/color.rb
+++ b/lib/irb/color.rb
@@ -46,6 +46,10 @@ module IRB # :nodoc:
end
def inspect_colorable?(obj)
+ if obj.is_a?(Class) && obj.name
+ return true
+ end
+
case obj
when Hash
obj.all? { |k, v| inspect_colorable?(k) && inspect_colorable?(v) }
diff --git a/test/irb/test_color.rb b/test/irb/test_color.rb
index 8439fd54f5..8a59374691 100644
--- a/test/irb/test_color.rb
+++ b/test/irb/test_color.rb
@@ -30,7 +30,7 @@ module TestIRB
"# comment" => "#{BLUE}#{BOLD}# comment#{CLEAR}",
"yield(hello)" => "#{GREEN}yield#{CLEAR}(hello)",
}.each do |code, result|
- assert_equal(result, with_term { IRB::Color.colorize_code(code) })
+ assert_equal(result, with_term { IRB::Color.colorize_code(code) }, "Case: colorize_code(#{code.dump})")
end
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6.0')
@@ -54,10 +54,11 @@ module TestIRB
{ a: 4 } => true,
/reg/ => true,
Object.new => false,
+ Struct => true,
Struct.new(:a) => false,
Struct.new(:a).new(1) => false,
}.each do |object, result|
- assert_equal(result, IRB::Color.inspect_colorable?(object))
+ assert_equal(result, IRB::Color.inspect_colorable?(object), "Case: inspect_colorable?(#{object.inspect})")
end
end
diff --git a/test/irb/test_completion.rb b/test/irb/test_completion.rb
index 608c41bad9..83df9c1c47 100644
--- a/test/irb/test_completion.rb
+++ b/test/irb/test_completion.rb
@@ -7,7 +7,7 @@ module TestIRB
begin
require "irb/completion"
bug5938 = '[ruby-core:42244]'
- cmds = %W[-rirb -rirb/completion -e IRB.setup(__FILE__)
+ cmds = %W[-W0 -rirb -rirb/completion -e IRB.setup(__FILE__)
-e IRB.conf[:MAIN_CONTEXT]=IRB::Irb.new.context
-e module\sFoo;def\sself.name;//;end;end
-e IRB::InputCompletor::CompletionProc.call("[1].first.")
diff --git a/test/irb/test_option.rb b/test/irb/test_option.rb
index 85ebd085ca..6f36d81bdd 100644
--- a/test/irb/test_option.rb
+++ b/test/irb/test_option.rb
@@ -5,7 +5,7 @@ module TestIRB
class TestOption < Test::Unit::TestCase
def test_end_of_option
bug4117 = '[ruby-core:33574]'
- status = assert_in_out_err(%w[-rirb -e IRB.start(__FILE__) -- -f --], "", //, [], bug4117)
+ status = assert_in_out_err(%w[-W0 -rirb -e IRB.start(__FILE__) -- -f --], "", //, [], bug4117)
assert(status.success?, bug4117)
end
end
diff --git a/test/irb/test_raise_no_backtrace_exception.rb b/test/irb/test_raise_no_backtrace_exception.rb
index 1d2e05bfac..38c61f2a94 100644
--- a/test/irb/test_raise_no_backtrace_exception.rb
+++ b/test/irb/test_raise_no_backtrace_exception.rb
@@ -4,7 +4,7 @@ require 'test/unit'
module TestIRB
class TestRaiseNoBacktraceException < Test::Unit::TestCase
def test_raise_exception
- assert_in_out_err(%w[-rirb -W1 -e IRB.start(__FILE__) -- -f --], <<-IRB, /Exception: foo/, [])
+ assert_in_out_err(%w[-rirb -W0 -e IRB.start(__FILE__) -- -f --], <<-IRB, /Exception: foo/, [])
e = Exception.new("foo")
def e.backtrace; nil; end
raise e