Sha256: 0f5171172fd154786f264a8587b16bfca11ff5bdd5496cb452fd1560e18aafc3
Contents?: true
Size: 1.35 KB
Versions: 2
Compression:
Stored size: 1.35 KB
Contents
require 'spec_helper' describe TypeConstraints do TypeConstraints.setup do type :TypeName do constraint -> v { v.kind_of?(Array) } end subtype :TypeName2, :TypeName do constraint -> array { array.all? do |v| v.kind_of?(String) end } end end describe "#setup" do it "Created registry" do expect(TypeConstraints.registry.class).to eq TypeConstraints::Registry end it "registry has TypeName meta" do expect(TypeConstraints.registry.metas[:TypeName].nil?).to eq false expect(TypeConstraints.registry.metas[:TypeName].constraint.class).to eq Proc end end describe "#check?" do it "return true if passed :TypeName and array" do expect(TypeConstraints.check?(:TypeName, [100,101,102])).to eq true end it "return false if passed :TypeName and integer" do expect(TypeConstraints.check?(:TypeName, 10000000000000)).to eq false end it "return true if passed :TypeName2 and Array[string]" do expect(TypeConstraints.check?(:TypeName2, ["100", "200"])).to eq true end it "return false if passed :TypeName2 and Array[integer]" do expect(TypeConstraints.check?(:TypeName2, [100, 200])).to eq false end it "return false if not exists meta" do expect(TypeConstraints.check?(:Hoge, [100, 200])).to eq false end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
type_constraints-0.1.0 | spec/type_constraints_spec.rb |
type_constraints-0.0.1 | spec/type_constraints_spec.rb |