diff options
Diffstat (limited to 'test/irb/test_color_printer.rb')
-rw-r--r-- | test/irb/test_color_printer.rb | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/test/irb/test_color_printer.rb b/test/irb/test_color_printer.rb index 93ec700146..c2c624d868 100644 --- a/test/irb/test_color_printer.rb +++ b/test/irb/test_color_printer.rb @@ -1,11 +1,11 @@ # frozen_string_literal: false -require 'test/unit' require 'irb/color_printer' -require 'rubygems' require 'stringio' +require_relative "helper" + module TestIRB - class TestColorPrinter < Test::Unit::TestCase + class ColorPrinterTest < TestCase CLEAR = "\e[0m" BOLD = "\e[1m" RED = "\e[31m" @@ -14,6 +14,10 @@ module TestIRB 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 @@ -24,18 +28,19 @@ module TestIRB 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) def test_color_printer - unless ripper_lexer_scan_supported? - pend 'Ripper::Lexer#scan is supported in Ruby 2.7+' - end { 1 => "#{BLUE}#{BOLD}1#{CLEAR}\n", "a\nb" => %[#{RED}#{BOLD}"#{CLEAR}#{RED}a\\nb#{CLEAR}#{RED}#{BOLD}"#{CLEAR}\n], - IRBTestColorPrinter.new('test') => "#{GREEN}#<struct TestIRB::TestColorPrinter::IRBTestColorPrinter#{CLEAR} a#{GREEN}=#{CLEAR}#{RED}#{BOLD}\"#{CLEAR}#{RED}test#{CLEAR}#{RED}#{BOLD}\"#{CLEAR}#{GREEN}>#{CLEAR}\n", + IRBTestColorPrinter.new('test') => "#{GREEN}#<struct TestIRB::ColorPrinterTest::IRBTestColorPrinter#{CLEAR} a#{GREEN}=#{CLEAR}#{RED}#{BOLD}\"#{CLEAR}#{RED}test#{CLEAR}#{RED}#{BOLD}\"#{CLEAR}#{GREEN}>#{CLEAR}\n", Ripper::Lexer.new('1').scan => "[#{GREEN}#<Ripper::Lexer::Elem:#{CLEAR} on_int@1:0 END token: #{RED}#{BOLD}\"#{CLEAR}#{RED}1#{CLEAR}#{RED}#{BOLD}\"#{CLEAR}#{GREEN}>#{CLEAR}]\n", Class.new{define_method(:pretty_print){|q| q.text("[__FILE__, __LINE__, __ENCODING__]")}}.new => "[#{CYAN}#{BOLD}__FILE__#{CLEAR}, #{CYAN}#{BOLD}__LINE__#{CLEAR}, #{CYAN}#{BOLD}__ENCODING__#{CLEAR}]\n", }.each do |object, result| @@ -46,10 +51,6 @@ module TestIRB private - def ripper_lexer_scan_supported? - Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0') - end - def with_term stdout = $stdout io = StringIO.new |