Sha256: 1bda05f27479e1e27c579ce5fcebdd8a05b68ad61c06274804c18859030a7a65

Contents?: true

Size: 1.07 KB

Versions: 33

Compression:

Stored size: 1.07 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

33 entries across 33 versions & 1 rubygems

Version Path
epitools-0.5.81 spec/typed_struct_spec.rb
epitools-0.5.79 spec/typed_struct_spec.rb
epitools-0.5.78 spec/typed_struct_spec.rb
epitools-0.5.77 spec/typed_struct_spec.rb
epitools-0.5.75 spec/typed_struct_spec.rb
epitools-0.5.74 spec/typed_struct_spec.rb
epitools-0.5.73 spec/typed_struct_spec.rb
epitools-0.5.72 spec/typed_struct_spec.rb
epitools-0.5.71 spec/typed_struct_spec.rb
epitools-0.5.70 spec/typed_struct_spec.rb
epitools-0.5.69 spec/typed_struct_spec.rb
epitools-0.5.68 spec/typed_struct_spec.rb
epitools-0.5.67 spec/typed_struct_spec.rb