@@ -339,10 +339,11 @@ def test_template_translate_location
339
339
assert_equal expected , new_template ( source ) . translate_location ( backtrace_location , spot )
340
340
end
341
341
342
+ # merely tests for the case where the backtrace and spot disagree about lineno
342
343
def test_template_translate_location_lineno_offset
343
344
highlight = "nomethoderror"
344
345
source = "<%= nomethoderror %>"
345
- compiled = "\n '.freeze; @output_buffer.append= nomethoderror ; @output_buffer.safe_append='\n "
346
+ compiled = "'.freeze; @output_buffer.append= nomethoderror ; @output_buffer.safe_append='"
346
347
347
348
backtrace_location = Data . define ( :lineno ) . new ( lineno : 1 )
348
349
spot = spot_highlight ( compiled , highlight , first_lineno : 2 , last_lineno : 2 )
@@ -351,6 +352,21 @@ def test_template_translate_location_lineno_offset
351
352
assert_equal expected , new_template ( source ) . translate_location ( backtrace_location , spot )
352
353
end
353
354
355
+ # We are testing the failure case here. `find_offset` doesn't correctly handle the case
356
+ # where the line number is not the same in the backtrace and template.
357
+ def test_template_translate_location_with_multiline_code_source
358
+ highlight = "nomethoderror"
359
+ source = "<%=\n good(\n nomethoderror\n ) %>"
360
+ extracted_line = " nomethoderror\n "
361
+ compiled = "ValidatedOutputBuffer.wrap(@output_buffer, ({}), ' \n good(\n nomethoderror\n " \
362
+ ") '.freeze, true).safe_none_append=( \n good(\n nomethoderror\n ) );\n @output_buffer"
363
+
364
+ backtrace_location = Data . define ( :lineno ) . new ( lineno : 6 )
365
+ spot = spot_highlight ( compiled , highlight , first_column : 1 , first_lineno : 6 , last_lineno : 6 , snippet : extracted_line )
366
+
367
+ assert_equal spot , new_template ( source ) . translate_location ( backtrace_location , spot )
368
+ end
369
+
354
370
def test_template_translate_location_with_multibye_string_before_highlight
355
371
highlight = "nomethoderror"
356
372
source = String . new ( "\u{a5} <%= nomethoderror %>" , encoding : Encoding ::UTF_8 ) # yen symbol
0 commit comments