diff options
author | Yusuke Endoh <mame@ruby-lang.org> | 2022-08-10 21:17:04 +0900 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2022-08-10 21:19:10 +0900 |
commit | 3a58009066049f9af09ea3171cecab88ba0d9f1c (patch) | |
tree | 20a90bbc117f2b57fcf3b6aeb6103dfce6ff20e3 /test/error_highlight | |
parent | 99e7fa5b3718d61d61427c67d244ec50b9eb8578 (diff) | |
download | ruby-3a58009066049f9af09ea3171cecab88ba0d9f1c.tar.gz |
[ruby/error_highlight] Make backtrace_location keyword work
We had to keep backtrace_location before opts is overwritten.
https://github.com/ruby/error_highlight/commit/2735e4681a
Diffstat (limited to 'test/error_highlight')
-rw-r--r-- | test/error_highlight/test_error_highlight.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/error_highlight/test_error_highlight.rb b/test/error_highlight/test_error_highlight.rb index 89c930f5e6..c4a998092b 100644 --- a/test/error_highlight/test_error_highlight.rb +++ b/test/error_highlight/test_error_highlight.rb @@ -1231,4 +1231,30 @@ undefined method `foo' for nil:NilClass end end end + + def raise_name_error + 1.time + end + + def test_spot_with_backtrace_location + lineno = __LINE__ + begin + raise_name_error + rescue NameError => exc + end + + spot = ErrorHighlight.spot(exc).except(:script_lines) + assert_equal(lineno - 4, spot[:first_lineno]) + assert_equal(lineno - 4, spot[:last_lineno]) + assert_equal(5, spot[:first_column]) + assert_equal(10, spot[:last_column]) + assert_equal(" 1.time\n", spot[:snippet]) + + spot = ErrorHighlight.spot(exc, backtrace_location: exc.backtrace_locations[1]).except(:script_lines) + assert_equal(lineno + 2, spot[:first_lineno]) + assert_equal(lineno + 2, spot[:last_lineno]) + assert_equal(6, spot[:first_column]) + assert_equal(22, spot[:last_column]) + assert_equal(" raise_name_error\n", spot[:snippet]) + end end |