Sha256: bebb09b2e2116cce952a88fa58708b44f05faf14c9cae27a32478013db2545b9

Contents?: true

Size: 1.84 KB

Versions: 4

Compression:

Stored size: 1.84 KB

Contents

require 'spec_helper'
module Alf
  module Types
    describe TypeCheck, '===' do

      let(:heading){ Heading.new(name: String, status: Integer) }

      let(:tuple)  { {name: 'Smith', status: 20} }
      let(:missing){ {               status: 20} }
      let(:extra)  { {name: 'Smith', status: 20, foo: "bar"} }
      let(:mix)    { {               status: 20, foo: "bar"} }
      let(:invalid){ {name: 'Smith', status: "20"} }

      context 'when strict' do
        let(:type_check){ TypeCheck.new(heading) }
        
        it 'accepts the valid tuple only' do
          (type_check === tuple).should be_true
          (type_check === missing).should be_false
          (type_check === extra).should be_false
          (type_check === mix).should be_false
          (type_check === invalid).should be_false
        end
      end
      
      context 'when not strict' do
        let(:type_check){ TypeCheck.new(heading, false) }
      
        it 'accepts the valid tuple and its projections' do
          (type_check === tuple).should be_true
          (type_check === missing).should be_true
          (type_check === extra).should be_false
          (type_check === mix).should be_false
          (type_check === invalid).should be_false
        end
      end

      context 'when passed invalid tuples' do
        let(:type_check){ TypeCheck.new(heading) }
      
        it 'rejects them simply' do
          (type_check === 12).should be_false
          (type_check === nil).should be_false
          (type_check === self).should be_false
          (type_check === {'name' => 'Smith', 'status' => 20}).should be_false
        end
      end

      context 'when passed a real Tuple' do
        let(:type_check){ TypeCheck.new(heading) }
      
        it 'accepts it if valid' do
          (type_check === Tuple(tuple)).should be_true
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
alf-core-0.15.0 spec/unit/alf-types/type_check/test_triple_equal.rb
alf-core-0.14.0 spec/unit/alf-types/type_check/test_triple_equal.rb
alf-core-0.13.1 spec/unit/alf-types/type_check/test_triple_equal.rb
alf-core-0.13.0 spec/unit/alf-types/type_check/test_triple_equal.rb