mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Support highlighting Regexp in inspect
This commit is contained in:
parent
e64bab5f77
commit
5fe99aefd3
2 changed files with 5 additions and 3 deletions
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue