2012-06-25 17:13:16 -04:00
|
|
|
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
|
|
|
|
|
2012-06-26 18:07:53 -04:00
|
|
|
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
|
|
|
|
|
2012-06-25 17:13:16 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def parse(haml, options = nil)
|
|
|
|
options ||= Options.new
|
|
|
|
parser = Parser.new(haml, options)
|
|
|
|
parser.parse
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|