spec/registry_spec.rb in bindata-0.9.3 vs spec/registry_spec.rb in bindata-0.10.0

- old
+ new

@@ -2,21 +2,32 @@ require File.expand_path(File.dirname(__FILE__)) + '/spec_common' require 'bindata/registry' describe BinData::Registry do + before(:all) do + A = Class.new + B = Class.new + C = Class.new + D = Class.new + end + before(:each) do - @r = BinData::Registry.instance + @r = BinData::Registry.new end - it "should be a singleton" do - BinData::Registry.instance.should == BinData::Registry.instance + it "should determine if a name is registered" do + @r.register('A', A) + + @r.is_registered?('a').should be_true end + it "should determine if a name is not registered" do + @r.is_registered?('xyz').should be_false + end + it "should lookup registered names" do - A = Class.new - B = Class.new @r.register('ASubClass', A) @r.register('AnotherSubClass', B) @r.lookup('a_sub_class').should == A @r.lookup('another_sub_class').should == B @@ -24,24 +35,54 @@ it "should not lookup unregistered names" do @r.lookup('a_non_existent_sub_class').should be_nil end + it "should allow overriding of registered classes" do + @r.register('A', A) + @r.register('A', B) + + @r.lookup('a').should == B + end + it "should convert CamelCase to underscores" do - @r.register('CamelCase', A).should == 'camel_case' + @r.underscore_name('CamelCase').should == 'camel_case' end it "should convert adjacent caps camelCase to underscores" do - @r.register('XYZCamelCase', A).should == 'xyz_camel_case' + @r.underscore_name('XYZCamelCase').should == 'xyz_camel_case' end it "should ignore the outer nestings of classes" do - @r.register('A::B::C', A).should == 'c' + @r.underscore_name('A::B::C').should == 'c' end - it "should allow overriding of registered classes" do - @r.register('A', A) - @r.register('A', B) + it "should lookup integers with endian" do +# @r.register("Int24be", A) +# @r.register("Int24le", B) +# @r.register("Uint24be", C) +# @r.register("Uint24le", D) +# +# @r.lookup("int24", :big).should == A +# @r.lookup("int24", :little).should == B +# @r.lookup("uint24", :big).should == C +# @r.lookup("uint24", :little).should == D + end - @r.lookup('a').should == B + it "should not lookup integers without endian" do +# @r.register("Int24be", A) + +# @r.lookup("int24").should be_nil + end + + it "should lookup floats with endian" do +# @r.register("FloatBe", A) +# @r.register("FloatLe", B) +# @r.register("DoubleBe", C) +# @r.register("DoubleLe", D) +# +# @r.lookup("float", :big).should == A +# @r.lookup("float", :little).should == B +# @r.lookup("double", :big).should == C +# @r.lookup("double", :little).should == D end end