diff options
author | Takashi Kokubun <takashikkbn@gmail.com> | 2019-06-13 00:40:27 +0900 |
---|---|---|
committer | Takashi Kokubun <takashikkbn@gmail.com> | 2019-06-13 00:41:00 +0900 |
commit | 2a26c1ea24ec107cfb43d8561ad28984846b7660 (patch) | |
tree | 8cb36c3e572dad76058ef445d2f46b7e88baef37 /test/irb | |
parent | 8d84e119da52573f9dfe3b2fe7a6d1c27b7fd71f (diff) | |
download | ruby-2a26c1ea24ec107cfb43d8561ad28984846b7660.tar.gz |
Clarify the Ruby version support status in IRB more
Diffstat (limited to 'test/irb')
-rw-r--r-- | test/irb/test_color.rb | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/test/irb/test_color.rb b/test/irb/test_color.rb index 60b7a9f96e..e1057d3144 100644 --- a/test/irb/test_color.rb +++ b/test/irb/test_color.rb @@ -61,6 +61,7 @@ module TestIRB "$stdout" => "#{GREEN}#{BOLD}$stdout#{CLEAR}", } + # specific to Ruby 2.7+ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0') tests.merge!({ "4.5.6" => "#{MAGENTA}#{BOLD}4.5#{CLEAR}#{RED}#{REVERSE}.6#{CLEAR}", @@ -72,24 +73,24 @@ module TestIRB end tests.each do |code, result| - if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.5.0') - # colorize_code is supported only for Ruby 2.5+. Just return the original code in 2.4-. - actual = with_term { IRB::Color.colorize_code(code) } - assert_equal(code, actual) - else + if colorize_code_supported? actual = with_term { IRB::Color.colorize_code(code, complete: true) } assert_equal(result, actual, "Case: colorize_code(#{code.dump}, complete: true)\nResult: #{humanized_literal(actual)}") actual = with_term { IRB::Color.colorize_code(code, complete: false) } assert_equal(result, actual, "Case: colorize_code(#{code.dump}, complete: false)\nResult: #{humanized_literal(actual)}") + else + actual = with_term { IRB::Color.colorize_code(code) } + assert_equal(code, actual) end end end def test_colorize_code_complete_true - unless lexer_scan_supported? + unless complete_option_supported? skip '`complete: true` is the same as `complete: false` in Ruby 2.6-' end + # `complete: true` behaviors. Warn end-of-file. { "'foo' + 'bar" => "#{RED}'#{CLEAR}#{RED}foo#{CLEAR}#{RED}'#{CLEAR} + #{RED}'#{CLEAR}#{RED}#{REVERSE}bar#{CLEAR}", @@ -106,18 +107,17 @@ module TestIRB "'foo' + 'bar" => "#{RED}'#{CLEAR}#{RED}foo#{CLEAR}#{RED}'#{CLEAR} + #{RED}'#{CLEAR}#{RED}bar#{CLEAR}", "('foo" => "(#{RED}'#{CLEAR}#{RED}foo#{CLEAR}", }.each do |code, result| - if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.5.0') - # colorize_code is supported only for Ruby 2.5+. Just return the original code in 2.4-. - actual = with_term { IRB::Color.colorize_code(code) } - assert_equal(code, actual) - else + if colorize_code_supported? actual = with_term { IRB::Color.colorize_code(code, complete: false) } assert_equal(result, actual, "Case: colorize_code(#{code.dump}, complete: false)\nResult: #{humanized_literal(actual)}") - unless lexer_scan_supported? + unless complete_option_supported? actual = with_term { IRB::Color.colorize_code(code, complete: true) } assert_equal(result, actual, "Case: colorize_code(#{code.dump}, complete: false)\nResult: #{humanized_literal(actual)}") end + else + actual = with_term { IRB::Color.colorize_code(code) } + assert_equal(code, actual) end end end @@ -142,7 +142,13 @@ module TestIRB private - def lexer_scan_supported? + # `#colorize_code` is supported only for Ruby 2.5+. It just returns the original code in 2.4-. + def colorize_code_supported? + Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.5.0') + end + + # `complete: true` is the same as `complete: false` in Ruby 2.6- + def complete_option_supported? Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0') end |