зеркало из https://github.com/github/ruby.git
Deal with more syntax highlight edge cases
Please refer to the tests again.
This commit is contained in:
Родитель
8aba3b7a04
Коммит
52b09fcee1
|
@ -15,12 +15,13 @@ module IRB # :nodoc:
|
|||
CYAN = 36
|
||||
|
||||
TOKEN_KEYWORDS = {
|
||||
on_kw: ['nil', 'self', 'true', 'false', '__FILE__'],
|
||||
on_kw: ['nil', 'self', 'true', 'false', '__FILE__', '__LINE__'],
|
||||
on_const: ['ENV'],
|
||||
}
|
||||
|
||||
begin
|
||||
TOKEN_SEQ_EXPRS = {
|
||||
on_backtick: [[RED], [Ripper::EXPR_BEG]],
|
||||
on_CHAR: [[BLUE, BOLD], [Ripper::EXPR_END]],
|
||||
on_const: [[BLUE, BOLD, UNDERLINE], [Ripper::EXPR_ARG, Ripper::EXPR_CMDARG, Ripper::EXPR_ENDFN]],
|
||||
on_embexpr_beg: [[RED], [Ripper::EXPR_BEG, Ripper::EXPR_END, Ripper::EXPR_CMDARG, Ripper::EXPR_FNAME, Ripper::EXPR_ARG]],
|
||||
|
@ -42,6 +43,7 @@ module IRB # :nodoc:
|
|||
on_tstring_beg: [[RED], [Ripper::EXPR_BEG, Ripper::EXPR_END, Ripper::EXPR_ARG, Ripper::EXPR_CMDARG]],
|
||||
on_tstring_content: [[RED], [Ripper::EXPR_BEG, Ripper::EXPR_END, Ripper::EXPR_ARG, Ripper::EXPR_CMDARG, Ripper::EXPR_FNAME]],
|
||||
on_tstring_end: [[RED], [Ripper::EXPR_END]],
|
||||
on_words_beg: [[RED], [Ripper::EXPR_BEG]],
|
||||
}
|
||||
rescue NameError
|
||||
TOKEN_SEQ_EXPRS = {}
|
||||
|
|
|
@ -58,7 +58,7 @@ class Reline::Unicode
|
|||
def self.escape_for_print(str)
|
||||
str.chars.map! { |gr|
|
||||
escaped = EscapedPairs[gr.ord]
|
||||
if escaped && gr != "\n"
|
||||
if escaped && gr != -"\n" && gr != -"\t"
|
||||
escaped
|
||||
else
|
||||
gr
|
||||
|
|
|
@ -46,7 +46,7 @@ module TestIRB
|
|||
'"#{}"' => "#{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}",
|
||||
"__FILE__" => "#{CYAN}#{BOLD}__FILE__#{CLEAR}",
|
||||
"[__FILE__, __LINE__]" => "[#{CYAN}#{BOLD}__FILE__#{CLEAR}, #{CYAN}#{BOLD}__LINE__#{CLEAR}]",
|
||||
":self" => "#{YELLOW}:#{CLEAR}#{YELLOW}self#{CLEAR}",
|
||||
":class" => "#{YELLOW}:#{CLEAR}#{YELLOW}class#{CLEAR}",
|
||||
"[:>, 3]" => "[#{YELLOW}:#{CLEAR}#{YELLOW}>#{CLEAR}, #{BLUE}#{BOLD}3#{CLEAR}]",
|
||||
|
@ -58,6 +58,9 @@ module TestIRB
|
|||
"foo %w[bar]" => "foo #{RED}%w[#{CLEAR}#{RED}bar#{CLEAR}#{RED}]#{CLEAR}",
|
||||
"foo %i[bar]" => "foo #{RED}%i[#{CLEAR}#{RED}bar#{CLEAR}#{RED}]#{CLEAR}",
|
||||
"foo :@bar, baz" => "foo #{YELLOW}:#{CLEAR}#{YELLOW}@bar#{CLEAR}, baz",
|
||||
"`echo`" => "#{RED}`#{CLEAR}#{RED}echo#{CLEAR}#{RED}`#{CLEAR}",
|
||||
"\t" => "\t", # not ^I
|
||||
"foo(*%W(bar))" => "foo(*#{RED}%W(#{CLEAR}#{RED}bar#{CLEAR}#{RED})#{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)}")
|
||||
|
|
Загрузка…
Ссылка в новой задаче