mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Ensure runtime error's backtrace line number is correct
This commit is contained in:
parent
7aa284d53f
commit
3462f32d04
2 changed files with 20 additions and 1 deletions
|
@ -51,7 +51,7 @@ module Hamlit
|
|||
width = next_width
|
||||
if width != @current_indent * 2
|
||||
if width != Hamlit::EOF && (width > @current_indent * 2 || width.odd?)
|
||||
ast << [:newline]
|
||||
ast << [:multi, [:newline], [:newline]]
|
||||
ast << syntax_error(
|
||||
"inconsistent indentation: #{2 * @current_indent} spaces used for indentation, "\
|
||||
"but the rest of the document was indented using #{width} spaces"
|
||||
|
|
|
@ -22,5 +22,24 @@ describe Hamlit::Engine do
|
|||
HAML
|
||||
to raise_error(Hamlit::SyntaxError, 'inconsistent indentation: 2 spaces used for indentation, but the rest of the document was indented using 1 spaces')
|
||||
end
|
||||
|
||||
it 'raises syntax error which has correct line number in backtrace' do
|
||||
begin
|
||||
render_string(<<-HAML.unindent)
|
||||
%1
|
||||
%2
|
||||
%3
|
||||
%4
|
||||
%5
|
||||
%6
|
||||
%7
|
||||
%8 this is invalid indent
|
||||
%9
|
||||
HAML
|
||||
rescue Hamlit::SyntaxError => e
|
||||
line_number = e.backtrace_locations.first.to_s.match(/:(\d+):/)[1]
|
||||
expect(line_number).to eq('8')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue