mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
04ae44fb31
Raise an Haml::Error when an `else` or `elsif` is wrongly nested after an `unless` as well as after `if`. See #535.
41 lines
No EOL
1.2 KiB
Ruby
41 lines
No EOL
1.2 KiB
Ruby
require 'test_helper'
|
|
|
|
module Haml
|
|
class ParserTest < MiniTest::Unit::TestCase
|
|
|
|
test "should raise error for 'else' at wrong indent level" do
|
|
begin
|
|
parse("- if true\n #first\n text\n - else\n #second")
|
|
flunk("Should have raised a Haml::Error")
|
|
rescue Error => e
|
|
assert_equal Error.message(:bad_script_indent, 'else', 0, 1), e.message
|
|
end
|
|
end
|
|
|
|
test "should raise error for 'elsif' at wrong indent level" do
|
|
begin
|
|
parse("- if true\n #first\n text\n - elsif false\n #second")
|
|
flunk("Should have raised a Haml::Error")
|
|
rescue Error => e
|
|
assert_equal Error.message(:bad_script_indent, 'elsif', 0, 1), e.message
|
|
end
|
|
end
|
|
|
|
test "should raise error for 'else' at wrong indent level after unless" do
|
|
begin
|
|
parse("- unless true\n #first\n text\n - else\n #second")
|
|
flunk("Should have raised a Haml::Error")
|
|
rescue Error => e
|
|
assert_equal Error.message(:bad_script_indent, 'else', 0, 1), e.message
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def parse(haml, options = nil)
|
|
options ||= Options.new
|
|
parser = Parser.new(haml, options)
|
|
parser.parse
|
|
end
|
|
end
|
|
end |