msfl_visitors 0.1.0.rc3 → 0.3.0.dev
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Gemfile.lock +2 -2
- data/README.md +9 -17
- data/lib/msfl_visitors/nodes/and.rb +0 -17
- data/lib/msfl_visitors/nodes/base.rb +3 -1
- data/lib/msfl_visitors/nodes/binary.rb +0 -7
- data/lib/msfl_visitors/nodes/dataset.rb +7 -0
- data/lib/msfl_visitors/nodes/equal.rb +17 -0
- data/lib/msfl_visitors/nodes/explicit_filter.rb +7 -0
- data/lib/msfl_visitors/nodes/filter.rb +16 -15
- data/lib/msfl_visitors/nodes/foreign.rb +7 -0
- data/lib/msfl_visitors/nodes/given.rb +7 -0
- data/lib/msfl_visitors/nodes/iterator.rb +7 -1
- data/lib/msfl_visitors/nodes/named_value.rb +16 -0
- data/lib/msfl_visitors/nodes/partial.rb +7 -0
- data/lib/msfl_visitors/nodes/set.rb +23 -0
- data/lib/msfl_visitors/nodes.rb +7 -9
- data/lib/msfl_visitors/parsers/msfl_parser.rb +33 -4
- data/lib/msfl_visitors/visitor.rb +165 -6
- data/lib/msfl_visitors.rb +0 -2
- data/msfl_visitors.gemspec +3 -3
- data/spec/nodes/iterator_spec.rb +21 -3
- data/spec/parsers/msfl_parser_spec.rb +61 -4
- data/spec/spec_helper.rb +5 -1
- data/spec/visitors/chewy_term_filter_spec.rb +460 -53
- metadata +11 -24
- data/lib/msfl_visitors/collectors/chewy/term_filter.rb +0 -19
- data/lib/msfl_visitors/collectors.rb +0 -1
- data/lib/msfl_visitors/nodes/binary_and.rb +0 -7
- data/lib/msfl_visitors/nodes/constant_value.rb +0 -11
- data/lib/msfl_visitors/nodes/grouping/close.rb +0 -9
- data/lib/msfl_visitors/nodes/grouping/grouping.rb +0 -24
- data/lib/msfl_visitors/nodes/grouping/open.rb +0 -9
- data/lib/msfl_visitors/nodes/set/close.rb +0 -9
- data/lib/msfl_visitors/nodes/set/delimiter.rb +0 -9
- data/lib/msfl_visitors/nodes/set/open.rb +0 -9
- data/lib/msfl_visitors/nodes/set/set.rb +0 -43
- data/lib/msfl_visitors/renderers/chewy/term_filter.rb +0 -59
- data/spec/renderers/chewy/term_filter_spec.rb +0 -24
@@ -4,27 +4,147 @@ describe MSFLVisitors::Visitor do
|
|
4
4
|
|
5
5
|
let(:node) { fail ArgumentError, "You must define the node variable in each scope." }
|
6
6
|
|
7
|
-
let(:
|
8
|
-
|
9
|
-
let(:renderer) { MSFLVisitors::Renderers::Chewy::TermFilter.new }
|
10
|
-
|
11
|
-
let(:visitor) { described_class.new collector, renderer }
|
7
|
+
let(:visitor) { described_class.new }
|
12
8
|
|
13
9
|
let(:left) { MSFLVisitors::Nodes::Field.new "lhs" }
|
14
10
|
|
15
11
|
let(:right) { MSFLVisitors::Nodes::Word.new "rhs" }
|
16
12
|
|
17
|
-
subject(:result) {
|
18
|
-
|
19
|
-
before(:each) { node.accept visitor }
|
13
|
+
subject(:result) { node.accept visitor }
|
20
14
|
|
21
15
|
context "when visiting" do
|
22
16
|
|
17
|
+
describe "an unsupported node" do
|
18
|
+
|
19
|
+
class UnsupportedNode
|
20
|
+
|
21
|
+
def accept(visitor)
|
22
|
+
visitor.visit self
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:node) { UnsupportedNode.new }
|
27
|
+
|
28
|
+
context "when using the TermFilter visitor" do
|
29
|
+
|
30
|
+
it "raises an ArgumentError" do
|
31
|
+
expect { subject }.to raise_error ArgumentError
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when using the Aggregations visitor" do
|
36
|
+
|
37
|
+
before { visitor.mode = :aggregations }
|
38
|
+
|
39
|
+
it "raises an ArgumentError" do
|
40
|
+
expect { subject }.to raise_error ArgumentError
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
# chewy looks like
|
47
|
+
# Index::Type.filter { match_all }.aggregations({toyotas: {terms: {make: 'Toyota'}, aggregations: { filter: { range: { avg_age: { gt: 10 }}} }}})
|
48
|
+
describe "a Partial node" do
|
49
|
+
|
50
|
+
let(:node) { MSFLVisitors::Nodes::Partial.new given_node, named_value }
|
51
|
+
|
52
|
+
let(:given_node) { MSFLVisitors::Nodes::Given.new [given_equal_node] }
|
53
|
+
|
54
|
+
let(:given_equal_node) { MSFLVisitors::Nodes::Equal.new given_field_node, given_value_node }
|
55
|
+
|
56
|
+
let(:given_field_node) { MSFLVisitors::Nodes::Field.new :make }
|
57
|
+
|
58
|
+
let(:given_value_node) { MSFLVisitors::Nodes::Word.new "Toyota" }
|
59
|
+
|
60
|
+
|
61
|
+
let(:named_value) { MSFLVisitors::Nodes::NamedValue.new MSFLVisitors::Nodes::Word.new("partial"), explicit_filter_node }
|
62
|
+
|
63
|
+
let(:explicit_filter_node) { MSFLVisitors::Nodes::ExplicitFilter.new [greater_than_node] }
|
64
|
+
|
65
|
+
let(:greater_than_node) { MSFLVisitors::Nodes::GreaterThan.new field_node, value_node }
|
66
|
+
|
67
|
+
let(:field_node) { MSFLVisitors::Nodes::Field.new :age }
|
68
|
+
|
69
|
+
let(:value_node) { MSFLVisitors::Nodes::Number.new 10 }
|
70
|
+
|
71
|
+
|
72
|
+
subject { visitor.visit_tree node }
|
73
|
+
|
74
|
+
it "results in the appropriate aggregation clause" do
|
75
|
+
exp = [{
|
76
|
+
clause: {
|
77
|
+
given: {
|
78
|
+
filter: {
|
79
|
+
term: { make: "Toyota" }
|
80
|
+
},
|
81
|
+
aggs: {
|
82
|
+
partial: {
|
83
|
+
filter: { range: { age: { gt: 10 }}}
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}
|
87
|
+
},
|
88
|
+
method_to_execute: :aggregations
|
89
|
+
}]
|
90
|
+
visitor.mode = :aggregations
|
91
|
+
expect(subject).to eq exp
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "a Given node" do
|
96
|
+
|
97
|
+
let(:node) { MSFLVisitors::Nodes::Given.new [given_equal_node] }
|
98
|
+
|
99
|
+
let(:given_equal_node) { MSFLVisitors::Nodes::Equal.new given_field_node, given_value_node }
|
100
|
+
|
101
|
+
let(:given_field_node) { MSFLVisitors::Nodes::Field.new :make }
|
102
|
+
|
103
|
+
let(:given_value_node) { MSFLVisitors::Nodes::Word.new "Toyota" }
|
104
|
+
|
105
|
+
|
106
|
+
it "results in: [:filter, { term: { make: \"Toyota\" } }]" do
|
107
|
+
visitor.mode = :aggregations
|
108
|
+
expect(subject).to eq([:filter, { term: { make: "Toyota" } }])
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "a Foreign node" do
|
113
|
+
|
114
|
+
let(:node) { MSFLVisitors::Nodes::Foreign.new dataset_node, filter_node }
|
115
|
+
|
116
|
+
let(:dataset_node) { MSFLVisitors::Nodes::Dataset.new "person" }
|
117
|
+
|
118
|
+
let(:filter_node) { MSFLVisitors::Nodes::ExplicitFilter.new [equal_node] }
|
119
|
+
|
120
|
+
let(:equal_node) { MSFLVisitors::Nodes::Equal.new left, right }
|
121
|
+
|
122
|
+
let(:left) { MSFLVisitors::Nodes::Field.new :age }
|
123
|
+
|
124
|
+
let(:right) { MSFLVisitors::Nodes::Number.new 25 }
|
125
|
+
|
126
|
+
context "when using the TermFilter visitor" do
|
127
|
+
|
128
|
+
it "results in: 'has_child( :person ).filter { age == 25 }" do
|
129
|
+
expect(subject).to eq "has_child( :person ).filter { age == 25 }"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context "when using the Aggregations visitor" do
|
134
|
+
|
135
|
+
before { visitor.mode = :aggregations }
|
136
|
+
|
137
|
+
it "results in: { has_child: { type: \"person\", filter: { term: { age: 25 } } } }" do
|
138
|
+
expect(subject).to eq({ has_child: { type: "person", filter: { term: { age: 25 } } } })
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
23
143
|
describe "a Containment node" do
|
24
144
|
|
25
145
|
let(:node) { MSFLVisitors::Nodes::Containment.new field, values }
|
26
146
|
|
27
|
-
let(:values) { MSFLVisitors::Nodes::Set
|
147
|
+
let(:values) { MSFLVisitors::Nodes::Set.new(MSFL::Types::Set.new([item_one, item_two, item_three])) }
|
28
148
|
|
29
149
|
let(:item_one) { MSFLVisitors::Nodes::Word.new "item_one" }
|
30
150
|
|
@@ -34,14 +154,26 @@ describe MSFLVisitors::Visitor do
|
|
34
154
|
|
35
155
|
let(:field) { left }
|
36
156
|
|
37
|
-
|
38
|
-
|
157
|
+
context "when using the TermFilter visitor" do
|
158
|
+
|
159
|
+
it "results in: 'lhs == [ \"item_one\", \"item_two\", \"item_three\" ]'" do
|
160
|
+
expect(subject).to eq "lhs == [ \"item_one\" , \"item_two\" , \"item_three\" ]"
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
context "when using the Aggregations visitor" do
|
165
|
+
|
166
|
+
before { visitor.mode = :aggregations }
|
167
|
+
|
168
|
+
it "results in: { terms: { lhs: [\"item_one\", \"item_two\", \"item_three\"] } }" do
|
169
|
+
expect(subject).to eq({ terms: { lhs: ["item_one", "item_two", "item_three"] } })
|
170
|
+
end
|
39
171
|
end
|
40
172
|
end
|
41
173
|
|
42
174
|
describe "a Set node" do
|
43
175
|
|
44
|
-
let(:node) { MSFLVisitors::Nodes::Set
|
176
|
+
let(:node) { MSFLVisitors::Nodes::Set.new values }
|
45
177
|
|
46
178
|
let(:values) { MSFL::Types::Set.new([item_one, item_two]) }
|
47
179
|
|
@@ -49,8 +181,20 @@ describe MSFLVisitors::Visitor do
|
|
49
181
|
|
50
182
|
let(:item_two) { MSFLVisitors::Nodes::Word.new "item_two" }
|
51
183
|
|
52
|
-
|
53
|
-
|
184
|
+
context "when using the TermFilter visitor" do
|
185
|
+
|
186
|
+
it "results in: '[ \"item_one\" , \"item_two\" ]'" do
|
187
|
+
expect(result).to eq "[ \"item_one\" , \"item_two\" ]"
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
context "when using the Aggregations visitor" do
|
192
|
+
|
193
|
+
before { visitor.mode = :aggregations }
|
194
|
+
|
195
|
+
it "results in: [\"item_one\", \"item_two\"]" do
|
196
|
+
expect(result).to eq ["item_one", "item_two"]
|
197
|
+
end
|
54
198
|
end
|
55
199
|
end
|
56
200
|
|
@@ -58,8 +202,20 @@ describe MSFLVisitors::Visitor do
|
|
58
202
|
|
59
203
|
let(:node) { MSFLVisitors::Nodes::Equal.new left, right }
|
60
204
|
|
61
|
-
|
62
|
-
|
205
|
+
context "when the current visitor is Chewy::TermFilter" do
|
206
|
+
|
207
|
+
it "results in: 'left == right'" do
|
208
|
+
expect(result).to eq "lhs == \"rhs\""
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
context "when the current visitor is Chewy::Aggregations" do
|
213
|
+
|
214
|
+
before { visitor.mode = :aggregations }
|
215
|
+
|
216
|
+
it "results in: { term: { lhs: \"rhs\" } }" do
|
217
|
+
expect(result).to eq({ term: { lhs: "rhs" } })
|
218
|
+
end
|
63
219
|
end
|
64
220
|
end
|
65
221
|
|
@@ -67,8 +223,22 @@ describe MSFLVisitors::Visitor do
|
|
67
223
|
|
68
224
|
let(:node) { MSFLVisitors::Nodes::GreaterThan.new left, right }
|
69
225
|
|
70
|
-
|
71
|
-
|
226
|
+
let(:right) { MSFLVisitors::Nodes::Number.new 1000 }
|
227
|
+
|
228
|
+
context "when using the TermFilter visitor" do
|
229
|
+
|
230
|
+
it "returns: 'left > 1000'" do
|
231
|
+
expect(result).to eq "lhs > 1000"
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
context "when using the Aggregations visitor" do
|
236
|
+
|
237
|
+
before { visitor.mode = :aggregations }
|
238
|
+
|
239
|
+
it "results in: { range: { lhs: { gt: 1000 } } }" do
|
240
|
+
expect(result).to eq({ range: { lhs: { gt: 1000 } } })
|
241
|
+
end
|
72
242
|
end
|
73
243
|
end
|
74
244
|
|
@@ -76,8 +246,22 @@ describe MSFLVisitors::Visitor do
|
|
76
246
|
|
77
247
|
let(:node) { MSFLVisitors::Nodes::GreaterThanEqual.new left, right }
|
78
248
|
|
79
|
-
|
80
|
-
|
249
|
+
let(:right) { MSFLVisitors::Nodes::Number.new 10.52 }
|
250
|
+
|
251
|
+
context "when using the TermFilter visitor" do
|
252
|
+
|
253
|
+
it "returns: 'left >= 10.52'" do
|
254
|
+
expect(result).to eq "lhs >= 10.52"
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
context "when using the Aggregations visitor" do
|
259
|
+
|
260
|
+
before { visitor.mode = :aggregations }
|
261
|
+
|
262
|
+
it "results in: { range: { lhs: { gte: 10.52 } } }" do
|
263
|
+
expect(result).to eq({ range: { lhs: { gte: 10.52 } } })
|
264
|
+
end
|
81
265
|
end
|
82
266
|
end
|
83
267
|
|
@@ -85,8 +269,22 @@ describe MSFLVisitors::Visitor do
|
|
85
269
|
|
86
270
|
let(:node) { MSFLVisitors::Nodes::LessThan.new left, right }
|
87
271
|
|
88
|
-
|
89
|
-
|
272
|
+
let(:right) { MSFLVisitors::Nodes::Number.new 133.7 }
|
273
|
+
|
274
|
+
context "when using the TermFilter visitor" do
|
275
|
+
|
276
|
+
it "returns: 'left < 133.7'" do
|
277
|
+
expect(result).to eq 'lhs < 133.7'
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
context "when using the Aggregations visitor" do
|
282
|
+
|
283
|
+
before { visitor.mode = :aggregations }
|
284
|
+
|
285
|
+
it "returns: { range: { lhs: { lt: 133.7 } } }" do
|
286
|
+
expect(result).to eq({ range: { lhs: { lt: 133.7 } } })
|
287
|
+
end
|
90
288
|
end
|
91
289
|
end
|
92
290
|
|
@@ -94,8 +292,82 @@ describe MSFLVisitors::Visitor do
|
|
94
292
|
|
95
293
|
let(:node) { MSFLVisitors::Nodes::LessThanEqual.new left, right }
|
96
294
|
|
97
|
-
|
98
|
-
|
295
|
+
let(:right) { MSFLVisitors::Nodes::Date.new Date.today }
|
296
|
+
|
297
|
+
context "when using the TermFilter visitor" do
|
298
|
+
|
299
|
+
it "returns: 'left <= \"#{Date.today}\"'" do
|
300
|
+
expect(result).to eq "lhs <= \"#{Date.today}\""
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
context "when using the Aggregations visitor" do
|
305
|
+
|
306
|
+
before { visitor.mode = :aggregations }
|
307
|
+
|
308
|
+
it "returns: { range: { lhs: { lte: \"#{Date.today}\" } } }" do
|
309
|
+
expect(result).to eq({ range: { lhs: { lte: "#{Date.today}" } } })
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
describe "a Filter node" do
|
315
|
+
|
316
|
+
let(:node) { MSFLVisitors::Nodes::Filter.new filtered_nodes }
|
317
|
+
|
318
|
+
let(:filtered_nodes) do
|
319
|
+
[
|
320
|
+
MSFLVisitors::Nodes::GreaterThanEqual.new(
|
321
|
+
MSFLVisitors::Nodes::Field.new(:value),
|
322
|
+
MSFLVisitors::Nodes::Number.new(1000))
|
323
|
+
]
|
324
|
+
end
|
325
|
+
|
326
|
+
context "when using the TermFilter visitor" do
|
327
|
+
|
328
|
+
it "returns: value >= 1000" do
|
329
|
+
expect(result).to eq "value >= 1000"
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
context "when using the Aggregations visitor" do
|
334
|
+
|
335
|
+
before { visitor.mode = :aggregations }
|
336
|
+
|
337
|
+
it "returns: { range: { value: { gte: 1000 } } }" do
|
338
|
+
expect(result).to eq({ range: { value: { gte: 1000 } } })
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
context "when the filter has multiple children" do
|
343
|
+
|
344
|
+
let(:filtered_nodes) do
|
345
|
+
[
|
346
|
+
MSFLVisitors::Nodes::Equal.new(
|
347
|
+
MSFLVisitors::Nodes::Field.new(:make),
|
348
|
+
MSFLVisitors::Nodes::Word.new("Chevy")
|
349
|
+
),
|
350
|
+
MSFLVisitors::Nodes::GreaterThanEqual.new(
|
351
|
+
MSFLVisitors::Nodes::Field.new(:value),
|
352
|
+
MSFLVisitors::Nodes::Number.new(1000))
|
353
|
+
]
|
354
|
+
end
|
355
|
+
|
356
|
+
context "when using the TermFilter visitor" do
|
357
|
+
|
358
|
+
it "returns: ( make == \"Chevy\" ) & ( value >= 1000 )" do
|
359
|
+
expect(result).to eq "( make == \"Chevy\" ) & ( value >= 1000 )"
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
context "when using the Aggregations visitor" do
|
364
|
+
|
365
|
+
before { visitor.mode = :aggregations }
|
366
|
+
|
367
|
+
it "returns: { and: [{ term: { make: \"Chevy\" } },{ range: { value: { gte: 1000 } } }] }" do
|
368
|
+
expect(result).to eq({ and: [{ term: { make: "Chevy" } },{ range: { value: { gte: 1000 } } }] })
|
369
|
+
end
|
370
|
+
end
|
99
371
|
end
|
100
372
|
end
|
101
373
|
|
@@ -119,38 +391,89 @@ describe MSFLVisitors::Visitor do
|
|
119
391
|
|
120
392
|
let(:third) { MSFLVisitors::Nodes::Equal.new(third_field, third_value) }
|
121
393
|
|
394
|
+
let(:node) { MSFLVisitors::Nodes::And.new(set_node) }
|
395
|
+
|
122
396
|
context "when the And node has zero items" do
|
123
|
-
let(:node) { MSFLVisitors::Nodes::And.new([]) }
|
124
397
|
|
125
|
-
|
126
|
-
|
398
|
+
let(:set_node) { MSFLVisitors::Nodes::Set.new [] }
|
399
|
+
|
400
|
+
context "when using the TermFilter visitor" do
|
401
|
+
|
402
|
+
it "is empty" do
|
403
|
+
expect(result).to be_empty
|
404
|
+
end
|
405
|
+
end
|
406
|
+
|
407
|
+
context "when using the Aggregations visitor" do
|
408
|
+
|
409
|
+
before { visitor.mode = :aggregations }
|
410
|
+
|
411
|
+
it "returns: { and: [] }" do
|
412
|
+
expect(result).to eq({ and: [] })
|
413
|
+
end
|
127
414
|
end
|
128
415
|
end
|
129
416
|
|
130
417
|
context "when the node has one item" do
|
131
418
|
|
132
|
-
let(:
|
419
|
+
let(:set_node) { MSFLVisitors::Nodes::Set.new [first] }
|
420
|
+
|
421
|
+
context "when using the TermFilter visitor" do
|
133
422
|
|
134
|
-
|
135
|
-
|
423
|
+
it "returns: the item without adding parentheses" do
|
424
|
+
expect(result).to eq 'first_field == "first_word"'
|
425
|
+
end
|
426
|
+
end
|
427
|
+
|
428
|
+
context "when using the Aggregations visitor" do
|
429
|
+
|
430
|
+
before { visitor.mode = :aggregations }
|
431
|
+
|
432
|
+
it "returns: { and: [{ term: { first_field: \"first_word\" }] }" do
|
433
|
+
expect(result).to eq({ and: [{ term: { first_field: "first_word" } }] })
|
434
|
+
end
|
136
435
|
end
|
137
436
|
end
|
138
437
|
|
139
438
|
context "when the node has two items" do
|
140
439
|
|
141
|
-
let(:
|
440
|
+
let(:set_node) { MSFLVisitors::Nodes::Set.new [first, second] }
|
441
|
+
|
442
|
+
context "when using the TermFilter visitor" do
|
142
443
|
|
143
|
-
|
144
|
-
|
444
|
+
it "returns: '( first_field == \"first_word\" ) & ( second_field == \"second_word\" )'" do
|
445
|
+
expect(result).to eq '( first_field == "first_word" ) & ( second_field == "second_word" )'
|
446
|
+
end
|
447
|
+
end
|
448
|
+
|
449
|
+
context "when using the Aggregations visitor" do
|
450
|
+
|
451
|
+
before { visitor.mode = :aggregations }
|
452
|
+
|
453
|
+
it "returns: { and: [{ term: { first_field: \"first_word\" } },{ term: { second_field: \"second_word\" } }] }" do
|
454
|
+
expect(result).to eq({ and: [{ term: { first_field: "first_word" }}, { term: { second_field: "second_word" } }] })
|
455
|
+
end
|
145
456
|
end
|
146
457
|
end
|
147
458
|
|
148
459
|
context "when the node has three items" do
|
149
460
|
|
150
|
-
let(:
|
461
|
+
let(:set_node) { MSFLVisitors::Nodes::Set.new [first, second, third] }
|
151
462
|
|
152
|
-
|
153
|
-
|
463
|
+
context "when using the TermFilter visitor" do
|
464
|
+
|
465
|
+
it "returns: '( first_field == \"first_word\" ) & ( second_field == \"second_word\" ) & ( third_field == \"third_word\" )'" do
|
466
|
+
expect(result).to eq '( first_field == "first_word" ) & ( second_field == "second_word" ) & ( third_field == "third_word" )'
|
467
|
+
end
|
468
|
+
end
|
469
|
+
|
470
|
+
context "when using the Aggregations visitor" do
|
471
|
+
|
472
|
+
before { visitor.mode = :aggregations }
|
473
|
+
|
474
|
+
it "returns: { and: [{ term: { first_field: \"first_word\" } },{ term: { second_field: \"second_word\" } },{ term: { third_field: \"third_word\" } }] }" do
|
475
|
+
expect(result).to eq({ and: [{ term: { first_field: "first_word" } },{ term: { second_field: "second_word" } },{ term: { third_field: "third_word" } }] })
|
476
|
+
end
|
154
477
|
end
|
155
478
|
end
|
156
479
|
|
@@ -158,13 +481,13 @@ describe MSFLVisitors::Visitor do
|
|
158
481
|
|
159
482
|
let(:node) do
|
160
483
|
MSFLVisitors::Nodes::And.new(
|
161
|
-
MSFLVisitors::Nodes::Set
|
484
|
+
MSFLVisitors::Nodes::Set.new(
|
162
485
|
[
|
163
486
|
MSFLVisitors::Nodes::Filter.new(
|
164
487
|
[
|
165
488
|
MSFLVisitors::Nodes::Containment.new(
|
166
489
|
MSFLVisitors::Nodes::Field.new(:make),
|
167
|
-
MSFLVisitors::Nodes::Set
|
490
|
+
MSFLVisitors::Nodes::Set.new(
|
168
491
|
[
|
169
492
|
MSFLVisitors::Nodes::Word.new("Honda"),
|
170
493
|
MSFLVisitors::Nodes::Word.new("Chevy"),
|
@@ -187,8 +510,21 @@ describe MSFLVisitors::Visitor do
|
|
187
510
|
)
|
188
511
|
end
|
189
512
|
|
190
|
-
|
191
|
-
|
513
|
+
context "when using the TermFilter visitor" do
|
514
|
+
|
515
|
+
it "returns: '( make == [ \"Honda\" , \"Chevy\" , \"Volvo\" ] ) & ( value >= 1000 )'" do
|
516
|
+
expect(result).to eq '( make == [ "Honda" , "Chevy" , "Volvo" ] ) & ( value >= 1000 )'
|
517
|
+
end
|
518
|
+
end
|
519
|
+
|
520
|
+
context "when using the Aggregations visitor" do
|
521
|
+
|
522
|
+
before { visitor.mode = :aggregations }
|
523
|
+
|
524
|
+
it "returns: { and: [{ terms: { make: [\"Honda\",\"Chevy\",\"Volvo\"]} }, { range: { value: { gte: 1000 } } }] }" do
|
525
|
+
expected = { and: [{ terms: { make: ["Honda", "Chevy", "Volvo"]} }, { range: { value: { gte: 1000 } } }] }
|
526
|
+
expect(result).to eq expected
|
527
|
+
end
|
192
528
|
end
|
193
529
|
end
|
194
530
|
end
|
@@ -196,18 +532,28 @@ describe MSFLVisitors::Visitor do
|
|
196
532
|
describe "value nodes" do
|
197
533
|
describe "a Boolean node" do
|
198
534
|
|
199
|
-
let(:collector) { Array.new }
|
200
|
-
|
201
535
|
let(:node) { MSFLVisitors::Nodes::Boolean.new value }
|
202
536
|
|
203
|
-
subject(:result) { node.accept
|
537
|
+
subject(:result) { node.accept visitor }
|
204
538
|
|
205
539
|
context "with a value of true" do
|
206
540
|
|
207
541
|
let(:value) { true }
|
208
542
|
|
209
|
-
|
210
|
-
|
543
|
+
context "when using the TermFilter visitor" do
|
544
|
+
|
545
|
+
it "returns: true" do
|
546
|
+
expect(result).to eq true
|
547
|
+
end
|
548
|
+
end
|
549
|
+
|
550
|
+
context "when using the Aggregations visitor" do
|
551
|
+
|
552
|
+
before { visitor.mode = :aggregations }
|
553
|
+
|
554
|
+
it "returns: true" do
|
555
|
+
expect(result).to eq true
|
556
|
+
end
|
211
557
|
end
|
212
558
|
end
|
213
559
|
|
@@ -216,7 +562,16 @@ describe MSFLVisitors::Visitor do
|
|
216
562
|
let(:value) { false }
|
217
563
|
|
218
564
|
it "returns: false" do
|
219
|
-
expect(result).to
|
565
|
+
expect(result).to eq false
|
566
|
+
end
|
567
|
+
|
568
|
+
context "when using the Aggregations visitor" do
|
569
|
+
|
570
|
+
before { visitor.mode = :aggregations }
|
571
|
+
|
572
|
+
it "returns: false" do
|
573
|
+
expect(result).to eq false
|
574
|
+
end
|
220
575
|
end
|
221
576
|
end
|
222
577
|
end
|
@@ -230,14 +585,21 @@ describe MSFLVisitors::Visitor do
|
|
230
585
|
it "is a double quoted literal string" do
|
231
586
|
expect(result).to eq "\"#{word}\""
|
232
587
|
end
|
588
|
+
|
589
|
+
context "when using the Aggregations visitor" do
|
590
|
+
|
591
|
+
before { visitor.mode = :aggregations }
|
592
|
+
|
593
|
+
it "returns: the literal string" do
|
594
|
+
expect(result).to eq "#{word}"
|
595
|
+
end
|
596
|
+
end
|
233
597
|
end
|
234
598
|
end
|
235
599
|
|
236
600
|
describe "range value nodes" do
|
237
601
|
|
238
|
-
|
239
|
-
|
240
|
-
subject(:result) { node.accept(visitor).first }
|
602
|
+
subject(:result) { node.accept visitor }
|
241
603
|
|
242
604
|
describe "a Date node" do
|
243
605
|
|
@@ -246,7 +608,16 @@ describe MSFLVisitors::Visitor do
|
|
246
608
|
let(:node) { MSFLVisitors::Nodes::Date.new today }
|
247
609
|
|
248
610
|
it "returns: the date using iso8601 formatting" do
|
249
|
-
expect(result).to eq today.iso8601
|
611
|
+
expect(result).to eq "\"#{today.iso8601}\""
|
612
|
+
end
|
613
|
+
|
614
|
+
context "when using the Aggregations visitor" do
|
615
|
+
|
616
|
+
before { visitor.mode = :aggregations }
|
617
|
+
|
618
|
+
it "returns: the date using iso8601 formatting" do
|
619
|
+
expect(result).to eq "#{today.iso8601}"
|
620
|
+
end
|
250
621
|
end
|
251
622
|
end
|
252
623
|
|
@@ -257,7 +628,16 @@ describe MSFLVisitors::Visitor do
|
|
257
628
|
let(:node) { MSFLVisitors::Nodes::Time.new now }
|
258
629
|
|
259
630
|
it "returns: the time using iso8601 formatting" do
|
260
|
-
expect(result).to eq now.iso8601
|
631
|
+
expect(result).to eq "\"#{now.iso8601}\""
|
632
|
+
end
|
633
|
+
|
634
|
+
context "when using the Aggregations visitor" do
|
635
|
+
|
636
|
+
before { visitor.mode = :aggregations }
|
637
|
+
|
638
|
+
it "returns: the date using iso8601 formatting" do
|
639
|
+
expect(result).to eq "#{now.iso8601}"
|
640
|
+
end
|
261
641
|
end
|
262
642
|
end
|
263
643
|
|
@@ -268,7 +648,16 @@ describe MSFLVisitors::Visitor do
|
|
268
648
|
let(:node) { MSFLVisitors::Nodes::DateTime.new now }
|
269
649
|
|
270
650
|
it "returns: the date and time using iso8601 formatting" do
|
271
|
-
expect(result).to eq now.iso8601
|
651
|
+
expect(result).to eq "\"#{now.iso8601}\""
|
652
|
+
end
|
653
|
+
|
654
|
+
context "when using the Aggregations visitor" do
|
655
|
+
|
656
|
+
before { visitor.mode = :aggregations }
|
657
|
+
|
658
|
+
it "returns: the date and time using iso8601 formatting" do
|
659
|
+
expect(result).to eq "#{now.iso8601}"
|
660
|
+
end
|
272
661
|
end
|
273
662
|
end
|
274
663
|
|
@@ -278,10 +667,19 @@ describe MSFLVisitors::Visitor do
|
|
278
667
|
|
279
668
|
let(:node) { MSFLVisitors::Nodes::Number.new number }
|
280
669
|
|
281
|
-
it "returns:
|
670
|
+
it "returns: 123" do
|
282
671
|
expect(result).to eq number
|
283
672
|
end
|
284
673
|
|
674
|
+
context "when using the Aggregations visitor" do
|
675
|
+
|
676
|
+
before { visitor.mode = :aggregations }
|
677
|
+
|
678
|
+
it "returns: 123" do
|
679
|
+
expect(result).to eq number
|
680
|
+
end
|
681
|
+
end
|
682
|
+
|
285
683
|
context "when the number is a float" do
|
286
684
|
|
287
685
|
let(:number) { 123.456 }
|
@@ -289,6 +687,15 @@ describe MSFLVisitors::Visitor do
|
|
289
687
|
it "returns: the number with the same precision" do
|
290
688
|
expect(result).to eq number
|
291
689
|
end
|
690
|
+
|
691
|
+
context "when using the Aggregations visitor" do
|
692
|
+
|
693
|
+
before { visitor.mode = :aggregations }
|
694
|
+
|
695
|
+
it "returns: the number with the same precision" do
|
696
|
+
expect(result).to eq number
|
697
|
+
end
|
698
|
+
end
|
292
699
|
end
|
293
700
|
end
|
294
701
|
end
|