@@ -11,6 +11,12 @@ def self.SGR(*attr) = CSI attr.join(?;), ?m
1111 RESET = SGR "" # could also use 0
1212 BOLD = SGR 1
1313 BOLD_UNDERLINE = SGR 1 , 4
14+ BOLD_YELLOW = SGR 1 , 33 , 40
15+ YELLOW = SGR 33 , 40
16+ BLUE = SGR 34
17+ CYAN = SGR 36 , 40
18+ MAGENTA_DARK = SGR 35
19+ MAGENTA = SGR 95
1420
1521 setup do
1622 @term_env_vars = ENV [ "TERM" ] , ENV [ "NO_COLOR" ] , ENV [ "FORCE_COLOR" ]
@@ -90,26 +96,41 @@ def self.SGR(*attr) = CSI attr.join(?;), ?m
9096 lex_state : #{ BOLD } :EXPR_BEG#{ RESET }
9197 token : #{ BOLD } :QUOTED#{ RESET } => #{ BOLD } "Microsoft.Exchange.Error: foo"#{ RESET }
9298 MSG
99+ expected_color_hl = <<~MSG . strip
100+ #{ BOLD } #{ msg } (#{ BOLD_UNDERLINE } #{ name } #{ RESET } #{ BOLD } )#{ RESET }
101+ #{ MAGENTA } processed #{ RESET } : #{ CYAN } "tag OK [Error=\\ "Microsoft.Exchange.Error: foo\\ ""#{ RESET }
102+ #{ MAGENTA } remaining #{ RESET } : #{ BOLD_YELLOW } "] done\\ r\\ n"#{ RESET }
103+ #{ MAGENTA } pos #{ RESET } : #{ CYAN } 45#{ RESET }
104+ #{ MAGENTA } lex_state #{ RESET } : #{ YELLOW } :EXPR_BEG#{ RESET }
105+ #{ MAGENTA } token #{ RESET } : #{ YELLOW } :QUOTED#{ RESET } => #{ CYAN } "Microsoft.Exchange.Error: foo"#{ RESET }
106+ MSG
93107
94108 ENV [ "TERM" ] , ENV [ "NO_COLOR" ] , ENV [ "FORCE_COLOR" ] = nil , nil , "0"
95109 assert_equal ( expected_no_hl , err . detailed_message )
96- assert_equal ( expected_no_color , err . detailed_message ( highlight : true ) )
110+ assert_equal ( expected_color_hl , err . detailed_message ( highlight : true ) )
111+ assert_equal ( expected_no_color , err . detailed_message ( highlight : true ,
112+ highlight_no_color : true ) )
97113
98114 ENV [ "TERM" ] , ENV [ "NO_COLOR" ] , ENV [ "FORCE_COLOR" ] = "dumb" , "1" , nil
99115 assert_equal ( expected_no_hl , err . detailed_message )
100116 assert_equal ( expected_no_color , err . detailed_message ( highlight : true ) )
117+ assert_equal ( expected_color_hl , err . detailed_message ( highlight : true ,
118+ highlight_no_color : false ) )
101119
102120 ENV [ "TERM" ] , ENV [ "NO_COLOR" ] , ENV [ "FORCE_COLOR" ] = "xterm" , nil , nil
103- assert_equal ( expected_no_color , err . detailed_message )
121+ assert_equal ( expected_color_hl , err . detailed_message )
104122 assert_equal ( expected_no_hl , err . detailed_message ( highlight : false ) )
123+ assert_equal ( expected_no_color , err . detailed_message ( highlight_no_color : true ) )
105124
106125 ENV [ "TERM" ] , ENV [ "NO_COLOR" ] , ENV [ "FORCE_COLOR" ] = "dumb" , nil , "1"
107- assert_equal ( expected_no_color , err . detailed_message )
126+ assert_equal ( expected_color_hl , err . detailed_message )
108127 assert_equal ( expected_no_hl , err . detailed_message ( highlight : false ) )
128+ assert_equal ( expected_no_color , err . detailed_message ( highlight_no_color : true ) )
109129
110130 ENV [ "TERM" ] , ENV [ "NO_COLOR" ] , ENV [ "FORCE_COLOR" ] = "unknown" , "1" , "1"
111131 assert_equal ( expected_no_color , err . detailed_message )
112132 assert_equal ( expected_no_hl , err . detailed_message ( highlight : false ) )
133+ assert_equal ( expected_color_hl , err . detailed_message ( highlight_no_color : false ) )
113134
114135 # reset to nil
115136 ENV [ "TERM" ] , ENV [ "NO_COLOR" ] , ENV [ "FORCE_COLOR" ] = nil , nil , nil
@@ -135,21 +156,35 @@ def self.SGR(*attr) = CSI attr.join(?;), ?m
135156 MSG
136157 assert_equal ( <<~MSG . strip , err . detailed_message ( highlight : true , parser_state : true ) )
137158 #{ BOLD } #{ msg } (#{ BOLD_UNDERLINE } #{ name } #{ RESET } #{ BOLD } )#{ RESET }
138- processed : #{ BOLD } "tag OK [Error=\\ "Microsoft.Exchange.Error: foo\\ ""#{ RESET }
139- remaining : #{ BOLD_UNDERLINE } "] done\\ r\\ n"#{ RESET }
140- pos : #{ BOLD } 45#{ RESET }
141- lex_state : #{ BOLD } :EXPR_BEG#{ RESET }
142- token : nil
159+ #{ MAGENTA } processed #{ RESET } : #{ CYAN } "tag OK [Error=\\ "Microsoft.Exchange.Error: foo\\ ""#{ RESET }
160+ #{ MAGENTA } remaining #{ RESET } : #{ BOLD_YELLOW } "] done\\ r\\ n"#{ RESET }
161+ #{ MAGENTA } pos #{ RESET } : #{ CYAN } 45#{ RESET }
162+ #{ MAGENTA } lex_state #{ RESET } : #{ YELLOW } :EXPR_BEG#{ RESET }
163+ #{ MAGENTA } token #{ RESET } : #{ MAGENTA_DARK } nil#{ RESET }
143164 MSG
144165
145166 # with parser_backtrace
146167 Net ::IMAP . debug = false
147168 parser = Net ::IMAP ::ResponseParser . new
148169 error = parser . parse ( "* 123 FETCH (UNKNOWN ...)\r \n " ) rescue $!
149170 no_hl = error . detailed_message ( parser_backtrace : true )
150- no_color = error . detailed_message ( parser_backtrace : true , highlight : true )
171+ color_hl = error . detailed_message ( parser_backtrace : true , highlight : true )
172+ no_color = error . detailed_message ( parser_backtrace : true , highlight : true ,
173+ highlight_no_color : true )
151174 assert_include no_hl , "caller[ 1]: %-30s (" % "msg_att"
152175 assert_include no_color , "caller[ 1]: #{ BOLD } %-30s#{ RESET } (" % "msg_att"
176+ assert_include color_hl ,
177+ "#{ MAGENTA } caller[#{ RESET } #{ BLUE } 1#{ RESET } #{ MAGENTA } ]#{ RESET } : " \
178+ "#{ BOLD } %-30s#{ RESET } (" % "msg_att"
179+ end
180+
181+ if defined? ( ::Ractor )
182+ %i[ ESC_NO_HL ESC_NO_COLOR ESC_COLORS ] . each do |name |
183+ test "ResponseParseError::#{ name } is Ractor shareable" do
184+ value = Net ::IMAP ::ResponseParseError . const_get ( name )
185+ assert Ractor . shareable? value
186+ end
187+ end
153188 end
154189
155190 test "ResponseTooLargeError" do
0 commit comments