spec/piglet_spec.rb in piglet-0.2.0 vs spec/piglet_spec.rb in piglet-0.2.2

- old
+ new

@@ -391,10 +391,26 @@ store(b, 'out2') end @interpreter.to_pig_latin.should match(/(\w+) = LOAD 'in';\n(\w+) = DISTINCT \1;\nSTORE \2 INTO 'out1';\nSTORE \2 INTO 'out2';/) end end + + context 'field expressions' do + it 'doesn\'t parenthesizes expressions with the same operator' do + output = @interpreter.to_pig_latin do + store(load('in').filter { |r| r.x.and(r.y.and(r.z)).and(r.w) }, 'out') + end + output.should include('x AND y AND z AND w') + end + + it 'parenthesizes expressions with different operators' do + output = @interpreter.to_pig_latin do + store(load('in').filter { |r| r.x.and(r.y.or(r.z)).and(r.w) }, 'out') + end + output.should include('x AND (y OR z) AND w') + end + end context 'long and complex scripts' do before do @interpreter.interpret do sessions = load('sessions', :schema => [ @@ -577,10 +593,12 @@ relation2 = load('in2', :schema => [[:c, :int], [:d, :double]]) relation3 = relation1.cogroup(relation1 => :b, relation2 => :c) throw :relations, [relation1, relation2, relation3] end end - relation3.schema.field_names.should eql([:group, relation1.alias.to_sym, relation2.alias.to_sym]) + relation3.schema.field_names[0].should eql(:group) + relation3.schema.field_names.should include(relation1.alias.to_sym) + relation3.schema.field_names.should include(relation2.alias.to_sym) relation3.schema.field_type(relation1.alias.to_sym).should be_a(Piglet::Schema::Bag) relation3.schema.field_type(relation2.alias.to_sym).should be_a(Piglet::Schema::Bag) relation3.schema.field_type(relation1.alias.to_sym).field_names.should eql([:a, :b]) relation3.schema.field_type(relation2.alias.to_sym).field_names.should eql([:c, :d]) end