]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/rb/spec/struct_nested_containers_spec.rb
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / thrift / lib / rb / spec / struct_nested_containers_spec.rb
1 #
2 # Licensed to the Apache Software Foundation (ASF) under one
3 # or more contributor license agreements. See the NOTICE file
4 # distributed with this work for additional information
5 # regarding copyright ownership. The ASF licenses this file
6 # to you under the Apache License, Version 2.0 (the
7 # "License"); you may not use this file except in compliance
8 # with the License. You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing,
13 # software distributed under the License is distributed on an
14 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 # KIND, either express or implied. See the License for the
16 # specific language governing permissions and limitations
17 # under the License.
18 #
19
20 require 'spec_helper'
21
22 describe 'StructNestedContainers' do
23
24 def with_type_checking
25 saved_type_checking, Thrift.type_checking = Thrift.type_checking, true
26 begin
27 yield
28 ensure
29 Thrift.type_checking = saved_type_checking
30 end
31 end
32
33 describe Thrift::Struct do
34 # Nested container tests, see THRIFT-369.
35 it "should support nested lists inside lists" do
36 with_type_checking do
37 a, b = SpecNamespace::NestedListInList.new, SpecNamespace::NestedListInList.new
38 [a, b].each do |thrift_struct|
39 thrift_struct.value = [ [1, 2, 3], [2, 3, 4] ]
40 thrift_struct.validate
41 end
42 expect(a).to eq(b)
43 b.value.push [3, 4, 5]
44 expect(a).not_to eq(b)
45 end
46 end
47
48 it "should support nested lists inside sets" do
49 with_type_checking do
50 a, b = SpecNamespace::NestedListInSet.new, SpecNamespace::NestedListInSet.new
51 [a, b].each do |thrift_struct|
52 thrift_struct.value = [ [1, 2, 3], [2, 3, 4] ].to_set
53 thrift_struct.validate
54 end
55 expect(a).to eq(b)
56 b.value.add [3, 4, 5]
57 expect(a).not_to eq(b)
58 end
59 end
60
61 it "should support nested lists in map keys" do
62 with_type_checking do
63 a, b = SpecNamespace::NestedListInMapKey.new, SpecNamespace::NestedListInMapKey.new
64 [a, b].each do |thrift_struct|
65 thrift_struct.value = { [1, 2, 3] => 1, [2, 3, 4] => 2 }
66 thrift_struct.validate
67 end
68 expect(a).to eq(b)
69 b.value[[3, 4, 5]] = 3
70 expect(a).not_to eq(b)
71 end
72 end
73
74 it "should support nested lists in map values" do
75 with_type_checking do
76 a, b = SpecNamespace::NestedListInMapValue.new, SpecNamespace::NestedListInMapValue.new
77 [a, b].each do |thrift_struct|
78 thrift_struct.value = { 1 => [1, 2, 3], 2 => [2, 3, 4] }
79 thrift_struct.validate
80 end
81 expect(a).to eq(b)
82 b.value[3] = [3, 4, 5]
83 expect(a).not_to eq(b)
84 end
85 end
86
87 it "should support nested sets inside lists" do
88 with_type_checking do
89 a, b = SpecNamespace::NestedSetInList.new, SpecNamespace::NestedSetInList.new
90 [a, b].each do |thrift_struct|
91 thrift_struct.value = [ [1, 2, 3].to_set, [2, 3, 4].to_set ]
92 thrift_struct.validate
93 end
94 expect(a).to eq(b)
95 b.value.push([3, 4, 5].to_set)
96 expect(a).not_to eq(b)
97 end
98 end
99
100 it "should support nested sets inside sets" do
101 with_type_checking do
102 a, b = SpecNamespace::NestedSetInSet.new, SpecNamespace::NestedSetInSet.new
103 [a, b].each do |thrift_struct|
104 thrift_struct.value = [ [1, 2, 3].to_set, [2, 3, 4].to_set ].to_set
105 thrift_struct.validate
106 end
107 expect(a).to eq(b)
108 b.value.add([3, 4, 5].to_set)
109 expect(a).not_to eq(b)
110 end
111 end
112
113 it "should support nested sets in map keys" do
114 with_type_checking do
115 a, b = SpecNamespace::NestedSetInMapKey.new, SpecNamespace::NestedSetInMapKey.new
116 [a, b].each do |thrift_struct|
117 thrift_struct.value = { [1, 2, 3].to_set => 1, [2, 3, 4].to_set => 2 }
118 thrift_struct.validate
119 end
120 expect(a).to eq(b)
121 b.value[[3, 4, 5].to_set] = 3
122 expect(a).not_to eq(b)
123 end
124 end
125
126 it "should support nested sets in map values" do
127 with_type_checking do
128 a, b = SpecNamespace::NestedSetInMapValue.new, SpecNamespace::NestedSetInMapValue.new
129 [a, b].each do |thrift_struct|
130 thrift_struct.value = { 1 => [1, 2, 3].to_set, 2 => [2, 3, 4].to_set }
131 thrift_struct.validate
132 end
133 expect(a).to eq(b)
134 b.value[3] = [3, 4, 5].to_set
135 expect(a).not_to eq(b)
136 end
137 end
138
139 it "should support nested maps inside lists" do
140 with_type_checking do
141 a, b = SpecNamespace::NestedMapInList.new, SpecNamespace::NestedMapInList.new
142 [a, b].each do |thrift_struct|
143 thrift_struct.value = [ {1 => 2, 3 => 4}, {2 => 3, 4 => 5} ]
144 thrift_struct.validate
145 end
146 expect(a).to eq(b)
147 b.value.push({ 3 => 4, 5 => 6 })
148 expect(a).not_to eq(b)
149 end
150 end
151
152 it "should support nested maps inside sets" do
153 with_type_checking do
154 a, b = SpecNamespace::NestedMapInSet.new, SpecNamespace::NestedMapInSet.new
155 [a, b].each do |thrift_struct|
156 thrift_struct.value = [ {1 => 2, 3 => 4}, {2 => 3, 4 => 5} ].to_set
157 thrift_struct.validate
158 end
159 expect(a).to eq(b)
160 b.value.add({ 3 => 4, 5 => 6 })
161 expect(a).not_to eq(b)
162 end
163 end
164
165 it "should support nested maps in map keys" do
166 with_type_checking do
167 a, b = SpecNamespace::NestedMapInMapKey.new, SpecNamespace::NestedMapInMapKey.new
168 [a, b].each do |thrift_struct|
169 thrift_struct.value = { { 1 => 2, 3 => 4} => 1, {2 => 3, 4 => 5} => 2 }
170 thrift_struct.validate
171 end
172 expect(a).to eq(b)
173 b.value[{3 => 4, 5 => 6}] = 3
174 expect(a).not_to eq(b)
175 end
176 end
177
178 it "should support nested maps in map values" do
179 with_type_checking do
180 a, b = SpecNamespace::NestedMapInMapValue.new, SpecNamespace::NestedMapInMapValue.new
181 [a, b].each do |thrift_struct|
182 thrift_struct.value = { 1 => { 1 => 2, 3 => 4}, 2 => {2 => 3, 4 => 5} }
183 thrift_struct.validate
184 end
185 expect(a).to eq(b)
186 b.value[3] = { 3 => 4, 5 => 6 }
187 expect(a).not_to eq(b)
188 end
189 end
190 end
191 end