summaryrefslogtreecommitdiff
path: root/test/irb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-06-04 00:14:55 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-06-04 00:14:55 +0900
commit0c459af7c233adb5f44022350bfe8fa132d8053e (patch)
tree0ce22c47f876f23d88113c2282d3e079dd69f027 /test/irb
parent928377d2c5153333445d58710534b471042ffb46 (diff)
Colorize error characters
* lib/irb/color.rb (IRB::Color.scan): ignore "incomplete end of input" error only, to colorize invalid characters, e.g., control characters, and invalid symbols, as errors.
Diffstat (limited to 'test/irb')
-rw-r--r--test/irb/test_color.rb13
1 files changed, 5 insertions, 8 deletions
diff --git a/test/irb/test_color.rb b/test/irb/test_color.rb
index ebae790b71..d327d617fa 100644
--- a/test/irb/test_color.rb
+++ b/test/irb/test_color.rb
@@ -41,6 +41,7 @@ module TestIRB
"'a\nb'" => "#{RED}'#{CLEAR}#{RED}a#{CLEAR}\n#{RED}b#{CLEAR}#{RED}'#{CLEAR}",
"4.5.6" => "#{MAGENTA}#{BOLD}4.5#{CLEAR}#{RED}#{REVERSE}.6#{CLEAR}",
"[1]]]" => "[1]]]",
+ "\e[0m\n" => "#{RED}#{REVERSE}^[#{CLEAR}[#{BLUE}#{BOLD}0#{CLEAR}m\n",
"%w[a b]" => "#{RED}%w[#{CLEAR}#{RED}a#{CLEAR} #{RED}b#{CLEAR}#{RED}]#{CLEAR}",
"%i[c d]" => "#{RED}%i[#{CLEAR}#{RED}c#{CLEAR} #{RED}d#{CLEAR}#{RED}]#{CLEAR}",
"{'a': 1}" => "{#{RED}'#{CLEAR}#{RED}a#{CLEAR}#{RED}':#{CLEAR} #{BLUE}#{BOLD}1#{CLEAR}}",
@@ -52,6 +53,8 @@ module TestIRB
"[__FILE__, __LINE__]" => "[#{CYAN}#{BOLD}__FILE__#{CLEAR}, #{CYAN}#{BOLD}__LINE__#{CLEAR}]",
":self" => "#{YELLOW}:#{CLEAR}#{YELLOW}self#{CLEAR}",
":class" => "#{YELLOW}:#{CLEAR}#{YELLOW}class#{CLEAR}",
+ ":@1" => "#{YELLOW}:#{CLEAR}#{RED}#{REVERSE}@1#{CLEAR}",
+ "@@1" => "#{RED}#{REVERSE}@@1#{CLEAR}",
"[:end, 2]" => "[#{YELLOW}:#{CLEAR}#{YELLOW}end#{CLEAR}, #{BLUE}#{BOLD}2#{CLEAR}]",
"[:>, 3]" => "[#{YELLOW}:#{CLEAR}#{YELLOW}>#{CLEAR}, #{BLUE}#{BOLD}3#{CLEAR}]",
":Hello ? world : nil" => "#{YELLOW}:#{CLEAR}#{YELLOW}Hello#{CLEAR} ? world : #{CYAN}#{BOLD}nil#{CLEAR}",
@@ -76,12 +79,9 @@ module TestIRB
end
def test_colorize_code_complete_true
- # `complete: true` behaviors. Warn compile_error.
+ # `complete: true` behaviors. Warn end-of-file.
{
- "\e[0m\n" => "#{RED}#{REVERSE}^[#{CLEAR}[#{BLUE}#{BOLD}0#{CLEAR}m\n",
"'foo' + 'bar" => "#{RED}'#{CLEAR}#{RED}foo#{CLEAR}#{RED}'#{CLEAR} + #{RED}'#{CLEAR}#{RED}#{REVERSE}bar#{CLEAR}",
- ":@1" => "#{YELLOW}:#{CLEAR}#{RED}#{REVERSE}@1#{CLEAR}",
- "@@1" => "#{RED}#{REVERSE}@@1#{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)}")
@@ -89,12 +89,9 @@ module TestIRB
end
def test_colorize_code_complete_false
- # `complete: false` behaviors. Do not warn compile_error.
+ # `complete: false` behaviors. Do not warn end-of-file
{
- "\e[0m\n" => "#{CLEAR}\n",
"'foo' + 'bar" => "#{RED}'#{CLEAR}#{RED}foo#{CLEAR}#{RED}'#{CLEAR} + #{RED}'#{CLEAR}#{RED}bar#{CLEAR}",
- ":@1" => "#{YELLOW}:#{CLEAR}#{YELLOW}@1#{CLEAR}",
- "@@1" => "@@1",
}.each do |code, result|
actual = with_term { IRB::Color.colorize_code(code, complete: false) }
assert_equal(result, actual, "Case: colorize_code(#{code.dump}, complete: false)\nResult: #{humanized_literal(actual)}")