piglet 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/piglet/field/field.rb +1 -1
- data/lib/piglet/field/infix_expression.rb +2 -0
- data/lib/piglet/field/prefix_expression.rb +3 -1
- data/lib/piglet.rb +1 -1
- data/spec/piglet_spec.rb +24 -3
- metadata +1 -1
data/lib/piglet/field/field.rb
CHANGED
@@ -2,6 +2,8 @@ module Piglet
|
|
2
2
|
module Field
|
3
3
|
class PrefixExpression # :nodoc:
|
4
4
|
include Field
|
5
|
+
|
6
|
+
attr_reader :operator
|
5
7
|
|
6
8
|
def initialize(operator, expression, space_between=true, options=nil)
|
7
9
|
options ||= {}
|
@@ -10,7 +12,7 @@ module Piglet
|
|
10
12
|
end
|
11
13
|
|
12
14
|
def simple?
|
13
|
-
|
15
|
+
false
|
14
16
|
end
|
15
17
|
|
16
18
|
def to_s
|
data/lib/piglet.rb
CHANGED
data/spec/piglet_spec.rb
CHANGED
@@ -395,6 +395,13 @@ describe Piglet do
|
|
395
395
|
end
|
396
396
|
|
397
397
|
context 'field expressions' do
|
398
|
+
it 'parenthesizes expressions with different operators' do
|
399
|
+
output = @interpreter.to_pig_latin do
|
400
|
+
store(load('in').filter { |r| r.x.and(r.y.or(r.z)).and(r.w) }, 'out')
|
401
|
+
end
|
402
|
+
output.should include('x AND (y OR z) AND w')
|
403
|
+
end
|
404
|
+
|
398
405
|
it 'doesn\'t parenthesizes expressions with the same operator' do
|
399
406
|
output = @interpreter.to_pig_latin do
|
400
407
|
store(load('in').filter { |r| r.x.and(r.y.and(r.z)).and(r.w) }, 'out')
|
@@ -402,11 +409,25 @@ describe Piglet do
|
|
402
409
|
output.should include('x AND y AND z AND w')
|
403
410
|
end
|
404
411
|
|
405
|
-
it '
|
412
|
+
it 'doesn\'t parenthesize function calls' do
|
406
413
|
output = @interpreter.to_pig_latin do
|
407
|
-
store(load('in').
|
414
|
+
store(load('in').foreach { |r| [r.x.max + r.y.min] }, 'out')
|
408
415
|
end
|
409
|
-
output.should include('x
|
416
|
+
output.should include('MAX(x) + MIN(y)')
|
417
|
+
end
|
418
|
+
|
419
|
+
it 'doesn\'t parenthesize a suffix expression followed by an infix expression' do
|
420
|
+
output = @interpreter.to_pig_latin do
|
421
|
+
store(load('in').foreach { |r| [r.x.null?.or(r.y)] }, 'out')
|
422
|
+
end
|
423
|
+
output.should include('x is null OR y')
|
424
|
+
end
|
425
|
+
|
426
|
+
it 'parenthesizes a prefix expression followed by an infix expression' do
|
427
|
+
output = @interpreter.to_pig_latin do
|
428
|
+
store(load('in').foreach { |r| [r.x.not.and(r.y)] }, 'out')
|
429
|
+
end
|
430
|
+
output.should include('(NOT x) AND y')
|
410
431
|
end
|
411
432
|
end
|
412
433
|
|