You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by il...@apache.org on 2012/02/29 01:39:39 UTC
svn commit: r1294917 - in /thrift/trunk/lib/rb/spec: ThriftSpec.thrift
struct_nested_containers_spec.rb
Author: ilyam
Date: Wed Feb 29 00:39:38 2012
New Revision: 1294917
URL: http://svn.apache.org/viewvc?rev=1294917&view=rev
Log:
THRIFT-369: sets and maps break equality
Client: ruby
Patch: Ilya Maykov
Added a unit test demonstrating that equality is not broken for structs with nested containers.
Added:
thrift/trunk/lib/rb/spec/struct_nested_containers_spec.rb
Modified:
thrift/trunk/lib/rb/spec/ThriftSpec.thrift
Modified: thrift/trunk/lib/rb/spec/ThriftSpec.thrift
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/rb/spec/ThriftSpec.thrift?rev=1294917&r1=1294916&r2=1294917&view=diff
==============================================================================
--- thrift/trunk/lib/rb/spec/ThriftSpec.thrift (original)
+++ thrift/trunk/lib/rb/spec/ThriftSpec.thrift Wed Feb 29 00:39:38 2012
@@ -129,4 +129,55 @@ struct Struct_with_union {
struct StructWithEnumMap {
1: map<SomeEnum, list<SomeEnum>> my_map;
-}
\ No newline at end of file
+}
+
+# Nested lists
+struct NestedListInList {
+ 1: list<list<byte>> value
+}
+
+struct NestedListInSet {
+ 1: set<list<byte>> value
+}
+
+struct NestedListInMapKey {
+ 1: map<list<byte>, byte> value
+}
+
+struct NestedListInMapValue {
+ 1: map<byte, list<byte>> value
+}
+
+# Nested sets
+struct NestedSetInList {
+ 1: list<set<byte>> value
+}
+
+struct NestedSetInSet {
+ 1: set<set<byte>> value
+}
+
+struct NestedSetInMapKey {
+ 1: map<set<byte>, byte> value
+}
+
+struct NestedSetInMapValue {
+ 1: map<byte, set<byte>> value
+}
+
+# Nested maps
+struct NestedMapInList {
+ 1: list<map<byte, byte>> value
+}
+
+struct NestedMapInSet {
+ 1: set<map<byte, byte>> value
+}
+
+struct NestedMapInMapKey {
+ 2: map<map<byte, byte>, byte> value
+}
+
+struct NestedMapInMapValue {
+ 2: map<byte, map<byte, byte>> value
+}
Added: thrift/trunk/lib/rb/spec/struct_nested_containers_spec.rb
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/rb/spec/struct_nested_containers_spec.rb?rev=1294917&view=auto
==============================================================================
--- thrift/trunk/lib/rb/spec/struct_nested_containers_spec.rb (added)
+++ thrift/trunk/lib/rb/spec/struct_nested_containers_spec.rb Wed Feb 29 00:39:38 2012
@@ -0,0 +1,193 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
+
+class StructNestedContainersSpec < Spec::ExampleGroup
+ include Thrift
+ include SpecNamespace
+
+ def with_type_checking
+ saved_type_checking, Thrift.type_checking = Thrift.type_checking, true
+ begin
+ yield
+ ensure
+ Thrift.type_checking = saved_type_checking
+ end
+ end
+
+ describe Struct do
+ # Nested container tests, see THRIFT-369.
+ it "should support nested lists inside lists" do
+ with_type_checking do
+ a, b = NestedListInList.new, NestedListInList.new
+ [a, b].each do |thrift_struct|
+ thrift_struct.value = [ [1, 2, 3], [2, 3, 4] ]
+ thrift_struct.validate
+ end
+ a.should == b
+ b.value.push [3, 4, 5]
+ a.should_not == b
+ end
+ end
+
+ it "should support nested lists inside sets" do
+ with_type_checking do
+ a, b = NestedListInSet.new, NestedListInSet.new
+ [a, b].each do |thrift_struct|
+ thrift_struct.value = [ [1, 2, 3], [2, 3, 4] ].to_set
+ thrift_struct.validate
+ end
+ a.should == b
+ b.value.add [3, 4, 5]
+ a.should_not == b
+ end
+ end
+
+ it "should support nested lists in map keys" do
+ with_type_checking do
+ a, b = NestedListInMapKey.new, NestedListInMapKey.new
+ [a, b].each do |thrift_struct|
+ thrift_struct.value = { [1, 2, 3] => 1, [2, 3, 4] => 2 }
+ thrift_struct.validate
+ end
+ a.should == b
+ b.value[[3, 4, 5]] = 3
+ a.should_not == b
+ end
+ end
+
+ it "should support nested lists in map values" do
+ with_type_checking do
+ a, b = NestedListInMapValue.new, NestedListInMapValue.new
+ [a, b].each do |thrift_struct|
+ thrift_struct.value = { 1 => [1, 2, 3], 2 => [2, 3, 4] }
+ thrift_struct.validate
+ end
+ a.should == b
+ b.value[3] = [3, 4, 5]
+ a.should_not == b
+ end
+ end
+
+ it "should support nested sets inside lists" do
+ with_type_checking do
+ a, b = NestedSetInList.new, NestedSetInList.new
+ [a, b].each do |thrift_struct|
+ thrift_struct.value = [ [1, 2, 3].to_set, [2, 3, 4].to_set ]
+ thrift_struct.validate
+ end
+ a.should == b
+ b.value.push([3, 4, 5].to_set)
+ a.should_not == b
+ end
+ end
+
+ it "should support nested sets inside sets" do
+ with_type_checking do
+ a, b = NestedSetInSet.new, NestedSetInSet.new
+ [a, b].each do |thrift_struct|
+ thrift_struct.value = [ [1, 2, 3].to_set, [2, 3, 4].to_set ].to_set
+ thrift_struct.validate
+ end
+ a.should == b
+ b.value.add([3, 4, 5].to_set)
+ a.should_not == b
+ end
+ end
+
+ it "should support nested sets in map keys" do
+ with_type_checking do
+ a, b = NestedSetInMapKey.new, NestedSetInMapKey.new
+ [a, b].each do |thrift_struct|
+ thrift_struct.value = { [1, 2, 3].to_set => 1, [2, 3, 4].to_set => 2 }
+ thrift_struct.validate
+ end
+ a.should == b
+ b.value[[3, 4, 5].to_set] = 3
+ a.should_not == b
+ end
+ end
+
+ it "should support nested sets in map values" do
+ with_type_checking do
+ a, b = NestedSetInMapValue.new, NestedSetInMapValue.new
+ [a, b].each do |thrift_struct|
+ thrift_struct.value = { 1 => [1, 2, 3].to_set, 2 => [2, 3, 4].to_set }
+ thrift_struct.validate
+ end
+ a.should == b
+ b.value[3] = [3, 4, 5].to_set
+ a.should_not == b
+ end
+ end
+
+ it "should support nested maps inside lists" do
+ with_type_checking do
+ a, b = NestedMapInList.new, NestedMapInList.new
+ [a, b].each do |thrift_struct|
+ thrift_struct.value = [ {1 => 2, 3 => 4}, {2 => 3, 4 => 5} ]
+ thrift_struct.validate
+ end
+ a.should == b
+ b.value.push({ 3 => 4, 5 => 6 })
+ a.should_not == b
+ end
+ end
+
+ it "should support nested maps inside sets" do
+ with_type_checking do
+ a, b = NestedMapInSet.new, NestedMapInSet.new
+ [a, b].each do |thrift_struct|
+ thrift_struct.value = [ {1 => 2, 3 => 4}, {2 => 3, 4 => 5} ].to_set
+ thrift_struct.validate
+ end
+ a.should == b
+ b.value.add({ 3 => 4, 5 => 6 })
+ a.should_not == b
+ end
+ end
+
+ it "should support nested maps in map keys" do
+ with_type_checking do
+ a, b = NestedMapInMapKey.new, NestedMapInMapKey.new
+ [a, b].each do |thrift_struct|
+ thrift_struct.value = { { 1 => 2, 3 => 4} => 1, {2 => 3, 4 => 5} => 2 }
+ thrift_struct.validate
+ end
+ a.should == b
+ b.value[{3 => 4, 5 => 6}] = 3
+ a.should_not == b
+ end
+ end
+
+ it "should support nested maps in map values" do
+ with_type_checking do
+ a, b = NestedMapInMapValue.new, NestedMapInMapValue.new
+ [a, b].each do |thrift_struct|
+ thrift_struct.value = { 1 => { 1 => 2, 3 => 4}, 2 => {2 => 3, 4 => 5} }
+ thrift_struct.validate
+ end
+ a.should == b
+ b.value[3] = { 3 => 4, 5 => 6 }
+ a.should_not == b
+ end
+ end
+ end
+end