@@ -17,6 +17,23 @@ class TestColor < Test::Unit::TestCase
17
17
MAGENTA = "\e [35m"
18
18
CYAN = "\e [36m"
19
19
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
+
20
37
def test_colorize_code
21
38
# Common behaviors. Warn parser error, but do not warn compile error.
22
39
tests = {
@@ -192,12 +209,19 @@ def io.tty?; true; end
192
209
ENV . replace ( env ) if env
193
210
end
194
211
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
197
220
message = -> {
198
221
args = [ code . dump ]
222
+ args << seq . inspect if seq
199
223
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 ) } "
201
225
}
202
226
assert_equal ( result , actual , message )
203
227
end
0 commit comments