[ruby/error_highlight] Ensure first_line and last_line are set
Fixes https://github.com/ruby/error_highlight/pull/58 https://github.com/ruby/error_highlight/commit/9ddc1f31a9
This commit is contained in:
parent
be44d5677d
commit
e01b4ca1c8
@ -344,6 +344,7 @@ module ErrorHighlight
|
|||||||
end
|
end
|
||||||
elsif mid.to_s =~ /\A\W+\z/ && lines.match(/\G\s*(#{ Regexp.quote(mid) })=.*\n/, nd_recv.last_column)
|
elsif mid.to_s =~ /\A\W+\z/ && lines.match(/\G\s*(#{ Regexp.quote(mid) })=.*\n/, nd_recv.last_column)
|
||||||
@snippet = $` + $&
|
@snippet = $` + $&
|
||||||
|
@beg_lineno = @end_lineno = lineno
|
||||||
@beg_column = $~.begin(1)
|
@beg_column = $~.begin(1)
|
||||||
@end_column = $~.end(1)
|
@end_column = $~.end(1)
|
||||||
end
|
end
|
||||||
@ -582,8 +583,9 @@ module ErrorHighlight
|
|||||||
@beg_column = nd_parent.last_column
|
@beg_column = nd_parent.last_column
|
||||||
@end_column = @node.last_column
|
@end_column = @node.last_column
|
||||||
else
|
else
|
||||||
@snippet = @fetch[@node.last_lineno]
|
fetch_line(@node.last_lineno)
|
||||||
if @snippet[...@node.last_column].match(/#{ Regexp.quote(const) }\z/)
|
if @snippet[...@node.last_column].match(/#{ Regexp.quote(const) }\z/)
|
||||||
|
@beg_lineno = @end_lineno = @node.last_lineno
|
||||||
@beg_column = $~.begin(0)
|
@beg_column = $~.begin(0)
|
||||||
@end_column = $~.end(0)
|
@end_column = $~.end(0)
|
||||||
end
|
end
|
||||||
@ -597,7 +599,7 @@ module ErrorHighlight
|
|||||||
nd_lhs, op, _nd_rhs = @node.children
|
nd_lhs, op, _nd_rhs = @node.children
|
||||||
*nd_parent_lhs, _const = nd_lhs.children
|
*nd_parent_lhs, _const = nd_lhs.children
|
||||||
if @name == op
|
if @name == op
|
||||||
@snippet = @fetch[nd_lhs.last_lineno]
|
fetch_line(nd_lhs.last_lineno)
|
||||||
if @snippet.match(/\G\s*(#{ Regexp.quote(op) })=/, nd_lhs.last_column)
|
if @snippet.match(/\G\s*(#{ Regexp.quote(op) })=/, nd_lhs.last_column)
|
||||||
@beg_column = $~.begin(1)
|
@beg_column = $~.begin(1)
|
||||||
@end_column = $~.end(1)
|
@end_column = $~.end(1)
|
||||||
@ -607,12 +609,12 @@ module ErrorHighlight
|
|||||||
@end_column = nd_lhs.last_column
|
@end_column = nd_lhs.last_column
|
||||||
if nd_parent_lhs.empty? # example: ::C += 1
|
if nd_parent_lhs.empty? # example: ::C += 1
|
||||||
if nd_lhs.first_lineno == nd_lhs.last_lineno
|
if nd_lhs.first_lineno == nd_lhs.last_lineno
|
||||||
@snippet = @fetch[nd_lhs.last_lineno]
|
fetch_line(nd_lhs.last_lineno)
|
||||||
@beg_column = nd_lhs.first_column
|
@beg_column = nd_lhs.first_column
|
||||||
end
|
end
|
||||||
else # example: Foo::Bar::C += 1
|
else # example: Foo::Bar::C += 1
|
||||||
if nd_parent_lhs.last.last_lineno == nd_lhs.last_lineno
|
if nd_parent_lhs.last.last_lineno == nd_lhs.last_lineno
|
||||||
@snippet = @fetch[nd_lhs.last_lineno]
|
fetch_line(nd_lhs.last_lineno)
|
||||||
@beg_column = nd_parent_lhs.last.last_column
|
@beg_column = nd_parent_lhs.last.last_column
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -44,6 +44,15 @@ class ErrorHighlightTest < Test::Unit::TestCase
|
|||||||
def assert_error_message(klass, expected_msg, &blk)
|
def assert_error_message(klass, expected_msg, &blk)
|
||||||
omit unless klass < ErrorHighlight::CoreExt
|
omit unless klass < ErrorHighlight::CoreExt
|
||||||
err = assert_raise(klass, &blk)
|
err = assert_raise(klass, &blk)
|
||||||
|
spot = ErrorHighlight.spot(err)
|
||||||
|
if spot
|
||||||
|
assert_kind_of(Integer, spot[:first_lineno])
|
||||||
|
assert_kind_of(Integer, spot[:first_column])
|
||||||
|
assert_kind_of(Integer, spot[:last_lineno])
|
||||||
|
assert_kind_of(Integer, spot[:last_column])
|
||||||
|
assert_kind_of(String, spot[:snippet])
|
||||||
|
assert_kind_of(Array, spot[:script_lines])
|
||||||
|
end
|
||||||
assert_equal(preprocess(expected_msg).chomp, err.detailed_message(highlight: false).sub(/ \((?:NoMethod|Name)Error\)/, ""))
|
assert_equal(preprocess(expected_msg).chomp, err.detailed_message(highlight: false).sub(/ \((?:NoMethod|Name)Error\)/, ""))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user