mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/error_highlight] Support a file that has no final newline
https://github.com/ruby/error_highlight/commit/9d671284cb
This commit is contained in:
parent
23c8bc367c
commit
5fd5d71a4b
2 changed files with 17 additions and 0 deletions
|
@ -35,6 +35,7 @@ module ErrorHighlight
|
|||
|
||||
@fetch = -> (lineno, last_lineno = lineno) do
|
||||
snippet = @node.script_lines[lineno - 1 .. last_lineno - 1].join("")
|
||||
snippet += "\n" unless snippet.end_with?("\n")
|
||||
|
||||
# It require some work to support Unicode (or multibyte) characters.
|
||||
# Tentatively, we stop highlighting if the code snippet has non-ascii characters.
|
||||
|
|
|
@ -1016,4 +1016,20 @@ _ _ ^^^^^
|
|||
load tmp.path
|
||||
end
|
||||
end
|
||||
|
||||
def test_no_final_newline
|
||||
tmp = Tempfile.new(["error_highlight_test", ".rb"])
|
||||
tmp << "1.time {}"
|
||||
tmp.close(false)
|
||||
|
||||
assert_error_message(NoMethodError, <<~END) do
|
||||
undefined method `time' for 1:Integer
|
||||
|
||||
1.time {}
|
||||
^^^^^
|
||||
END
|
||||
|
||||
load tmp.path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue