Sha256: 5ac2bbc80019f6ce9986aa7a62814e532dcbb3240974fc0752a500b8d717179e

Contents?: true

Size: 1.45 KB

Versions: 2

Compression:

Stored size: 1.45 KB

Contents

# encoding: utf-8

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')


include Piglet::Field


describe BinaryConditional do

  before do
    @true_test = mock('test expression')
    @true_test.stub!(:to_s).and_return('true')
    @expressions = {}
    [:int, :long, :float, :double, :chararray, :bytearray, :bag, :tuple].each do |type|
      @expressions[type] = mock("#{type} expression")
      @expressions[type].extend Field
      @expressions[type].stub!(:type).and_return(type)
    end
  end
  
  describe '#type' do
    it 'returns the type of the true expression' do
      bincond = BinaryConditional.new(@true_test, @expressions[:int], @expressions[:float])
      bincond.type.should == :int
    end
    
    it 'returns int if the true expression is an Integer' do
      bincond = BinaryConditional.new(@true_test, 3, @expressions[:float])
      bincond.type.should == :int
    end
    
    it 'returns float if the true expression is a Float' do
      bincond = BinaryConditional.new(@true_test, 3.14, @expressions[:float])
      bincond.type.should == :float
    end
    
    it 'returns boolean if the true expression is true' do
      bincond = BinaryConditional.new(@true_test, true, @expressions[:float])
      bincond.type.should == :boolean
    end

    it 'returns boolean if the true expression is false' do
      bincond = BinaryConditional.new(@true_test, false, @expressions[:float])
      bincond.type.should == :boolean
    end
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
piglet-0.3.0 spec/piglet/field/binary_conditional_spec.rb
piglet-0.2.5 spec/piglet/field/binary_conditional_spec.rb