Sha256: 7e099560a9a561a115bc10889658211af6f742b8fc83e83234961a9e0359bdc2

Contents?: true

Size: 1.1 KB

Versions: 15

Compression:

Stored size: 1.1 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(NoMethodError)

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

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

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
epitools-0.5.136 spec/typed_struct_spec.rb
epitools-0.5.134 spec/typed_struct_spec.rb
epitools-0.5.133 spec/typed_struct_spec.rb
epitools-0.5.131 spec/typed_struct_spec.rb
epitools-0.5.130 spec/typed_struct_spec.rb
epitools-0.5.129 spec/typed_struct_spec.rb
epitools-0.5.128 spec/typed_struct_spec.rb
epitools-0.5.126 spec/typed_struct_spec.rb
epitools-0.5.125 spec/typed_struct_spec.rb
epitools-0.5.124 spec/typed_struct_spec.rb
epitools-0.5.123 spec/typed_struct_spec.rb
epitools-0.5.122 spec/typed_struct_spec.rb
epitools-0.5.121 spec/typed_struct_spec.rb
epitools-0.5.119 spec/typed_struct_spec.rb
epitools-0.5.118 spec/typed_struct_spec.rb