diff options
author | Takashi Kokubun <takashikkbn@gmail.com> | 2019-05-25 07:48:58 -0700 |
---|---|---|
committer | Takashi Kokubun <takashikkbn@gmail.com> | 2019-05-25 07:49:15 -0700 |
commit | ada64aa9e7f1e087b9fd536d9bc512de401f42a0 (patch) | |
tree | 083d5c1b46c0a009519dc70c248f0cef267cdd8b /test/irb | |
parent | 7c507345a73afe3f599e407e851b9c0d708adeb0 (diff) | |
download | ruby-ada64aa9e7f1e087b9fd536d9bc512de401f42a0.tar.gz |
Clear IRB::Color escape sequence before newline
because otherwise prompt and other things could be polluted.
Diffstat (limited to 'test/irb')
-rw-r--r-- | test/irb/test_color.rb | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/test/irb/test_color.rb b/test/irb/test_color.rb index e61e3d3cd8..1d7d74e151 100644 --- a/test/irb/test_color.rb +++ b/test/irb/test_color.rb @@ -32,12 +32,13 @@ module TestIRB '"##@var]"' => "#{RED}\"#{CLEAR}#{RED}##{CLEAR}#{RED}##{CLEAR}@var#{RED}]#{CLEAR}#{RED}\"#{CLEAR}", '"foo#{a} #{b}"' => "#{RED}\"#{CLEAR}#{RED}foo#{CLEAR}#{RED}\#{#{CLEAR}a#{RED}}#{CLEAR}#{RED} #{CLEAR}#{RED}\#{#{CLEAR}b#{RED}}#{CLEAR}#{RED}\"#{CLEAR}", '/r#{e}g/' => "#{RED}#{BOLD}/#{CLEAR}#{RED}r#{CLEAR}#{RED}\#{#{CLEAR}e#{RED}}#{CLEAR}#{RED}g#{CLEAR}#{RED}#{BOLD}/#{CLEAR}", - "'a\nb'" => "#{RED}'#{CLEAR}#{RED}a\n#{CLEAR}#{RED}b#{CLEAR}#{RED}'#{CLEAR}", + "'a\nb'" => "#{RED}'#{CLEAR}#{RED}a#{CLEAR}\n#{RED}b#{CLEAR}#{RED}'#{CLEAR}", "4.5.6" => "4.5.6", "[1]]]" => "[1]]]", "\e[0m\n" => "^[[#{BLUE}#{BOLD}0#{CLEAR}m\n", }.each do |code, result| - assert_equal(result, with_term { IRB::Color.colorize_code(code) }, "Case: colorize_code(#{code.dump})") + actual = with_term { IRB::Color.colorize_code(code) } + assert_equal(result, actual, "Case: colorize_code(#{code.dump})\nResult: #{humanized_literal(actual)}") end end @@ -75,5 +76,18 @@ module TestIRB $stdout = stdout ENV.replace(env) if env end + + def humanized_literal(str) + str + .gsub(CLEAR, '@@@{CLEAR}') + .gsub(BOLD, '@@@{BOLD}') + .gsub(UNDERLINE, '@@@{UNDERLINE}') + .gsub(RED, '@@@{RED}') + .gsub(GREEN, '@@@{GREEN}') + .gsub(BLUE, '@@@{BLUE}') + .gsub(MAGENTA, '@@@{MAGENTA}') + .gsub(CYAN, '@@@{CYAN}') + .dump.gsub(/@@@/, '#') + end end end |