rb: Thrift.check_type should check struct classes [THRIFT-185]
authorKevin Clark <kclark@apache.org>
Sat, 13 Dec 2008 02:39:20 +0000 (02:39 +0000)
committerKevin Clark <kclark@apache.org>
Sat, 13 Dec 2008 02:39:20 +0000 (02:39 +0000)
Author: Piotr Kozikowski

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@726156 13f79535-47bb-0310-9956-ffa450edef68

lib/rb/lib/thrift/types.rb
lib/rb/spec/types_spec.rb

index 3a83a9f..460f80f 100644 (file)
@@ -60,6 +60,8 @@ module Thrift
       value.each do |el|
         check_type(el, field[:element], "#{name}.element", false)
       end
+    when Types::STRUCT
+      raise TypeError, "Expected #{field[:class]}, received #{value.class} for field #{name}" unless field[:class] == value.class
     end
   end
 
index 183a354..873db30 100644 (file)
@@ -37,7 +37,7 @@ class ThriftTypesSpec < Spec::ExampleGroup
       lambda { Thrift.check_type("3",            {:type => Types::STRING}, :foo) }.should_not raise_error(TypeError)
       lambda { Thrift.check_type(3,              {:type => Types::STRING}, :foo) }.should raise_error(TypeError)
       hello = SpecNamespace::Hello.new
-      lambda { Thrift.check_type(hello,          {:type => Types::STRUCT}, :foo) }.should_not raise_error(TypeError)
+      lambda { Thrift.check_type(hello,          {:type => Types::STRUCT, :class => SpecNamespace::Hello}, :foo) }.should_not raise_error(TypeError)
       lambda { Thrift.check_type("foo",          {:type => Types::STRUCT}, :foo) }.should raise_error(TypeError)
       lambda { Thrift.check_type({:foo => 1},    {:type => Types::MAP},    :foo) }.should_not raise_error(TypeError)
       lambda { Thrift.check_type([1],            {:type => Types::MAP},    :foo) }.should raise_error(TypeError)
@@ -74,6 +74,9 @@ class ThriftTypesSpec < Spec::ExampleGroup
       lambda { Thrift.check_type(Set.new([1, 2]), field, :foo) }.should_not raise_error(TypeError)
       lambda { Thrift.check_type(Set.new([1, nil, 2]), field, :foo) }.should raise_error(TypeError)
       lambda { Thrift.check_type(Set.new([1, 2.3, 2]), field, :foo) }.should raise_error(TypeError)
+      
+      field = {:type => Types::STRUCT, :class => SpecNamespace::Hello}
+      lambda { Thrift.check_type(SpecNamespace::BoolStruct, field, :foo) }.should raise_error(TypeError)
     end
 
     it "should give the TypeError a readable message" do