diff options
author | Takashi Kokubun <takashikkbn@gmail.com> | 2019-05-25 20:47:29 -0700 |
---|---|---|
committer | Takashi Kokubun <takashikkbn@gmail.com> | 2019-05-25 20:47:33 -0700 |
commit | 13f58eccdab374ab14d33a6882c52e048cb52e3c (patch) | |
tree | 7e9b6d0d23b14d82bcffd6af1b4fa62830bbdbc3 /test | |
parent | a516834b47de810b53241c66f677fafd4485bebd (diff) | |
download | ruby-13f58eccdab374ab14d33a6882c52e048cb52e3c.tar.gz |
Always color Symbol as Yellow on IRB::Color
Symbol color was made blue as a workaround because it was hard to
distinguish `foo`s in `:foo` and `def foo; end` (both are :on_ident).
But I wanted to make it yellow like pry.
`:Struct` had the same problem in :on_const. Because the :on_const was
also blue (but underlined and bold), it was not a big issue.
While they're not so problematic since we got a workaround, we also had
a more serious issue for highlighting a symbol like `:"a#{b}c"`.
The first half was considered as Symbol and the last half was considered
as String, because the colorizer did not have a state like a parser.
To approach the last issue, I introduced `IRB::Color::SymbolState` which
is a thin state manager knowing only "the token is Symbol or not". Having
this module magically solves the first two problems as well. So now we
can highlight Symbol as yellow in the perfect manner.
Diffstat (limited to 'test')
-rw-r--r-- | test/irb/test_color.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/test/irb/test_color.rb b/test/irb/test_color.rb index c723f9180b..e2e44385a8 100644 --- a/test/irb/test_color.rb +++ b/test/irb/test_color.rb @@ -11,6 +11,7 @@ module TestIRB UNDERLINE = "\e[4m" RED = "\e[31m" GREEN = "\e[32m" + YELLOW = "\e[33m" BLUE = "\e[34m" MAGENTA = "\e[35m" CYAN = "\e[36m" @@ -24,7 +25,7 @@ module TestIRB { "1" => "#{BLUE}#{BOLD}1#{CLEAR}", "2.3" => "#{MAGENTA}#{BOLD}2.3#{CLEAR}", - "['foo', :bar]" => "[#{RED}'#{CLEAR}#{RED}foo#{CLEAR}#{RED}'#{CLEAR}, #{BLUE}#{BOLD}:#{CLEAR}#{BLUE}#{BOLD}bar#{CLEAR}]", + "['foo', :bar]" => "[#{RED}'#{CLEAR}#{RED}foo#{CLEAR}#{RED}'#{CLEAR}, #{YELLOW}:#{CLEAR}#{YELLOW}bar#{CLEAR}]", "class A; end" => "#{GREEN}class#{CLEAR} #{BLUE}#{BOLD}#{UNDERLINE}A#{CLEAR}; #{GREEN}end#{CLEAR}", "def self.foo; bar; end" => "#{GREEN}def#{CLEAR} #{CYAN}#{BOLD}self#{CLEAR}.#{BLUE}#{BOLD}foo#{CLEAR}; bar; #{GREEN}end#{CLEAR}", 'ERB.new("a#{nil}b", trim_mode: "-")' => "#{BLUE}#{BOLD}#{UNDERLINE}ERB#{CLEAR}.new(#{RED}\"#{CLEAR}#{RED}a#{CLEAR}#{RED}\#{#{CLEAR}#{CYAN}#{BOLD}nil#{CLEAR}#{RED}}#{CLEAR}#{RED}b#{CLEAR}#{RED}\"#{CLEAR}, #{MAGENTA}trim_mode:#{CLEAR} #{RED}\"#{CLEAR}#{RED}-#{CLEAR}#{RED}\"#{CLEAR})", @@ -40,9 +41,11 @@ module TestIRB "%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}}", - ":Struct" => "#{BLUE}#{BOLD}:#{CLEAR}#{BLUE}#{BOLD}#{UNDERLINE}Struct#{CLEAR}", + ":Struct" => "#{YELLOW}:#{CLEAR}#{YELLOW}Struct#{CLEAR}", "<<EOS\nhere\nEOS" => "#{RED}<<EOS#{CLEAR}\n#{RED}here#{CLEAR}\n#{RED}EOS#{CLEAR}", '"#{}"' => "#{RED}\"#{CLEAR}#{RED}\#{#{CLEAR}#{RED}}#{CLEAR}#{RED}\"#{CLEAR}", + ':"a#{}b"' => "#{YELLOW}:\"#{CLEAR}#{YELLOW}a#{CLEAR}#{YELLOW}\#{#{CLEAR}#{YELLOW}}#{CLEAR}#{YELLOW}b#{CLEAR}#{YELLOW}\"#{CLEAR}", + ':"a#{ def b; end; \'c\' + "#{ :d }" }e"' => "#{YELLOW}:\"#{CLEAR}#{YELLOW}a#{CLEAR}#{YELLOW}\#{#{CLEAR} #{GREEN}def#{CLEAR} #{BLUE}#{BOLD}b#{CLEAR}; #{GREEN}end#{CLEAR}; #{RED}'#{CLEAR}#{RED}c#{CLEAR}#{RED}'#{CLEAR} + #{RED}\"#{CLEAR}#{RED}\#{#{CLEAR} #{YELLOW}:#{CLEAR}#{YELLOW}d#{CLEAR} #{RED}}#{CLEAR}#{RED}\"#{CLEAR} #{YELLOW}}#{CLEAR}#{YELLOW}e#{CLEAR}#{YELLOW}\"#{CLEAR}", }.each do |code, result| actual = with_term { IRB::Color.colorize_code(code) } assert_equal(result, actual, "Case: colorize_code(#{code.dump})\nResult: #{humanized_literal(actual)}") @@ -91,6 +94,7 @@ module TestIRB .gsub(UNDERLINE, '@@@{UNDERLINE}') .gsub(RED, '@@@{RED}') .gsub(GREEN, '@@@{GREEN}') + .gsub(YELLOW, '@@@{YELLOW}') .gsub(BLUE, '@@@{BLUE}') .gsub(MAGENTA, '@@@{MAGENTA}') .gsub(CYAN, '@@@{CYAN}') |