Skip to content

Commit

Permalink
[ruby/irb] Test colors with enabling colors
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu authored and matzbot committed Dec 26, 2022
1 parent d93d786 commit a968d78
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/irb/test_color.rb
Expand Up @@ -18,6 +18,20 @@ class TestColor < TestCase
MAGENTA = "\e[35m"
CYAN = "\e[36m"

def setup
super
if IRB.respond_to?(:conf)
@colorize, IRB.conf[:USE_COLORIZE] = IRB.conf[:USE_COLORIZE], true
end
end

def teardown
if instance_variable_defined?(:@colorize)
IRB.conf[:USE_COLORIZE] = @colorize
end
super
end

def test_colorize
text = "text"
{
Expand Down
8 changes: 8 additions & 0 deletions test/irb/test_color_printer.rb
Expand Up @@ -15,6 +15,10 @@ class TestColorPrinter < TestCase
CYAN = "\e[36m"

def setup
super
if IRB.respond_to?(:conf)
@colorize, IRB.conf[:USE_COLORIZE] = IRB.conf[:USE_COLORIZE], true
end
@get_screen_size = Reline.method(:get_screen_size)
Reline.instance_eval { undef :get_screen_size }
def Reline.get_screen_size
Expand All @@ -25,6 +29,10 @@ def Reline.get_screen_size
def teardown
Reline.instance_eval { undef :get_screen_size }
Reline.define_singleton_method(:get_screen_size, @get_screen_size)
if instance_variable_defined?(:@colorize)
IRB.conf[:USE_COLORIZE] = @colorize
end
super
end

IRBTestColorPrinter = Struct.new(:a)
Expand Down

0 comments on commit a968d78

Please sign in to comment.