sparsam 0.2.3 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -79,6 +79,14 @@ describe 'Sparsam' do
79
79
  ids.size.should == 0
80
80
  end
81
81
 
82
+ it "can deserialize unions" do
83
+ data = UN.new({ :id_i32 => 1000 })
84
+ result = data.serialize
85
+ data2 = Sparsam::Deserializer.deserialize(UN, result)
86
+ Sparsam.validate(UN, data2, Sparsam::RECURSIVE).should == true
87
+ data2.id_i32.should == 1000
88
+ end
89
+
82
90
  it "can handle passing in initialization data" do
83
91
  init = { "id_i32" => 10, "id_s" => "woohoo blackbird" }
84
92
  data = SS.new(init)
@@ -219,6 +227,44 @@ describe 'Sparsam' do
219
227
  e.field_name.should == "id_i32"
220
228
  end
221
229
 
230
+ it "includes additional information on serializing mismatched types" do
231
+ data = MiniRequired.new
232
+ data.id_i32 = "not an i32"
233
+
234
+ e = nil
235
+ begin
236
+ data.serialize
237
+ rescue Sparsam::TypeMismatch => exception
238
+ e = exception
239
+ end
240
+ e.message.should include("T_I32", "String")
241
+
242
+ data = EveryType.new
243
+ data.a_struct = EveryType.new
244
+
245
+ e = nil
246
+ begin
247
+ data.serialize
248
+ rescue Sparsam::TypeMismatch => exception
249
+ e = exception
250
+ end
251
+ e.message.should include("US", "EveryType")
252
+ end
253
+
254
+ it "includes additional information on deserializing mismatched types" do
255
+ data = NotSS.new
256
+ data.id_s = "not an i32"
257
+
258
+ serialized = data.serialize
259
+
260
+ begin
261
+ Sparsam::Deserializer.deserialize(SS, serialized)
262
+ rescue Sparsam::TypeMismatch => exception
263
+ e = exception
264
+ end
265
+ e.message.should include("T_I32", "T_STRING")
266
+ end
267
+
222
268
  it "will throw errors when given junk data" do
223
269
  expect {
224
270
  Sparsam::Deserializer.deserialize(SS, "wolololololol")
@@ -443,6 +489,23 @@ describe 'Sparsam' do
443
489
  end
444
490
  end
445
491
 
492
+ it 'handles recursive structs' do
493
+ recursive_struct = RecursiveStruct.new
494
+ recursive_struct.id = 1
495
+ recursive_struct.self_struct = RecursiveStruct.new
496
+ recursive_struct.self_struct.id = 2
497
+ recursive_struct.self_list = [RecursiveStruct.new]
498
+ recursive_struct.self_list[0].id = 3
499
+
500
+ data = recursive_struct.serialize
501
+
502
+ new_recursive = Sparsam::Deserializer.deserialize(RecursiveStruct, data)
503
+
504
+ new_recursive.id.should == 1
505
+ new_recursive.self_struct.id.should == 2
506
+ new_recursive.self_list[0].id.should == 3
507
+ end
508
+
446
509
  it 'handles structs with modified eigenclasses' do
447
510
  nested_struct = US.new
448
511
 
@@ -483,4 +546,76 @@ describe 'Sparsam' do
483
546
  end
484
547
  end
485
548
  end
549
+
550
+ describe 'generated enum types' do
551
+ let(:enum_module) { Magic }
552
+
553
+ it 'includes thrift constants as top level module constants' do
554
+ enum_module.const_defined?(:Black).should == true
555
+ enum_module.const_defined?(:White).should == true
556
+ enum_module.const_defined?(:Red).should == true
557
+ enum_module.const_defined?(:Blue).should == true
558
+ enum_module.const_defined?(:Green).should == true
559
+
560
+ enum_module.const_get(:Black).should == 0
561
+ enum_module.const_get(:White).should == 1
562
+ enum_module.const_get(:Red).should == 2
563
+ enum_module.const_get(:Blue).should == 3
564
+ enum_module.const_get(:Green).should == 4
565
+ end
566
+
567
+ it 'contains a VALUE_MAP constant that maps from int value to string' do
568
+ enum_module.const_defined?(:VALUE_MAP).should == true
569
+
570
+ value_map = enum_module.const_get(:VALUE_MAP)
571
+
572
+ value_map.should eql({
573
+ 0 => 'Black',
574
+ 1 => 'White',
575
+ 2 => 'Red',
576
+ 3 => 'Blue',
577
+ 4 => 'Green',
578
+ })
579
+
580
+ value_map[enum_module.const_get(:Black)].should == 'Black'
581
+ value_map[enum_module.const_get(:White)].should == 'White'
582
+ value_map[enum_module.const_get(:Red)].should == 'Red'
583
+ value_map[enum_module.const_get(:Blue)].should == 'Blue'
584
+ value_map[enum_module.const_get(:Green)].should == 'Green'
585
+ end
586
+
587
+ it 'contains an INVERTED_VALUE_MAP constant that maps from name to int value' do
588
+ enum_module.const_defined?(:INVERTED_VALUE_MAP).should == true
589
+
590
+ inverted_value_map = enum_module.const_get(:INVERTED_VALUE_MAP)
591
+
592
+ inverted_value_map.should eql({
593
+ 'Black' => 0,
594
+ 'White' => 1,
595
+ 'Red' => 2,
596
+ 'Blue' => 3,
597
+ 'Green' => 4,
598
+ })
599
+
600
+ inverted_value_map['Black'].should == enum_module.const_get(:Black)
601
+ inverted_value_map['White'].should == enum_module.const_get(:White)
602
+ inverted_value_map['Red'].should == enum_module.const_get(:Red)
603
+ inverted_value_map['Blue'].should == enum_module.const_get(:Blue)
604
+ inverted_value_map['Green'].should == enum_module.const_get(:Green)
605
+ end
606
+
607
+ it 'contains a VALID_VALUES constant that is a set of all enum values' do
608
+ enum_module.const_defined?(:VALID_VALUES).should == true
609
+
610
+ valid_values = enum_module.const_get(:VALID_VALUES)
611
+
612
+ valid_values.should be_a(Set)
613
+ valid_values.should include(enum_module.const_get(:Black))
614
+ valid_values.should include(enum_module.const_get(:White))
615
+ valid_values.should include(enum_module.const_get(:Red))
616
+ valid_values.should include(enum_module.const_get(:Blue))
617
+ valid_values.should include(enum_module.const_get(:Green))
618
+ valid_values.length.should == 5
619
+ end
620
+ end
486
621
  end
@@ -82,6 +82,12 @@ struct EveryType {
82
82
  15: optional UN a_union
83
83
  }
84
84
 
85
+ struct RecursiveStruct {
86
+ 1: optional i64 id
87
+ 2: optional RecursiveStruct self_struct
88
+ 3: optional list<RecursiveStruct> self_list
89
+ }
90
+
85
91
  exception SimpleException {
86
92
  1: optional string message
87
93
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sparsam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Airbnb Thrift Developers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-29 00:00:00.000000000 Z
11
+ date: 2021-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -164,8 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
164
  - !ruby/object:Gem::Version
165
165
  version: '0'
166
166
  requirements: []
167
- rubyforge_project: thrift
168
- rubygems_version: 2.6.11
167
+ rubygems_version: 3.0.3
169
168
  signing_key:
170
169
  specification_version: 4
171
170
  summary: Ruby bindings for Apache Thrift
@@ -174,4 +173,3 @@ test_files:
174
173
  - spec/gen-ruby/user_types.rb
175
174
  - spec/gen-ruby/user_constants.rb
176
175
  - spec/user.thrift
177
- has_rdoc: true