diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-04-08 01:00:41 +0900 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2021-04-26 21:14:37 +0900 |
commit | 75f1ad8cb33171662e3248a1fe8ded2eda0a9cef (patch) | |
tree | b5c9edb174af44ac953f280a6a139c44f3e38646 /test/irb/test_color.rb | |
parent | 6ddaad606e99aab254288ef14fffbd34a2e54e16 (diff) | |
download | ruby-75f1ad8cb33171662e3248a1fe8ded2eda0a9cef.tar.gz |
[ruby/irb] Added test_colorize
https://github.com/ruby/irb/commit/10e290fc3a
Diffstat (limited to 'test/irb/test_color.rb')
-rw-r--r-- | test/irb/test_color.rb | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/test/irb/test_color.rb b/test/irb/test_color.rb index b652552c30..ada207da73 100644 --- a/test/irb/test_color.rb +++ b/test/irb/test_color.rb @@ -17,6 +17,23 @@ module TestIRB MAGENTA = "\e[35m" 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 # Common behaviors. Warn parser error, but do not warn compile error. tests = { @@ -192,12 +209,19 @@ module TestIRB ENV.replace(env) if env end - def assert_equal_with_term(result, code, **opts) - actual = with_term { IRB::Color.colorize_code(code, **opts) } + def assert_equal_with_term(result, code, seq: nil, **opts) + actual = with_term do + if seq + IRB::Color.colorize(code, seq, **opts) + else + IRB::Color.colorize_code(code, **opts) + end + end message = -> { args = [code.dump] + args << seq.inspect if seq 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) end |