diff options
| author | Yusuke Endoh <mame@ruby-lang.org> | 2021-07-13 16:53:52 +0900 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2021-07-13 16:54:17 +0900 |
| commit | 5fd5d71a4b100fdeca55352a5441b095a1d82e16 (patch) | |
| tree | bfb995c4bf921eb6ff5cfb21175ed35a4d31ec90 | |
| parent | 23c8bc367c6d700789a4059b831606966efb674c (diff) | |
[ruby/error_highlight] Support a file that has no final newline
https://github.com/ruby/error_highlight/commit/9d671284cb
| -rw-r--r-- | lib/error_highlight/base.rb | 1 | ||||
| -rw-r--r-- | test/error_highlight/test_error_highlight.rb | 16 |
2 files changed, 17 insertions, 0 deletions
diff --git a/lib/error_highlight/base.rb b/lib/error_highlight/base.rb index fc23508a5d..696df76ff9 100644 --- a/lib/error_highlight/base.rb +++ b/lib/error_highlight/base.rb @@ -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. diff --git a/test/error_highlight/test_error_highlight.rb b/test/error_highlight/test_error_highlight.rb index 071b3bfd3e..03909bd593 100644 --- a/test/error_highlight/test_error_highlight.rb +++ b/test/error_highlight/test_error_highlight.rb @@ -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 |
