Sha256: 34a2c02d3a953c619f6ffb09dcbbcf984dd76388c5bfeace6837603e984c5b2c

Contents?: true

Size: 1.06 KB

Versions: 12

Compression:

Stored size: 1.06 KB

Contents

require 'epitools'

describe TypedStruct do

  it "works" do
    t = TypedStruct["a:int b c:boolean d:timestamp"].new

                 t.a.should == nil
    t.a = "111"; t.a.should == 111
    t.b = "111"; t.b.should == "111"
    t.c = "yes"; t.c.should == true
    #t.c?.should == true
  end

  it "compact syntaxes" do
    t = TypedStruct["a,b:int c,d:bool"].new(1,2,1,0)
    t.a.should == 1
    t.b.should == 2
    t.c.should == true
    t.d.should == false
  end

  it "wildcardses" do
    t = TypedStruct["a:int *"].new

                 t.a.should == nil
    t.a = "111"; t.a.should == 111

                 t.q.should == nil
    t.q = "111"; t.q.should == "111"
  end

  it "drops unknowns" do

    ts = TypedStruct["a:int"]
    lambda { ts.new a: 1, b: 2 }.should raise_error

    ts = TypedStruct["a:int -"]
    lambda {
      t = ts.new a: 1, b: 2
      t.a.should == 1
      lambda { t.b }.should raise_error
    }.should_not raise_error
  end

  it "can't use wildcard and drop unknown at once" do
    lambda { TypedStruct["a:int - *"].new }.should raise_error
  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
epitools-0.5.116 spec/typed_struct_spec.rb
epitools-0.5.115 spec/typed_struct_spec.rb
epitools-0.5.114 spec/typed_struct_spec.rb
epitools-0.5.113 spec/typed_struct_spec.rb
epitools-0.5.112 spec/typed_struct_spec.rb
epitools-0.5.111 spec/typed_struct_spec.rb
epitools-0.5.110 spec/typed_struct_spec.rb
epitools-0.5.109 spec/typed_struct_spec.rb
epitools-0.5.108 spec/typed_struct_spec.rb
epitools-0.5.107 spec/typed_struct_spec.rb
epitools-0.5.106 spec/typed_struct_spec.rb
epitools-0.5.105 spec/typed_struct_spec.rb