Support highlighting Regexp in inspect

This commit is contained in:
Takashi Kokubun 2019-04-26 01:15:30 +09:00
Родитель e64bab5f77
Коммит 5fe99aefd3
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 6FFC433B12EE23DD
2 изменённых файлов: 5 добавлений и 3 удалений

Просмотреть файл

@ -28,8 +28,8 @@ module IRB # :nodoc:
on_kw: [[GREEN], [Ripper::EXPR_CLASS, Ripper::EXPR_BEG, Ripper::EXPR_END, Ripper::EXPR_FNAME]],
on_label: [[MAGENTA], [Ripper::EXPR_LABELED]],
on_qwords_beg: [[RED], [Ripper::EXPR_BEG]],
on_regexp_beg: [[RED], [Ripper::EXPR_BEG]],
on_regexp_end: [[RED], [Ripper::EXPR_BEG]],
on_regexp_beg: [[RED, BOLD], [Ripper::EXPR_BEG]],
on_regexp_end: [[RED, BOLD], [Ripper::EXPR_BEG]],
on_symbeg: [[BLUE, BOLD], [Ripper::EXPR_FNAME]],
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_ARG, Ripper::EXPR_CMDARG]],
@ -47,7 +47,7 @@ module IRB # :nodoc:
obj.all? { |k, v| inspect_colorable?(k) && inspect_colorable?(v) }
when Array
obj.all? { |o| inspect_colorable?(o) }
when String, Symbol, Integer, Float, FalseClass, TrueClass, NilClass
when String, Symbol, Regexp, Integer, Float, FalseClass, TrueClass, NilClass
true
else
false

Просмотреть файл

@ -23,6 +23,7 @@ module TestIRB
"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})",
"# comment" => "#{BLUE}#{BOLD}# comment#{CLEAR}",
'/r#{e}g/' => "#{RED}#{BOLD}/#{CLEAR}#{RED}r#{CLEAR}#{RED}\#{#{CLEAR}e}#{RED}g#{CLEAR}#{RED}#{BOLD}/#{CLEAR}",
}.each do |code, result|
assert_equal(result, with_term { IRB::Color.colorize_code(code) })
end
@ -34,6 +35,7 @@ module TestIRB
2.3 => true,
['foo', :bar] => true,
{ a: 4 } => true,
/reg/ => true,
Object.new => false,
Struct.new(:a) => false,
Struct.new(:a).new(1) => false,