@@ -17,6 +17,23 @@ class TestColor < Test::Unit::TestCase
1717 MAGENTA = "\e [35m"
1818 CYAN = "\e [36m"
1919
20+ def test_colorize
21+ text = "text"
22+ {
23+ [ :BOLD ] => "#{ BOLD } #{ text } #{ CLEAR } " ,
24+ [ :UNDERLINE ] => "#{ UNDERLINE } #{ text } #{ CLEAR } " ,
25+ [ :REVERSE ] => "#{ REVERSE } #{ text } #{ CLEAR } " ,
26+ [ :RED ] => "#{ RED } #{ text } #{ CLEAR } " ,
27+ [ :GREEN ] => "#{ GREEN } #{ text } #{ CLEAR } " ,
28+ [ :YELLOW ] => "#{ YELLOW } #{ text } #{ CLEAR } " ,
29+ [ :BLUE ] => "#{ BLUE } #{ text } #{ CLEAR } " ,
30+ [ :MAGENTA ] => "#{ MAGENTA } #{ text } #{ CLEAR } " ,
31+ [ :CYAN ] => "#{ CYAN } #{ text } #{ CLEAR } " ,
32+ } . each do |seq , result |
33+ assert_equal_with_term ( result , text , seq : seq )
34+ end
35+ end
36+
2037 def test_colorize_code
2138 # Common behaviors. Warn parser error, but do not warn compile error.
2239 tests = {
@@ -192,12 +209,19 @@ def io.tty?; true; end
192209 ENV . replace ( env ) if env
193210 end
194211
195- def assert_equal_with_term ( result , code , **opts )
196- actual = with_term { IRB ::Color . colorize_code ( code , **opts ) }
212+ def assert_equal_with_term ( result , code , seq : nil , **opts )
213+ actual = with_term do
214+ if seq
215+ IRB ::Color . colorize ( code , seq , **opts )
216+ else
217+ IRB ::Color . colorize_code ( code , **opts )
218+ end
219+ end
197220 message = -> {
198221 args = [ code . dump ]
222+ args << seq . inspect if seq
199223 opts . each { |kwd , val | args << "#{ kwd } : #{ val } " }
200- "Case: colorize_code (#{ args . join ( ', ' ) } )\n Result: #{ humanized_literal ( actual ) } "
224+ "Case: colorize #{ seq ? "" : "_code" } (#{ args . join ( ', ' ) } )\n Result: #{ humanized_literal ( actual ) } "
201225 }
202226 assert_equal ( result , actual , message )
203227 end
0 commit comments