Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary coloring support check #413

Merged
merged 1 commit into from
Oct 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 17 additions & 30 deletions test/irb/test_color.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,23 +135,19 @@ def test_colorize_code
end

tests.each do |code, result|
if colorize_code_supported?
assert_equal_with_term(result, code, complete: true)
assert_equal_with_term(result, code, complete: false)
assert_equal_with_term(result, code, complete: true)
assert_equal_with_term(result, code, complete: false)

assert_equal_with_term(code, code, complete: true, tty: false)
assert_equal_with_term(code, code, complete: false, tty: false)
assert_equal_with_term(code, code, complete: true, tty: false)
assert_equal_with_term(code, code, complete: false, tty: false)

assert_equal_with_term(code, code, complete: true, colorable: false)
assert_equal_with_term(code, code, complete: true, colorable: false)

assert_equal_with_term(code, code, complete: false, colorable: false)
assert_equal_with_term(code, code, complete: false, colorable: false)

assert_equal_with_term(result, code, complete: true, tty: false, colorable: true)
assert_equal_with_term(result, code, complete: true, tty: false, colorable: true)

assert_equal_with_term(result, code, complete: false, tty: false, colorable: true)
else
assert_equal_with_term(code, code)
end
assert_equal_with_term(result, code, complete: false, tty: false, colorable: true)
end
end

Expand Down Expand Up @@ -181,26 +177,22 @@ def test_colorize_code_complete_false
"'foo' + 'bar" => "#{RED}#{BOLD}'#{CLEAR}#{RED}foo#{CLEAR}#{RED}#{BOLD}'#{CLEAR} + #{RED}#{BOLD}'#{CLEAR}#{RED}bar#{CLEAR}",
"('foo" => "(#{RED}#{BOLD}'#{CLEAR}#{RED}foo#{CLEAR}",
}.each do |code, result|
if colorize_code_supported?
assert_equal_with_term(result, code, complete: false)
assert_equal_with_term(result, code, complete: false)

assert_equal_with_term(code, code, complete: false, tty: false)
assert_equal_with_term(code, code, complete: false, tty: false)

assert_equal_with_term(code, code, complete: false, colorable: false)
assert_equal_with_term(code, code, complete: false, colorable: false)

assert_equal_with_term(result, code, complete: false, tty: false, colorable: true)
assert_equal_with_term(result, code, complete: false, tty: false, colorable: true)

unless complete_option_supported?
assert_equal_with_term(result, code, complete: true)
unless complete_option_supported?
assert_equal_with_term(result, code, complete: true)

assert_equal_with_term(code, code, complete: true, tty: false)
assert_equal_with_term(code, code, complete: true, tty: false)

assert_equal_with_term(code, code, complete: true, colorable: false)
assert_equal_with_term(code, code, complete: true, colorable: false)

assert_equal_with_term(result, code, complete: true, tty: false, colorable: true)
end
else
assert_equal_with_term(code, code)
assert_equal_with_term(result, code, complete: true, tty: false, colorable: true)
end
end
end
Expand All @@ -227,11 +219,6 @@ def test_inspect_colorable

private

# `#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')
Expand Down