mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
make sync-default-gems GEM=irb
Synced from 5feb361ed8
.
This includes a support to colorize named Class instance on IRB inspect.
This commit is contained in:
parent
3f9562015e
commit
9348643575
5 changed files with 10 additions and 5 deletions
|
@ -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) }
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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.")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue