aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2019-06-04 00:22:22 +0900
committerTakashi Kokubun <takashikkbn@gmail.com>2019-06-04 00:26:02 +0900
commitde541fe1961370e64541d73c96cf790d30f28604 (patch)
treee0dff25bcc3c45dd846d2375c25a405cb36ca812
parent6498c733da4f34aca47ca88412605761467a2fec (diff)
downloadruby-de541fe1961370e64541d73c96cf790d30f28604.tar.gz
colorize_code must return escaped text
This was needed before 0c459af7c233adb5f44022350bfe8fa132d8053e but it could be actually useless now. But I added this anyway just in case.
-rw-r--r--lib/irb/color.rb4
-rw-r--r--test/irb/test_color.rb5
2 files changed, 6 insertions, 3 deletions
diff --git a/lib/irb/color.rb b/lib/irb/color.rb
index c2d0084446..4996ccf92f 100644
--- a/lib/irb/color.rb
+++ b/lib/irb/color.rb
@@ -123,7 +123,9 @@ module IRB # :nodoc:
end
# give up colorizing incomplete Ripper tokens
- return code if length != code.bytesize
+ if length != code.bytesize
+ return Reline::Unicode.escape_for_print(code)
+ end
colored
end
diff --git a/test/irb/test_color.rb b/test/irb/test_color.rb
index d327d617fa..ae6e02afa9 100644
--- a/test/irb/test_color.rb
+++ b/test/irb/test_color.rb
@@ -69,6 +69,7 @@ module TestIRB
"\t" => "\t", # not ^I
"foo(*%W(bar))" => "foo(*#{RED}%W(#{CLEAR}#{RED}bar#{CLEAR}#{RED})#{CLEAR})",
"$stdout" => "#{GREEN}#{BOLD}$stdout#{CLEAR}",
+ "\u0013" => "#{RED}#{REVERSE}^S#{CLEAR}",
}.each do |code, result|
actual = with_term { IRB::Color.colorize_code(code, complete: true) }
assert_equal(result, actual, "Case: colorize_code(#{code.dump}, complete: true)\nResult: #{humanized_literal(actual)}")
@@ -79,7 +80,7 @@ module TestIRB
end
def test_colorize_code_complete_true
- # `complete: true` behaviors. Warn end-of-file.
+ # `complete: true` behaviors. Warn compile_error.
{
"'foo' + 'bar" => "#{RED}'#{CLEAR}#{RED}foo#{CLEAR}#{RED}'#{CLEAR} + #{RED}'#{CLEAR}#{RED}#{REVERSE}bar#{CLEAR}",
}.each do |code, result|
@@ -89,7 +90,7 @@ module TestIRB
end
def test_colorize_code_complete_false
- # `complete: false` behaviors. Do not warn end-of-file
+ # `complete: false` behaviors. Do not warn compile_error.
{
"'foo' + 'bar" => "#{RED}'#{CLEAR}#{RED}foo#{CLEAR}#{RED}'#{CLEAR} + #{RED}'#{CLEAR}#{RED}bar#{CLEAR}",
}.each do |code, result|