Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/error_highlight/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ def spot_call_for_name
end
elsif mid.to_s =~ /\A\W+\z/ && lines.match(/\G\s*(#{ Regexp.quote(mid) })=.*\n/, nd_recv.last_column)
@snippet = $` + $&
@beg_lineno = @end_lineno = lineno
@beg_column = $~.begin(1)
@end_column = $~.end(1)
end
Expand Down Expand Up @@ -582,8 +583,9 @@ def spot_colon2
@beg_column = nd_parent.last_column
@end_column = @node.last_column
else
@snippet = @fetch[@node.last_lineno]
fetch_line(@node.last_lineno)
if @snippet[[email protected]_column].match(/#{ Regexp.quote(const) }\z/)
@beg_lineno = @end_lineno = @node.last_lineno
@beg_column = $~.begin(0)
@end_column = $~.end(0)
end
Expand All @@ -597,7 +599,7 @@ def spot_op_cdecl
nd_lhs, op, _nd_rhs = @node.children
*nd_parent_lhs, _const = nd_lhs.children
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)
@beg_column = $~.begin(1)
@end_column = $~.end(1)
Expand All @@ -607,12 +609,12 @@ def spot_op_cdecl
@end_column = nd_lhs.last_column
if nd_parent_lhs.empty? # example: ::C += 1
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
end
else # example: Foo::Bar::C += 1
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
end
end
Expand Down
9 changes: 9 additions & 0 deletions test/test_error_highlight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ def preprocess(msg)
def assert_error_message(klass, expected_msg, &blk)
omit unless klass < ErrorHighlight::CoreExt
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\)/, ""))
end
else
Expand Down