Skip to content

Commit

Permalink
make sync-default-gems GEM=irb
Browse files Browse the repository at this point in the history
Synced from ruby/irb@5feb361.
This includes a support to colorize named Class instance on IRB inspect.
  • Loading branch information
k0kubun committed Apr 27, 2019
1 parent 3f95620 commit 9348643
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
4 changes: 4 additions & 0 deletions lib/irb/color.rb
Expand Up @@ -46,6 +46,10 @@ def colorable?
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) }
Expand Down
5 changes: 3 additions & 2 deletions test/irb/test_color.rb
Expand Up @@ -30,7 +30,7 @@ def test_colorize_code
"# 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')
Expand All @@ -54,10 +54,11 @@ def test_inspect_colorable
{ 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

Expand Down
2 changes: 1 addition & 1 deletion test/irb/test_completion.rb
Expand Up @@ -7,7 +7,7 @@ def test_nonstring_module_name
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.")
Expand Down
2 changes: 1 addition & 1 deletion test/irb/test_option.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/irb/test_raise_no_backtrace_exception.rb
Expand Up @@ -4,7 +4,7 @@
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
Expand Down

0 comments on commit 9348643

Please sign in to comment.