[前][次][番号順一覧][スレッド一覧]

ruby-changes:65965

From: Nobuyoshi <ko1@a...>
Date: Mon, 26 Apr 2021 21:14:49 +0900 (JST)
Subject: [ruby-changes:65965] 75f1ad8cb3 (master): [ruby/irb] Added test_colorize

https://git.ruby-lang.org/ruby.git/commit/?id=75f1ad8cb3

From 75f1ad8cb33171662e3248a1fe8ded2eda0a9cef Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Thu, 8 Apr 2021 01:00:41 +0900
Subject: [ruby/irb] Added test_colorize

https://github.com/ruby/irb/commit/10e290fc3a
---
 test/irb/test_color.rb | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/test/irb/test_color.rb b/test/irb/test_color.rb
index b652552..ada207d 100644
--- a/test/irb/test_color.rb
+++ b/test/irb/test_color.rb
@@ -17,6 +17,23 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_color.rb#L17
     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 https://github.com/ruby/ruby/blob/trunk/test/irb/test_color.rb#L209
       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
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]