Sha256: 8cc3a6b8f25472a694fdefca79856db90ef0ec4079645da7b13cd5bad0e06a22

Contents?: true

Size: 1.34 KB

Versions: 2

Compression:

Stored size: 1.34 KB

Contents

require 'spec_helper'
module Alf
  module Engine
    describe SetAttr do

      it 'should work on an empty operand' do
        SetAttr.new(Leaf.new([]), TupleComputation[{}]).to_a.should eq([])
      end

      it 'should allow implementing UPDATE' do
        rel = Leaf.new [
          {:name => "Jones"},
          {:name => "Smith"}
        ]
        exp = [
          {:name => "JONES"},
          {:name => "SMITH"}
        ]
        comp = TupleComputation[:name => lambda{ name.upcase }]
        SetAttr.new(rel, comp).to_a.should eq(exp)
      end

      it 'should allow implementing EXTEND' do
        rel = Leaf.new [
          {:name => "Jones"},
          {:name => "Smith"}
        ]
        exp = [
          {:name => "Jones", :up => "JONES"},
          {:name => "Smith", :up => "SMITH"}
        ]
        comp = TupleComputation[:up => lambda{ name.upcase }]
        SetAttr.new(rel, comp).to_a.should eq(exp)
      end

      it 'should support lambda of arity 1' do
        rel = Leaf.new [
          {:name => "Jones"},
          {:name => "Smith"}
        ]
        exp = [
          {:name => "Jones", :up => "JONES"},
          {:name => "Smith", :up => "SMITH"}
        ]
        comp = TupleComputation[:up => lambda{|t| t.name.upcase }]
        SetAttr.new(rel, comp).to_a.should eq(exp)
      end

    end
  end # module Engine
end # module Alf

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
alf-core-0.15.0 spec/unit/alf-engine/test_set_attr.rb
alf-core-0.14.0 spec/unit/alf-engine/test_set_attr.rb