/
parser_test.rb
78 lines (68 loc) · 2.35 KB
/
parser_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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::SyntaxError")
rescue SyntaxError => 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::SyntaxError")
rescue SyntaxError => 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::SyntaxError")
rescue SyntaxError => e
assert_equal Error.message(:bad_script_indent, 'else', 0, 1), e.message
end
end
test "should raise syntax error for else with no if" do
begin
parse("- else\n 'foo'")
flunk("Should have raised a Haml::SyntaxError")
rescue SyntaxError => e
assert_equal Error.message(:missing_if, 'else'), e.message
end
end
test "should raise syntax error for nested else with no" do
begin
parse("#foo\n - else\n 'foo'")
flunk("Should have raised a Haml::SyntaxError")
rescue SyntaxError => e
assert_equal Error.message(:missing_if, 'else'), e.message
end
end
test "else after if containing case is accepted" do
# see issue 572
begin
parse "- if true\n - case @foo\n - when 1\n bar\n- else\n bar"
assert true
rescue SyntaxError
flunk 'else clause after if containing case should be accepted'
end
end
test "else after if containing unless is accepted" do
begin
parse "- if true\n - unless @foo\n bar\n- else\n bar"
assert true
rescue SyntaxError
flunk 'else clause after if containing unless should be accepted'
end
end
private
def parse(haml, options = nil)
options ||= Options.new
parser = Parser.new(haml, options)
parser.parse
end
end
end