This repository has been archived by the owner on Apr 4, 2018. It is now read-only.
/
parsing_test.rb
166 lines (128 loc) · 3.16 KB
/
parsing_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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
require "common"
require "sibyl/parser"
require "sibyl/transform"
describe "Parser" do
def sexp(source)
parser = Sibyl::Parser.new
transform = Sibyl::Transform.new
transform.apply(parser.parse(source))
end
it "should parse a metadata line with a number" do
actual = sexp(%{
metadata need 1660
})
expected = [[:metadata, "need", 1660]]
assert_equal expected, actual
end
it "should parse a metadata line with a word" do
actual = sexp(%{
metadata foo bar-baz
})
expected = [[:metadata, "foo", "bar-baz"]]
assert_equal expected, actual
end
it "should parse a metadata line with a string" do
actual = sexp(%{
metadata foo "bar baz"
})
expected = [[:metadata, "foo", "bar baz"]]
assert_equal expected, actual
end
it "should parse a simple multiple option step" do
actual = sexp(%{
step multiple a
option yes -> b
option no -> c
})
expected = [
[:step, "multiple", "a", [
[:option, :simple, "yes", "b"],
[:option, :simple, "no", "c"]]]]
assert_equal expected, actual
end
it "should parse a multiple option step with logic" do
actual = sexp(%{
step multiple a
option yes ->
if { logic } -> b
otherwise -> c
option no -> d
})
expected = [
[:step, "multiple", "a", [
[:option, :branch, "yes", [
[:if, "logic", "b"],
[:otherwise, "c"]]],
[:option, :simple, "no", "d"]]]]
assert_equal expected, actual
end
it "should parse a step with a simple direct transition" do
actual = sexp(%{
step salary a
go -> b
})
expected = [
[:step, "salary", "a", [
[:go, :simple, "b"]]]]
assert_equal expected, actual
end
it "should parse a step with a direct transition with logic" do
actual = sexp(%{
step salary a
go ->
if { logic } -> b
otherwise -> c
})
expected = [
[:step, "salary", "a", [
[:go, :branch, [
[:if, "logic", "b"],
[:otherwise, "c"]]]]]]
assert_equal expected, actual
end
it "should parse an empty document" do
actual = sexp(%{
})
expected = []
assert_equal expected, actual
end
it "should parse a reject block" do
actual = sexp(%{
step any a
reject { logic }
})
expected = [
[:step, "any", "a", [
[:reject, "logic"]]]]
assert_equal expected, actual
end
it "should parse a set block" do
actual = sexp(%{
step any a
set foo_bar { input }
})
expected = [
[:step, "any", "a", [
[:set, "foo_bar", "input"]]]]
assert_equal expected, actual
end
it "should ignore a comment inside a unit" do
actual = sexp(%{
step any a
-- ignore me
go -> b
})
expected = [
[:step, "any", "a", [
[:go, :simple, "b"]]]]
assert_equal expected, actual
end
it "should ignore a comment before a unit" do
actual = sexp(%{
-- ignore me
metadata foo bar
})
expected = [[:metadata, "foo", "bar"]]
assert_equal expected, actual
end
end