Sha256: 495ccc54d99fc8a5bf624159406fbde6d11be4cdf46f04eefbc72ce9bf63a627

Contents?: true

Size: 954 Bytes

Versions: 3

Compression:

Stored size: 954 Bytes

Contents

require 'spec_helper'
module Qrb
  describe SubType, "equality" do

    let(:c1){ ->(i){ i>0   } }
    let(:c2){ ->(i){ i<255 } }

    let(:type) { SubType.new(intType, default: c1)      }
    let(:type2){ SubType.new(intType, default: c1)      }
    let(:type3){ SubType.new(intType, another_name: c1) }
    let(:type4){ SubType.new(intType, default: c2)      }
    let(:type5){ SubType.new(floatType, default: c1)    }

    it 'should apply structural equality' do
      (type == type2).should be_true
      (type == type3).should be_true
    end

    it 'should apply distinguish different types' do
      (type == type4).should be_false
      (type == type5).should be_false
    end

    it 'should be a total function, with nil for non types' do
      (type == 12).should be_false
    end

    it 'should implement hash accordingly' do
      (type.hash == type2.hash).should be_true
      (type.hash == type3.hash).should be_true
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
qrb-0.3.0 spec/unit/type/sub_type/test_equality.rb
qrb-0.2.0 spec/unit/type/sub_type/test_equality.rb
qrb-0.1.0 spec/unit/type/sub_type/test_equality.rb