-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathparser_spec.rb
92 lines (74 loc) · 2.08 KB
/
parser_spec.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
describe Curly::Parser do
it "parses component tokens" do
tokens = [
[:component, "a", nil, {}],
]
expect(parse(tokens)).to eq [
component("a")
]
end
it "parses conditional blocks" do
tokens = [
[:conditional_block_start, "a?", nil, {}],
[:component, "hello", nil, {}],
[:block_end, "a?", nil],
]
expect(parse(tokens)).to eq [
conditional_block(component("a?"), [component("hello")])
]
end
it "parses inverse conditional blocks" do
tokens = [
[:inverse_conditional_block_start, "a?", nil, {}],
[:component, "hello", nil, {}],
[:block_end, "a?", nil],
]
expect(parse(tokens)).to eq [
inverse_conditional_block(component("a?"), [component("hello")])
]
end
it "parses collection blocks" do
tokens = [
[:collection_block_start, "mice", nil, {}],
[:component, "hello", nil, {}],
[:block_end, "mice", nil],
]
expect(parse(tokens)).to eq [
collection_block(component("mice"), [component("hello")])
]
end
it "fails if a block is not closed" do
tokens = [
[:collection_block_start, "mice", nil, {}],
]
expect { parse(tokens) }.to raise_exception(Curly::IncompleteBlockError)
end
it "fails if a block is closed with the wrong component" do
tokens = [
[:collection_block_start, "mice", nil, {}],
[:block_end, "men", nil, {}],
]
expect { parse(tokens) }.to raise_exception(Curly::IncorrectEndingError)
end
it "fails if there is a closing component too many" do
tokens = [
[:block_end, "world", nil, {}],
]
expect { parse(tokens) }.to raise_exception(Curly::IncorrectEndingError)
end
def parse(tokens)
described_class.parse(tokens)
end
def component(*args)
Curly::Parser::Component.new(*args)
end
def conditional_block(*args)
Curly::Parser::Block.new(:conditional, *args)
end
def inverse_conditional_block(*args)
Curly::Parser::Block.new(:inverse_conditional, *args)
end
def collection_block(*args)
Curly::Parser::Block.new(:collection, *args)
end
end