blob: 36c738ec71a52294a4f6bca24d15175137e45614 [file] [log] [blame]
David Reissea2cba82009-03-30 21:35:00 +00001#
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
Jake Farrella87810f2012-09-28 01:59:04 +000020require 'spec_helper'
Kevin Clark03d7a472008-06-18 01:09:41 +000021
Jake Farrella87810f2012-09-28 01:59:04 +000022describe 'Struct' do
Kevin Clark03d7a472008-06-18 01:09:41 +000023
Jake Farrella87810f2012-09-28 01:59:04 +000024 describe Thrift::Struct do
Kevin Clark140b5552008-06-18 01:17:57 +000025 it "should iterate over all fields properly" do
26 fields = {}
Jake Farrella87810f2012-09-28 01:59:04 +000027 SpecNamespace::Foo.new.each_field { |fid,field_info| fields[fid] = field_info }
James E. King III27247072018-03-22 20:50:23 -040028 expect(fields).to eq(SpecNamespace::Foo::FIELDS)
Kevin Clark9479b1a2008-06-18 01:13:37 +000029 end
Kevin Clark9479b1a2008-06-18 01:13:37 +000030
Kevin Clark140b5552008-06-18 01:17:57 +000031 it "should initialize all fields to defaults" do
Jake Farrella87810f2012-09-28 01:59:04 +000032 validate_default_arguments(SpecNamespace::Foo.new)
Bryan Duxbury6a1fb172010-09-21 16:30:58 +000033 end
34
35 it "should initialize all fields to defaults and accept a block argument" do
Jake Farrella87810f2012-09-28 01:59:04 +000036 SpecNamespace::Foo.new do |f|
Bryan Duxbury6a1fb172010-09-21 16:30:58 +000037 validate_default_arguments(f)
38 end
39 end
40
41 def validate_default_arguments(object)
James E. King III27247072018-03-22 20:50:23 -040042 expect(object.simple).to eq(53)
43 expect(object.words).to eq("words")
44 expect(object.hello).to eq(SpecNamespace::Hello.new(:greeting => 'hello, world!'))
45 expect(object.ints).to eq([1, 2, 2, 3])
46 expect(object.complex).to be_nil
47 expect(object.shorts).to eq(Set.new([5, 17, 239]))
Kevin Clark140b5552008-06-18 01:17:57 +000048 end
Kevin Clark1cfd6932008-06-18 01:13:58 +000049
Kevin Clark140b5552008-06-18 01:17:57 +000050 it "should not share default values between instances" do
51 begin
Jake Farrella87810f2012-09-28 01:59:04 +000052 struct = SpecNamespace::Foo.new
Kevin Clark140b5552008-06-18 01:17:57 +000053 struct.ints << 17
James E. King III27247072018-03-22 20:50:23 -040054 expect(SpecNamespace::Foo.new.ints).to eq([1,2,2,3])
Kevin Clark140b5552008-06-18 01:17:57 +000055 ensure
56 # ensure no leakage to other tests
Jake Farrella87810f2012-09-28 01:59:04 +000057 SpecNamespace::Foo::FIELDS[4][:default] = [1,2,2,3]
Kevin Clark140b5552008-06-18 01:17:57 +000058 end
59 end
Kevin Clark03d7a472008-06-18 01:09:41 +000060
Kevin Clark140b5552008-06-18 01:17:57 +000061 it "should properly initialize boolean values" do
Jake Farrella87810f2012-09-28 01:59:04 +000062 struct = SpecNamespace::BoolStruct.new(:yesno => false)
James E. King III27247072018-03-22 20:50:23 -040063 expect(struct.yesno).to be_falsey
Kevin Clark140b5552008-06-18 01:17:57 +000064 end
Kevin Clark03d7a472008-06-18 01:09:41 +000065
Kevin Clark140b5552008-06-18 01:17:57 +000066 it "should have proper == semantics" do
James E. King III27247072018-03-22 20:50:23 -040067 expect(SpecNamespace::Foo.new).not_to eq(SpecNamespace::Hello.new)
68 expect(SpecNamespace::Foo.new).to eq(SpecNamespace::Foo.new)
69 expect(SpecNamespace::Foo.new(:simple => 52)).not_to eq(SpecNamespace::Foo.new)
Kevin Clark140b5552008-06-18 01:17:57 +000070 end
Kevin Clark03d7a472008-06-18 01:09:41 +000071
Bryan Duxbury3d03c522010-02-18 17:42:06 +000072 it "should print enum value names in inspect" do
James E. King III27247072018-03-22 20:50:23 -040073 expect(SpecNamespace::StructWithSomeEnum.new(:some_enum => SpecNamespace::SomeEnum::ONE).inspect).to eq("<SpecNamespace::StructWithSomeEnum some_enum:ONE (0)>")
Bryan Duxbury3d03c522010-02-18 17:42:06 +000074
James E. King III27247072018-03-22 20:50:23 -040075 expect(SpecNamespace::StructWithEnumMap.new(:my_map => {SpecNamespace::SomeEnum::ONE => [SpecNamespace::SomeEnum::TWO]}).inspect).to eq("<SpecNamespace::StructWithEnumMap my_map:{ONE (0): [TWO (1)]}>")
Bryan Duxbury3d03c522010-02-18 17:42:06 +000076 end
77
Bryan Duxbury39dadd62010-02-18 22:00:45 +000078 it "should pretty print binary fields" do
James E. King III27247072018-03-22 20:50:23 -040079 expect(SpecNamespace::Foo2.new(:my_binary => "\001\002\003").inspect).to eq("<SpecNamespace::Foo2 my_binary:010203>")
Bryan Duxbury39dadd62010-02-18 22:00:45 +000080 end
81
Bryan Duxbury0e4920c2010-02-18 20:28:27 +000082 it "should offer field? methods" do
James E. King III27247072018-03-22 20:50:23 -040083 expect(SpecNamespace::Foo.new.opt_string?).to be_falsey
84 expect(SpecNamespace::Foo.new(:simple => 52).simple?).to be_truthy
85 expect(SpecNamespace::Foo.new(:my_bool => false).my_bool?).to be_truthy
86 expect(SpecNamespace::Foo.new(:my_bool => true).my_bool?).to be_truthy
Bryan Duxbury0e4920c2010-02-18 20:28:27 +000087 end
88
Bryan Duxbury205e4502010-02-18 23:19:42 +000089 it "should be comparable" do
Jake Farrella87810f2012-09-28 01:59:04 +000090 s1 = SpecNamespace::StructWithSomeEnum.new(:some_enum => SpecNamespace::SomeEnum::ONE)
91 s2 = SpecNamespace::StructWithSomeEnum.new(:some_enum => SpecNamespace::SomeEnum::TWO)
Bryan Duxbury205e4502010-02-18 23:19:42 +000092
James E. King III27247072018-03-22 20:50:23 -040093 expect(s1 <=> s2).to eq(-1)
94 expect(s2 <=> s1).to eq(1)
95 expect(s1 <=> s1).to eq(0)
96 expect(s1 <=> SpecNamespace::StructWithSomeEnum.new()).to eq(-1)
Bryan Duxbury205e4502010-02-18 23:19:42 +000097 end
98
Kevin Clark140b5552008-06-18 01:17:57 +000099 it "should read itself off the wire" do
Jake Farrella87810f2012-09-28 01:59:04 +0000100 struct = SpecNamespace::Foo.new
James E. King III27247072018-03-22 20:50:23 -0400101 prot = Thrift::BaseProtocol.new(double("transport"))
102 expect(prot).to receive(:read_struct_begin).twice
103 expect(prot).to receive(:read_struct_end).twice
104 expect(prot).to receive(:read_field_begin).and_return(
Jake Farrella87810f2012-09-28 01:59:04 +0000105 ['complex', Thrift::Types::MAP, 5], # Foo
106 ['words', Thrift::Types::STRING, 2], # Foo
107 ['hello', Thrift::Types::STRUCT, 3], # Foo
108 ['greeting', Thrift::Types::STRING, 1], # Hello
109 [nil, Thrift::Types::STOP, 0], # Hello
110 ['simple', Thrift::Types::I32, 1], # Foo
111 ['ints', Thrift::Types::LIST, 4], # Foo
112 ['shorts', Thrift::Types::SET, 6], # Foo
113 [nil, Thrift::Types::STOP, 0] # Hello
Kevin Clark140b5552008-06-18 01:17:57 +0000114 )
James E. King III27247072018-03-22 20:50:23 -0400115 expect(prot).to receive(:read_field_end).exactly(7).times
116 expect(prot).to receive(:read_map_begin).and_return(
Jake Farrella87810f2012-09-28 01:59:04 +0000117 [Thrift::Types::I32, Thrift::Types::MAP, 2], # complex
118 [Thrift::Types::STRING, Thrift::Types::DOUBLE, 2], # complex/1/value
119 [Thrift::Types::STRING, Thrift::Types::DOUBLE, 1] # complex/2/value
Kevin Clark140b5552008-06-18 01:17:57 +0000120 )
James E. King III27247072018-03-22 20:50:23 -0400121 expect(prot).to receive(:read_map_end).exactly(3).times
122 expect(prot).to receive(:read_list_begin).and_return([Thrift::Types::I32, 4])
123 expect(prot).to receive(:read_list_end)
124 expect(prot).to receive(:read_set_begin).and_return([Thrift::Types::I16, 2])
125 expect(prot).to receive(:read_set_end)
126 expect(prot).to receive(:read_i32).and_return(
Kevin Clark140b5552008-06-18 01:17:57 +0000127 1, 14, # complex keys
128 42, # simple
129 4, 23, 4, 29 # ints
130 )
James E. King III27247072018-03-22 20:50:23 -0400131 expect(prot).to receive(:read_string).and_return("pi", "e", "feigenbaum", "apple banana", "what's up?")
132 expect(prot).to receive(:read_double).and_return(Math::PI, Math::E, 4.669201609)
133 expect(prot).to receive(:read_i16).and_return(2, 3)
134 expect(prot).not_to receive(:skip)
Kevin Clark140b5552008-06-18 01:17:57 +0000135 struct.read(prot)
Kevin Clark03d7a472008-06-18 01:09:41 +0000136
James E. King III27247072018-03-22 20:50:23 -0400137 expect(struct.simple).to eq(42)
138 expect(struct.complex).to eq({1 => {"pi" => Math::PI, "e" => Math::E}, 14 => {"feigenbaum" => 4.669201609}})
139 expect(struct.hello).to eq(SpecNamespace::Hello.new(:greeting => "what's up?"))
140 expect(struct.words).to eq("apple banana")
141 expect(struct.ints).to eq([4, 23, 4, 29])
142 expect(struct.shorts).to eq(Set.new([3, 2]))
Kevin Clark140b5552008-06-18 01:17:57 +0000143 end
Kevin Clark03d7a472008-06-18 01:09:41 +0000144
Dmytro Shteflyuk5b5fd3c2026-03-11 19:50:50 -0400145 it "rejects negative container sizes while reading" do
146 struct = SpecNamespace::Foo.new
147 prot = Thrift::BaseProtocol.new(double("transport"))
148
149 expect(prot).to receive(:read_list_begin).and_return([Thrift::Types::I32, -1])
150
151 expect {
152 struct.send(:read_field, prot, SpecNamespace::Foo::FIELDS[4])
153 }.to raise_error(Thrift::ProtocolException, "Negative size") { |error|
154 expect(error.type).to eq(Thrift::ProtocolException::NEGATIVE_SIZE)
155 }
156 end
157
158 it "does not preallocate arrays from declared list sizes" do
159 struct = SpecNamespace::Foo.new
160 prot = Thrift::BaseProtocol.new(double("transport"))
161 declared_size = 1 << 30
162 sentinel = RuntimeError.new("stop after first element")
163
164 expect(prot).to receive(:read_list_begin).and_return([Thrift::Types::I32, declared_size])
165 expect(prot).to receive(:read_i32).and_raise(sentinel)
166 expect(Array).not_to receive(:new).with(declared_size)
167
168 expect {
169 struct.send(:read_field, prot, SpecNamespace::Foo::FIELDS[4])
170 }.to raise_error(sentinel)
171 end
172
Bryan Duxbury30dd7252010-02-27 05:47:15 +0000173 it "should serialize false boolean fields correctly" do
Jake Farrella87810f2012-09-28 01:59:04 +0000174 b = SpecNamespace::BoolStruct.new(:yesno => false)
175 prot = Thrift::BinaryProtocol.new(Thrift::MemoryBufferTransport.new)
James E. King III27247072018-03-22 20:50:23 -0400176 expect(prot).to receive(:write_bool).with(false)
Bryan Duxbury30dd7252010-02-27 05:47:15 +0000177 b.write(prot)
178 end
179
Kevin Clark140b5552008-06-18 01:17:57 +0000180 it "should skip unexpected fields in structs and use default values" do
Jake Farrella87810f2012-09-28 01:59:04 +0000181 struct = SpecNamespace::Foo.new
James E. King III27247072018-03-22 20:50:23 -0400182 prot = Thrift::BaseProtocol.new(double("transport"))
183 expect(prot).to receive(:read_struct_begin)
184 expect(prot).to receive(:read_struct_end)
185 expect(prot).to receive(:read_field_begin).and_return(
Jake Farrella87810f2012-09-28 01:59:04 +0000186 ['simple', Thrift::Types::I32, 1],
187 ['complex', Thrift::Types::STRUCT, 5],
188 ['thinz', Thrift::Types::MAP, 7],
189 ['foobar', Thrift::Types::I32, 3],
190 ['words', Thrift::Types::STRING, 2],
191 [nil, Thrift::Types::STOP, 0]
Kevin Clark140b5552008-06-18 01:17:57 +0000192 )
James E. King III27247072018-03-22 20:50:23 -0400193 expect(prot).to receive(:read_field_end).exactly(5).times
194 expect(prot).to receive(:read_i32).and_return(42)
195 expect(prot).to receive(:read_string).and_return("foobar")
196 expect(prot).to receive(:skip).with(Thrift::Types::STRUCT)
197 expect(prot).to receive(:skip).with(Thrift::Types::MAP)
Jake Farrella87810f2012-09-28 01:59:04 +0000198 # prot.should_receive(:read_map_begin).and_return([Thrift::Types::I32, Thrift::Types::I32, 0])
Bryan Duxburyc0166282009-02-02 00:48:17 +0000199 # prot.should_receive(:read_map_end)
James E. King III27247072018-03-22 20:50:23 -0400200 expect(prot).to receive(:skip).with(Thrift::Types::I32)
Kevin Clark140b5552008-06-18 01:17:57 +0000201 struct.read(prot)
Kevin Clark03d7a472008-06-18 01:09:41 +0000202
James E. King III27247072018-03-22 20:50:23 -0400203 expect(struct.simple).to eq(42)
204 expect(struct.complex).to be_nil
205 expect(struct.words).to eq("foobar")
206 expect(struct.hello).to eq(SpecNamespace::Hello.new(:greeting => 'hello, world!'))
207 expect(struct.ints).to eq([1, 2, 2, 3])
208 expect(struct.shorts).to eq(Set.new([5, 17, 239]))
Kevin Clark140b5552008-06-18 01:17:57 +0000209 end
Kevin Clark090b69e2008-06-18 01:12:58 +0000210
Kevin Clark140b5552008-06-18 01:17:57 +0000211 it "should write itself to the wire" do
James E. King III27247072018-03-22 20:50:23 -0400212 prot = Thrift::BaseProtocol.new(double("transport")) #mock("Protocol")
213 expect(prot).to receive(:write_struct_begin).with("SpecNamespace::Foo")
214 expect(prot).to receive(:write_struct_begin).with("SpecNamespace::Hello")
215 expect(prot).to receive(:write_struct_end).twice
216 expect(prot).to receive(:write_field_begin).with('ints', Thrift::Types::LIST, 4)
217 expect(prot).to receive(:write_i32).with(1)
218 expect(prot).to receive(:write_i32).with(2).twice
219 expect(prot).to receive(:write_i32).with(3)
220 expect(prot).to receive(:write_field_begin).with('complex', Thrift::Types::MAP, 5)
221 expect(prot).to receive(:write_i32).with(5)
222 expect(prot).to receive(:write_string).with('foo')
223 expect(prot).to receive(:write_double).with(1.23)
224 expect(prot).to receive(:write_field_begin).with('shorts', Thrift::Types::SET, 6)
225 expect(prot).to receive(:write_i16).with(5)
226 expect(prot).to receive(:write_i16).with(17)
227 expect(prot).to receive(:write_i16).with(239)
228 expect(prot).to receive(:write_field_stop).twice
229 expect(prot).to receive(:write_field_end).exactly(6).times
230 expect(prot).to receive(:write_field_begin).with('simple', Thrift::Types::I32, 1)
231 expect(prot).to receive(:write_i32).with(53)
232 expect(prot).to receive(:write_field_begin).with('hello', Thrift::Types::STRUCT, 3)
233 expect(prot).to receive(:write_field_begin).with('greeting', Thrift::Types::STRING, 1)
234 expect(prot).to receive(:write_string).with('hello, world!')
235 expect(prot).to receive(:write_map_begin).with(Thrift::Types::I32, Thrift::Types::MAP, 1)
236 expect(prot).to receive(:write_map_begin).with(Thrift::Types::STRING, Thrift::Types::DOUBLE, 1)
237 expect(prot).to receive(:write_map_end).twice
238 expect(prot).to receive(:write_list_begin).with(Thrift::Types::I32, 4)
239 expect(prot).to receive(:write_list_end)
240 expect(prot).to receive(:write_set_begin).with(Thrift::Types::I16, 3)
241 expect(prot).to receive(:write_set_end)
Kevin Clark140b5552008-06-18 01:17:57 +0000242
Jake Farrella87810f2012-09-28 01:59:04 +0000243 struct = SpecNamespace::Foo.new
Kevin Clark140b5552008-06-18 01:17:57 +0000244 struct.words = nil
245 struct.complex = {5 => {"foo" => 1.23}}
246 struct.write(prot)
247 end
248
249 it "should raise an exception if presented with an unknown container" do
250 # yeah this is silly, but I'm going for code coverage here
Jake Farrella87810f2012-09-28 01:59:04 +0000251 struct = SpecNamespace::Foo.new
James E. King III27247072018-03-22 20:50:23 -0400252 expect { struct.send :write_container, nil, nil, {:type => "foo"} }.to raise_error(StandardError, "Not a container type: foo")
Kevin Clark140b5552008-06-18 01:17:57 +0000253 end
Kevin Clark23193752008-06-18 01:18:07 +0000254
255 it "should support optional type-checking in Thrift::Struct.new" do
256 Thrift.type_checking = true
257 begin
Dmytro Shteflyukf06db1b2025-11-20 18:09:21 -0500258 expect { SpecNamespace::Hello.new(:greeting => 3) }.to raise_error(Thrift::TypeError, "Expected Types::STRING, received Integer for field greeting")
Kevin Clark23193752008-06-18 01:18:07 +0000259 ensure
260 Thrift.type_checking = false
261 end
James E. King III27247072018-03-22 20:50:23 -0400262 expect { SpecNamespace::Hello.new(:greeting => 3) }.not_to raise_error
Kevin Clark23193752008-06-18 01:18:07 +0000263 end
264
265 it "should support optional type-checking in field accessors" do
266 Thrift.type_checking = true
267 begin
Jake Farrella87810f2012-09-28 01:59:04 +0000268 hello = SpecNamespace::Hello.new
Dmytro Shteflyukf06db1b2025-11-20 18:09:21 -0500269 expect { hello.greeting = 3 }.to raise_error(Thrift::TypeError, "Expected Types::STRING, received Integer for field greeting")
Kevin Clark23193752008-06-18 01:18:07 +0000270 ensure
271 Thrift.type_checking = false
272 end
James E. King III27247072018-03-22 20:50:23 -0400273 expect { hello.greeting = 3 }.not_to raise_error
Kevin Clark23193752008-06-18 01:18:07 +0000274 end
275
276 it "should raise an exception when unknown types are given to Thrift::Struct.new" do
James E. King III27247072018-03-22 20:50:23 -0400277 expect { SpecNamespace::Hello.new(:fish => 'salmon') }.to raise_error(Exception, "Unknown key given to SpecNamespace::Hello.new: fish")
Kevin Clark23193752008-06-18 01:18:07 +0000278 end
Kevin Clark3af92872008-07-28 22:20:36 +0000279
280 it "should support `raise Xception, 'message'` for Exception structs" do
281 begin
Jake Farrella87810f2012-09-28 01:59:04 +0000282 raise SpecNamespace::Xception, "something happened"
Kevin Clark3af92872008-07-28 22:20:36 +0000283 rescue Thrift::Exception => e
James E. King III27247072018-03-22 20:50:23 -0400284 expect(e.message).to eq("something happened")
285 expect(e.code).to eq(1)
Kevin Clark3af92872008-07-28 22:20:36 +0000286 # ensure it gets serialized properly, this is the really important part
James E. King III27247072018-03-22 20:50:23 -0400287 prot = Thrift::BaseProtocol.new(double("trans"))
288 expect(prot).to receive(:write_struct_begin).with("SpecNamespace::Xception")
289 expect(prot).to receive(:write_struct_end)
290 expect(prot).to receive(:write_field_begin).with('message', Thrift::Types::STRING, 1)#, "something happened")
291 expect(prot).to receive(:write_string).with("something happened")
292 expect(prot).to receive(:write_field_begin).with('code', Thrift::Types::I32, 2)#, 1)
293 expect(prot).to receive(:write_i32).with(1)
294 expect(prot).to receive(:write_field_stop)
295 expect(prot).to receive(:write_field_end).twice
Kevin Clark3af92872008-07-28 22:20:36 +0000296
297 e.write(prot)
298 end
299 end
300
301 it "should support the regular initializer for exception structs" do
302 begin
Jake Farrella87810f2012-09-28 01:59:04 +0000303 raise SpecNamespace::Xception, :message => "something happened", :code => 5
Kevin Clark3af92872008-07-28 22:20:36 +0000304 rescue Thrift::Exception => e
James E. King III27247072018-03-22 20:50:23 -0400305 expect(e.message).to eq("something happened")
306 expect(e.code).to eq(5)
307 prot = Thrift::BaseProtocol.new(double("trans"))
308 expect(prot).to receive(:write_struct_begin).with("SpecNamespace::Xception")
309 expect(prot).to receive(:write_struct_end)
310 expect(prot).to receive(:write_field_begin).with('message', Thrift::Types::STRING, 1)
311 expect(prot).to receive(:write_string).with("something happened")
312 expect(prot).to receive(:write_field_begin).with('code', Thrift::Types::I32, 2)
313 expect(prot).to receive(:write_i32).with(5)
314 expect(prot).to receive(:write_field_stop)
315 expect(prot).to receive(:write_field_end).twice
Kevin Clark3af92872008-07-28 22:20:36 +0000316
317 e.write(prot)
318 end
319 end
Dmytro Shteflyuke9ac8e32025-11-19 23:33:23 -0500320
321 it "should handle UUID fields in structs" do
322 struct = SpecNamespace::Foo.new(
323 simple: 42,
324 words: 'test',
325 opt_uuid: '550e8400-e29b-41d4-a716-446655440000'
326 )
327
328 trans = Thrift::MemoryBufferTransport.new
329 prot = Thrift::BinaryProtocol.new(trans)
330
331 struct.write(prot)
332
333 result = SpecNamespace::Foo.new
334 result.read(prot)
335
336 expect(result.simple).to eq(42)
337 expect(result.words).to eq('test')
338 expect(result.opt_uuid).to eq('550e8400-e29b-41d4-a716-446655440000')
339 end
340
341 it "should handle optional UUID fields when unset" do
342 struct = SpecNamespace::Foo.new(simple: 42, words: 'test')
343 expect(struct.opt_uuid).to be_nil
344 expect(struct.opt_uuid?).to be_falsey
345 end
346
347 it "should handle list of UUIDs in SimpleList" do
348 uuids = ['550e8400-e29b-41d4-a716-446655440000', '6ba7b810-9dad-11d1-80b4-00c04fd430c8']
349 struct = SpecNamespace::SimpleList.new(uuids: uuids)
350
351 trans = Thrift::MemoryBufferTransport.new
352 prot = Thrift::CompactProtocol.new(trans)
353
354 struct.write(prot)
355
356 result = SpecNamespace::SimpleList.new
357 result.read(prot)
358
359 expect(result.uuids).to eq(uuids)
360 end
361
362 it "should normalize UUID case to lowercase" do
363 struct = SpecNamespace::Foo.new(opt_uuid: '550E8400-E29B-41D4-A716-446655440000')
364
365 trans = Thrift::MemoryBufferTransport.new
366 prot = Thrift::BinaryProtocol.new(trans)
367
368 struct.write(prot)
369
370 result = SpecNamespace::Foo.new
371 result.read(prot)
372
373 expect(result.opt_uuid).to eq('550e8400-e29b-41d4-a716-446655440000')
374 end
375
376 it "should handle UUID alongside other types in SimpleList" do
377 struct = SpecNamespace::SimpleList.new(
378 bools: [true, false],
379 i32s: [1, 2, 3],
380 strings: ['hello', 'world'],
381 uuids: ['550e8400-e29b-41d4-a716-446655440000', '00000000-0000-0000-0000-000000000000']
382 )
383
384 trans = Thrift::MemoryBufferTransport.new
385 prot = Thrift::BinaryProtocol.new(trans)
386
387 struct.write(prot)
388
389 result = SpecNamespace::SimpleList.new
390 result.read(prot)
391
392 expect(result.bools).to eq([true, false])
393 expect(result.i32s).to eq([1, 2, 3])
394 expect(result.strings).to eq(['hello', 'world'])
395 expect(result.uuids).to eq(['550e8400-e29b-41d4-a716-446655440000', '00000000-0000-0000-0000-000000000000'])
396 end
Kevin Clark090b69e2008-06-18 01:12:58 +0000397 end
Kevin Clark03d7a472008-06-18 01:09:41 +0000398end