mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/irb] Added test_colorize
https://github.com/ruby/irb/commit/10e290fc3a
This commit is contained in:
parent
6ddaad606e
commit
75f1ad8cb3
1 changed files with 27 additions and 3 deletions
|
@ -17,6 +17,23 @@ module TestIRB
|
||||||
MAGENTA = "\e[35m"
|
MAGENTA = "\e[35m"
|
||||||
CYAN = "\e[36m"
|
CYAN = "\e[36m"
|
||||||
|
|
||||||
|
def test_colorize
|
||||||
|
text = "text"
|
||||||
|
{
|
||||||
|
[:BOLD] => "#{BOLD}#{text}#{CLEAR}",
|
||||||
|
[:UNDERLINE] => "#{UNDERLINE}#{text}#{CLEAR}",
|
||||||
|
[:REVERSE] => "#{REVERSE}#{text}#{CLEAR}",
|
||||||
|
[:RED] => "#{RED}#{text}#{CLEAR}",
|
||||||
|
[:GREEN] => "#{GREEN}#{text}#{CLEAR}",
|
||||||
|
[:YELLOW] => "#{YELLOW}#{text}#{CLEAR}",
|
||||||
|
[:BLUE] => "#{BLUE}#{text}#{CLEAR}",
|
||||||
|
[:MAGENTA] => "#{MAGENTA}#{text}#{CLEAR}",
|
||||||
|
[:CYAN] => "#{CYAN}#{text}#{CLEAR}",
|
||||||
|
}.each do |seq, result|
|
||||||
|
assert_equal_with_term(result, text, seq: seq)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_colorize_code
|
def test_colorize_code
|
||||||
# Common behaviors. Warn parser error, but do not warn compile error.
|
# Common behaviors. Warn parser error, but do not warn compile error.
|
||||||
tests = {
|
tests = {
|
||||||
|
@ -192,12 +209,19 @@ module TestIRB
|
||||||
ENV.replace(env) if env
|
ENV.replace(env) if env
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_equal_with_term(result, code, **opts)
|
def assert_equal_with_term(result, code, seq: nil, **opts)
|
||||||
actual = with_term { IRB::Color.colorize_code(code, **opts) }
|
actual = with_term do
|
||||||
|
if seq
|
||||||
|
IRB::Color.colorize(code, seq, **opts)
|
||||||
|
else
|
||||||
|
IRB::Color.colorize_code(code, **opts)
|
||||||
|
end
|
||||||
|
end
|
||||||
message = -> {
|
message = -> {
|
||||||
args = [code.dump]
|
args = [code.dump]
|
||||||
|
args << seq.inspect if seq
|
||||||
opts.each {|kwd, val| args << "#{kwd}: #{val}"}
|
opts.each {|kwd, val| args << "#{kwd}: #{val}"}
|
||||||
"Case: colorize_code(#{args.join(', ')})\nResult: #{humanized_literal(actual)}"
|
"Case: colorize#{seq ? "" : "_code"}(#{args.join(', ')})\nResult: #{humanized_literal(actual)}"
|
||||||
}
|
}
|
||||||
assert_equal(result, actual, message)
|
assert_equal(result, actual, message)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue