protobuf-core 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +18 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +23 -0
  8. data/Rakefile +5 -0
  9. data/bin/protoc-gen-ruby +16 -0
  10. data/lib/protobuf.rb +27 -0
  11. data/lib/protobuf/code_generator.rb +44 -0
  12. data/lib/protobuf/core.rb +2 -0
  13. data/lib/protobuf/core/version.rb +5 -0
  14. data/lib/protobuf/decoder.rb +73 -0
  15. data/lib/protobuf/deprecation.rb +112 -0
  16. data/lib/protobuf/descriptors.rb +3 -0
  17. data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +54 -0
  18. data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +251 -0
  19. data/lib/protobuf/encoder.rb +67 -0
  20. data/lib/protobuf/enum.rb +303 -0
  21. data/lib/protobuf/exceptions.rb +9 -0
  22. data/lib/protobuf/field.rb +74 -0
  23. data/lib/protobuf/field/base_field.rb +267 -0
  24. data/lib/protobuf/field/bool_field.rb +59 -0
  25. data/lib/protobuf/field/bytes_field.rb +82 -0
  26. data/lib/protobuf/field/double_field.rb +25 -0
  27. data/lib/protobuf/field/enum_field.rb +68 -0
  28. data/lib/protobuf/field/field_array.rb +87 -0
  29. data/lib/protobuf/field/fixed32_field.rb +25 -0
  30. data/lib/protobuf/field/fixed64_field.rb +28 -0
  31. data/lib/protobuf/field/float_field.rb +41 -0
  32. data/lib/protobuf/field/int32_field.rb +21 -0
  33. data/lib/protobuf/field/int64_field.rb +21 -0
  34. data/lib/protobuf/field/integer_field.rb +23 -0
  35. data/lib/protobuf/field/message_field.rb +65 -0
  36. data/lib/protobuf/field/sfixed32_field.rb +27 -0
  37. data/lib/protobuf/field/sfixed64_field.rb +28 -0
  38. data/lib/protobuf/field/signed_integer_field.rb +29 -0
  39. data/lib/protobuf/field/sint32_field.rb +21 -0
  40. data/lib/protobuf/field/sint64_field.rb +21 -0
  41. data/lib/protobuf/field/string_field.rb +34 -0
  42. data/lib/protobuf/field/uint32_field.rb +21 -0
  43. data/lib/protobuf/field/uint64_field.rb +21 -0
  44. data/lib/protobuf/field/varint_field.rb +73 -0
  45. data/lib/protobuf/generators/base.rb +70 -0
  46. data/lib/protobuf/generators/enum_generator.rb +41 -0
  47. data/lib/protobuf/generators/extension_generator.rb +27 -0
  48. data/lib/protobuf/generators/field_generator.rb +131 -0
  49. data/lib/protobuf/generators/file_generator.rb +132 -0
  50. data/lib/protobuf/generators/group_generator.rb +105 -0
  51. data/lib/protobuf/generators/message_generator.rb +98 -0
  52. data/lib/protobuf/generators/printable.rb +160 -0
  53. data/lib/protobuf/logging.rb +39 -0
  54. data/lib/protobuf/message.rb +193 -0
  55. data/lib/protobuf/message/fields.rb +133 -0
  56. data/lib/protobuf/message/serialization.rb +89 -0
  57. data/lib/protobuf/optionable.rb +23 -0
  58. data/lib/protobuf/wire_type.rb +10 -0
  59. data/proto/dynamic_discovery.proto +44 -0
  60. data/proto/google/protobuf/compiler/plugin.proto +147 -0
  61. data/proto/google/protobuf/descriptor.proto +620 -0
  62. data/proto/rpc.proto +62 -0
  63. data/protobuf-core.gemspec +31 -0
  64. data/spec/bin/protoc-gen-ruby_spec.rb +23 -0
  65. data/spec/data/data.bin +3 -0
  66. data/spec/data/types.bin +0 -0
  67. data/spec/encoding/all_types_spec.rb +105 -0
  68. data/spec/encoding/extreme_values_spec.rb +0 -0
  69. data/spec/functional/class_inheritance_spec.rb +52 -0
  70. data/spec/functional/compile_and_require_spec.rb +29 -0
  71. data/spec/lib/protobuf/base_spec.rb +84 -0
  72. data/spec/lib/protobuf/code_generator_spec.rb +60 -0
  73. data/spec/lib/protobuf/enum_generator_spec.rb +73 -0
  74. data/spec/lib/protobuf/enum_spec.rb +265 -0
  75. data/spec/lib/protobuf/extension_generator_spec.rb +42 -0
  76. data/spec/lib/protobuf/field/bool_field_spec.rb +51 -0
  77. data/spec/lib/protobuf/field/field_array_spec.rb +69 -0
  78. data/spec/lib/protobuf/field/float_field_spec.rb +55 -0
  79. data/spec/lib/protobuf/field/int32_field_spec.rb +90 -0
  80. data/spec/lib/protobuf/field/string_field_spec.rb +45 -0
  81. data/spec/lib/protobuf/field_generator_spec.rb +102 -0
  82. data/spec/lib/protobuf/field_spec.rb +191 -0
  83. data/spec/lib/protobuf/file_generator_spec.rb +32 -0
  84. data/spec/lib/protobuf/message_generator_spec.rb +0 -0
  85. data/spec/lib/protobuf/message_spec.rb +526 -0
  86. data/spec/lib/protobuf/optionable_spec.rb +46 -0
  87. data/spec/lib/protobuf_spec.rb +45 -0
  88. data/spec/spec_helper.rb +9 -0
  89. data/spec/support/packed_field.rb +22 -0
  90. data/spec/support/test/all_types.data.bin +0 -0
  91. data/spec/support/test/all_types.data.txt +119 -0
  92. data/spec/support/test/bacon.proto +14 -0
  93. data/spec/support/test/defaults.pb.rb +27 -0
  94. data/spec/support/test/defaults.proto +9 -0
  95. data/spec/support/test/enum.pb.rb +61 -0
  96. data/spec/support/test/enum.proto +34 -0
  97. data/spec/support/test/extended.pb.rb +24 -0
  98. data/spec/support/test/extended.proto +10 -0
  99. data/spec/support/test/extreme_values.data.bin +0 -0
  100. data/spec/support/test/google_unittest.pb.rb +530 -0
  101. data/spec/support/test/google_unittest.proto +713 -0
  102. data/spec/support/test/google_unittest_import.pb.rb +39 -0
  103. data/spec/support/test/google_unittest_import.proto +64 -0
  104. data/spec/support/test/google_unittest_import_public.pb.rb +10 -0
  105. data/spec/support/test/google_unittest_import_public.proto +38 -0
  106. data/spec/support/test/multi_field_extensions.pb.rb +58 -0
  107. data/spec/support/test/multi_field_extensions.proto +33 -0
  108. data/spec/support/test/resource.pb.rb +106 -0
  109. data/spec/support/test/resource.proto +94 -0
  110. metadata +306 -0
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Protobuf::Field::FloatField do
4
+
5
+ class SomeFloatMessage < ::Protobuf::Message
6
+ optional :float, :some_float, 1
7
+ end
8
+
9
+ let(:instance) { SomeFloatMessage.new }
10
+
11
+ describe '#define_setter' do
12
+ subject { instance.some_float = value; instance.some_float }
13
+
14
+ context 'when set with an int' do
15
+ let(:value) { 100 }
16
+
17
+ it 'is readable as a float' do
18
+ expect(subject).to eq(100.0)
19
+ end
20
+ end
21
+
22
+ context 'when set with a float' do
23
+ let(:value) { 100.1 }
24
+
25
+ it 'is readable as a float' do
26
+ expect(subject).to eq(100.1)
27
+ end
28
+ end
29
+
30
+ context 'when set with a string of a float' do
31
+ let(:value) { "101.1" }
32
+
33
+ it 'is readable as a float' do
34
+ expect(subject).to eq(101.1)
35
+ end
36
+ end
37
+
38
+ context 'when set with a non-numeric string' do
39
+ let(:value) { "aaaa" }
40
+
41
+ it 'throws an error' do
42
+ expect { subject }.to raise_error(ArgumentError)
43
+ end
44
+ end
45
+
46
+ context 'when set with something that is not a float' do
47
+ let(:value) { [1, 2, 3] }
48
+
49
+ it 'throws an error' do
50
+ expect { subject }.to raise_error(TypeError)
51
+ end
52
+ end
53
+ end
54
+
55
+ end
@@ -0,0 +1,90 @@
1
+ require 'spec_helper'
2
+ require 'support/packed_field'
3
+
4
+ RSpec.describe Protobuf::Field::Int32Field do
5
+
6
+ it_behaves_like :packable_field, described_class
7
+
8
+ class SomeInt32Message < ::Protobuf::Message
9
+ optional :int32, :some_int, 1
10
+ end
11
+
12
+ let(:instance) { SomeInt32Message.new }
13
+
14
+ describe '#define_setter' do
15
+ subject { instance.some_int = value; instance.some_int }
16
+
17
+ context 'when set with an int' do
18
+ let(:value) { 100 }
19
+
20
+ it 'is readable as an int' do
21
+ expect(subject).to eq(100)
22
+ end
23
+ end
24
+
25
+ context 'when set with a float' do
26
+ let(:value) { 100.1 }
27
+
28
+ it 'is readable as an int' do
29
+ expect(subject).to eq(100)
30
+ end
31
+ end
32
+
33
+ context 'when set with a string of an int' do
34
+ let(:value) { "101" }
35
+
36
+ it 'is readable as an int' do
37
+ expect(subject).to eq(101)
38
+ end
39
+ end
40
+
41
+ context 'when set with a negative representation of an int as string' do
42
+ let(:value) { "-101" }
43
+
44
+ it 'is readable as a negative int' do
45
+ expect(subject).to eq(-101)
46
+ end
47
+ end
48
+
49
+ context 'when set with a non-numeric string' do
50
+ let(:value) { "aaaa" }
51
+
52
+ it 'throws an error' do
53
+ expect { subject }.to raise_error(TypeError)
54
+ end
55
+ end
56
+
57
+ context 'when set with a string of an int in hex format' do
58
+ let(:value) { "0x101" }
59
+
60
+ it 'throws an error' do
61
+ expect { subject }.to raise_error(TypeError)
62
+ end
63
+ end
64
+
65
+ context 'when set with a string of an int larger than int32 max' do
66
+ let(:value) { (described_class.max + 1).to_s }
67
+
68
+ it 'throws an error' do
69
+ expect { subject }.to raise_error(TypeError)
70
+ end
71
+ end
72
+
73
+ context 'when set with something that is not an int' do
74
+ let(:value) { [1, 2, 3] }
75
+
76
+ it 'throws an error' do
77
+ expect { subject }.to raise_error(TypeError)
78
+ end
79
+ end
80
+
81
+ context 'when set with a timestamp' do
82
+ let(:value) { Time.now }
83
+
84
+ it 'throws an error' do
85
+ expect { subject }.to raise_error(TypeError)
86
+ end
87
+ end
88
+ end
89
+
90
+ end
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe ::Protobuf::Field::StringField do
6
+
7
+ describe '#encode' do
8
+ context 'when a repeated string field contains frozen strings' do
9
+ it 'does not raise an encoding error' do
10
+ expect do
11
+ frozen_strings = ["foo".freeze, "bar".freeze, "baz".freeze]
12
+ ::Test::ResourceFindRequest.encode(:name => 'resource', :widgets => frozen_strings)
13
+ end.not_to raise_error
14
+ end
15
+ end
16
+
17
+ context 'when a repeated bytes field contains frozen strings' do
18
+ it 'does not raise an encoding error' do
19
+ expect do
20
+ frozen_strings = ["foo".freeze, "bar".freeze, "baz".freeze]
21
+ ::Test::ResourceFindRequest.encode(:name => 'resource', :widget_bytes => frozen_strings)
22
+ end.not_to raise_error
23
+ end
24
+ end
25
+
26
+ it 'does not alter string values after encoding multiple times' do
27
+ source_string = "foo"
28
+ proto = ::Test::Resource.new(:name => source_string)
29
+ proto.encode
30
+ expect(proto.name).to eq source_string
31
+ proto.encode
32
+ expect(proto.name).to eq source_string
33
+ end
34
+
35
+ it 'does not alter unicode string values after encoding multiple times' do
36
+ source_string = "¢"
37
+ proto = ::Test::Resource.new(:name => source_string)
38
+ proto.encode
39
+ expect(proto.name).to eq source_string
40
+ proto.encode
41
+ expect(proto.name).to eq source_string
42
+ end
43
+ end
44
+
45
+ end
@@ -0,0 +1,102 @@
1
+ require 'spec_helper'
2
+
3
+ require 'protobuf/generators/field_generator'
4
+
5
+ RSpec.describe ::Protobuf::Generators::FieldGenerator do
6
+
7
+ let(:label_enum) { :LABEL_OPTIONAL }
8
+ let(:name) { 'foo_bar' }
9
+ let(:number) { 3 }
10
+ let(:type_enum) { :TYPE_STRING }
11
+ let(:type_name) { nil }
12
+ let(:default_value) { nil }
13
+ let(:extendee) { nil }
14
+ let(:field_options) { {} }
15
+
16
+ let(:field_fields) do
17
+ {
18
+ :label => label_enum,
19
+ :name => name,
20
+ :number => number,
21
+ :type => type_enum,
22
+ :type_name => type_name,
23
+ :default_value => default_value,
24
+ :extendee => extendee,
25
+ :options => field_options,
26
+ }
27
+ end
28
+
29
+ let(:field) { ::Google::Protobuf::FieldDescriptorProto.new(field_fields) }
30
+
31
+ describe '#compile' do
32
+ subject { described_class.new(field).to_s }
33
+
34
+ specify { expect(subject).to eq "optional :string, :foo_bar, 3\n" }
35
+
36
+ context 'when the type is another message' do
37
+ let(:type_enum) { :TYPE_MESSAGE }
38
+ let(:type_name) { '.foo.bar.Baz' }
39
+
40
+ specify { expect(subject).to eq "optional ::Foo::Bar::Baz, :foo_bar, 3\n" }
41
+ end
42
+
43
+ context 'when a default value is used' do
44
+ let(:type_enum) { :TYPE_INT32 }
45
+ let(:default_value) { '42' }
46
+ specify { expect(subject).to eq "optional :int32, :foo_bar, 3, :default => 42\n" }
47
+
48
+ context 'when type is an enum' do
49
+ let(:type_enum) { :TYPE_ENUM }
50
+ let(:type_name) { '.foo.bar.Baz' }
51
+ let(:default_value) { 'QUUX' }
52
+
53
+ specify { expect(subject).to eq "optional ::Foo::Bar::Baz, :foo_bar, 3, :default => ::Foo::Bar::Baz::QUUX\n" }
54
+ end
55
+
56
+ context 'when the type is a string' do
57
+ let(:type_enum) { :TYPE_STRING }
58
+ let(:default_value) { "a default \"string\"" }
59
+
60
+ specify { expect(subject).to eq "optional :string, :foo_bar, 3, :default => \"a default \"string\"\"\n" }
61
+ end
62
+
63
+ context 'when float or double field type' do
64
+ let(:type_enum) { :TYPE_DOUBLE }
65
+
66
+ context 'when the default value is "nan"' do
67
+ let(:default_value) { 'nan' }
68
+ specify { expect(subject).to match(/::Float::NAN/) }
69
+ end
70
+
71
+ context 'when the default value is "inf"' do
72
+ let(:default_value) { 'inf' }
73
+ specify { expect(subject).to match(/::Float::INFINITY/) }
74
+ end
75
+
76
+ context 'when the default value is "-inf"' do
77
+ let(:default_value) { '-inf' }
78
+ specify { expect(subject).to match(/-::Float::INFINITY/) }
79
+ end
80
+ end
81
+ end
82
+
83
+ context 'when the field is an extension' do
84
+ let(:extendee) { 'foo.bar.Baz' }
85
+
86
+ specify { expect(subject).to eq "optional :string, :foo_bar, 3, :extension => true\n" }
87
+ end
88
+
89
+ context 'when field is packed' do
90
+ let(:field_options) { { :packed => true } }
91
+
92
+ specify { expect(subject).to eq "optional :string, :foo_bar, 3, :packed => true\n" }
93
+ end
94
+
95
+ context 'when field is deprecated' do
96
+ let(:field_options) { { :deprecated => true } }
97
+
98
+ specify { expect(subject).to eq "optional :string, :foo_bar, 3, :deprecated => true\n" }
99
+ end
100
+ end
101
+
102
+ end
@@ -0,0 +1,191 @@
1
+ require 'spec_helper'
2
+ require 'protobuf/field'
3
+
4
+ RSpec.describe ::Protobuf::Field do
5
+
6
+ describe '.build' do
7
+ pending
8
+ end
9
+
10
+ describe '.field_class' do
11
+ context 'when type is an enum class' do
12
+ it 'returns an enum field' do
13
+ expect(subject.field_class(::Test::EnumTestType)).to eq(::Protobuf::Field::EnumField)
14
+ expect(subject.field_type(::Test::EnumTestType)).to eq(::Test::EnumTestType)
15
+ end
16
+ end
17
+
18
+ context 'when type is a message class' do
19
+ it 'returns a message field' do
20
+ expect(subject.field_class(::Test::Resource)).to eq(::Protobuf::Field::MessageField)
21
+ expect(subject.field_type(::Test::Resource)).to eq(::Test::Resource)
22
+ end
23
+ end
24
+
25
+ context 'when type is a base field class' do
26
+ it 'returns that class' do
27
+ expect(subject.field_class(::Protobuf::Field::BoolField)).to eq(::Protobuf::Field::BoolField)
28
+ end
29
+ end
30
+
31
+ context 'when type is a double field class or symbol' do
32
+ it 'returns that class' do
33
+ expected_field = ::Protobuf::Field::DoubleField
34
+ expect(subject.field_class(expected_field)).to eq(expected_field)
35
+ expect(subject.field_class(:double)).to eq(expected_field)
36
+ expect(subject.field_type(expected_field)).to eq(expected_field)
37
+ expect(subject.field_type(:double)).to eq(expected_field)
38
+ end
39
+ end
40
+
41
+ context 'when type is a float field class or symbol' do
42
+ it 'returns that class' do
43
+ expected_field = ::Protobuf::Field::FloatField
44
+ expect(subject.field_class(expected_field)).to eq(expected_field)
45
+ expect(subject.field_class(:float)).to eq(expected_field)
46
+ expect(subject.field_type(expected_field)).to eq(expected_field)
47
+ expect(subject.field_type(:float)).to eq(expected_field)
48
+ end
49
+ end
50
+
51
+ context 'when type is a int32 field class or symbol' do
52
+ it 'returns that class' do
53
+ expected_field = ::Protobuf::Field::Int32Field
54
+ expect(subject.field_class(expected_field)).to eq(expected_field)
55
+ expect(subject.field_class(:int32)).to eq(expected_field)
56
+ expect(subject.field_type(expected_field)).to eq(expected_field)
57
+ expect(subject.field_type(:int32)).to eq(expected_field)
58
+ end
59
+ end
60
+
61
+ context 'when type is a int64 field class or symbol' do
62
+ it 'returns that class' do
63
+ expected_field = ::Protobuf::Field::Int64Field
64
+ expect(subject.field_class(expected_field)).to eq(expected_field)
65
+ expect(subject.field_class(:int64)).to eq(expected_field)
66
+ expect(subject.field_type(expected_field)).to eq(expected_field)
67
+ expect(subject.field_type(:int64)).to eq(expected_field)
68
+ end
69
+ end
70
+
71
+ context 'when type is a uint32 field class or symbol' do
72
+ it 'returns that class' do
73
+ expected_field = ::Protobuf::Field::Uint32Field
74
+ expect(subject.field_class(expected_field)).to eq(expected_field)
75
+ expect(subject.field_class(:uint32)).to eq(expected_field)
76
+ expect(subject.field_type(expected_field)).to eq(expected_field)
77
+ expect(subject.field_type(:uint32)).to eq(expected_field)
78
+ end
79
+ end
80
+
81
+ context 'when type is a uint64 field class or symbol' do
82
+ it 'returns that class' do
83
+ expected_field = ::Protobuf::Field::Uint64Field
84
+ expect(subject.field_class(expected_field)).to eq(expected_field)
85
+ expect(subject.field_class(:uint64)).to eq(expected_field)
86
+ expect(subject.field_type(expected_field)).to eq(expected_field)
87
+ expect(subject.field_type(:uint64)).to eq(expected_field)
88
+ end
89
+ end
90
+
91
+ context 'when type is a sint32 field class or symbol' do
92
+ it 'returns that class' do
93
+ expected_field = ::Protobuf::Field::Sint32Field
94
+ expect(subject.field_class(expected_field)).to eq(expected_field)
95
+ expect(subject.field_class(:sint32)).to eq(expected_field)
96
+ expect(subject.field_type(expected_field)).to eq(expected_field)
97
+ expect(subject.field_type(:sint32)).to eq(expected_field)
98
+ end
99
+ end
100
+
101
+ context 'when type is a sint64 field class or symbol' do
102
+ it 'returns that class' do
103
+ expected_field = ::Protobuf::Field::Sint64Field
104
+ expect(subject.field_class(expected_field)).to eq(expected_field)
105
+ expect(subject.field_class(:sint64)).to eq(expected_field)
106
+ expect(subject.field_type(expected_field)).to eq(expected_field)
107
+ expect(subject.field_type(:sint64)).to eq(expected_field)
108
+ end
109
+ end
110
+
111
+ context 'when type is a fixed32 field class or symbol' do
112
+ it 'returns that class' do
113
+ expected_field = ::Protobuf::Field::Fixed32Field
114
+ expect(subject.field_class(expected_field)).to eq(expected_field)
115
+ expect(subject.field_class(:fixed32)).to eq(expected_field)
116
+ expect(subject.field_type(expected_field)).to eq(expected_field)
117
+ expect(subject.field_type(:fixed32)).to eq(expected_field)
118
+ end
119
+ end
120
+
121
+ context 'when type is a fixed64 field class or symbol' do
122
+ it 'returns that class' do
123
+ expected_field = ::Protobuf::Field::Fixed64Field
124
+ expect(subject.field_class(expected_field)).to eq(expected_field)
125
+ expect(subject.field_class(:fixed64)).to eq(expected_field)
126
+ expect(subject.field_type(expected_field)).to eq(expected_field)
127
+ expect(subject.field_type(:fixed64)).to eq(expected_field)
128
+ end
129
+ end
130
+
131
+ context 'when type is a sfixed32 field class or symbol' do
132
+ it 'returns that class' do
133
+ expected_field = ::Protobuf::Field::Sfixed32Field
134
+ expect(subject.field_class(expected_field)).to eq(expected_field)
135
+ expect(subject.field_class(:sfixed32)).to eq(expected_field)
136
+ expect(subject.field_type(expected_field)).to eq(expected_field)
137
+ expect(subject.field_type(:sfixed32)).to eq(expected_field)
138
+ end
139
+ end
140
+
141
+ context 'when type is a sfixed64 field class or symbol' do
142
+ it 'returns that class' do
143
+ expected_field = ::Protobuf::Field::Sfixed64Field
144
+ expect(subject.field_class(expected_field)).to eq(expected_field)
145
+ expect(subject.field_class(:sfixed64)).to eq(expected_field)
146
+ expect(subject.field_type(expected_field)).to eq(expected_field)
147
+ expect(subject.field_type(:sfixed64)).to eq(expected_field)
148
+ end
149
+ end
150
+
151
+ context 'when type is a string field class or symbol' do
152
+ it 'returns that class' do
153
+ expected_field = ::Protobuf::Field::StringField
154
+ expect(subject.field_class(expected_field)).to eq(expected_field)
155
+ expect(subject.field_class(:string)).to eq(expected_field)
156
+ expect(subject.field_type(expected_field)).to eq(expected_field)
157
+ expect(subject.field_type(:string)).to eq(expected_field)
158
+ end
159
+ end
160
+
161
+ context 'when type is a bytes field class or symbol' do
162
+ it 'returns that class' do
163
+ expected_field = ::Protobuf::Field::BytesField
164
+ expect(subject.field_class(expected_field)).to eq(expected_field)
165
+ expect(subject.field_class(:bytes)).to eq(expected_field)
166
+ expect(subject.field_type(expected_field)).to eq(expected_field)
167
+ expect(subject.field_type(:bytes)).to eq(expected_field)
168
+ end
169
+ end
170
+
171
+ context 'when type is a bool field class or symbol' do
172
+ it 'returns that class' do
173
+ expected_field = ::Protobuf::Field::BoolField
174
+ expect(subject.field_class(expected_field)).to eq(expected_field)
175
+ expect(subject.field_class(:bool)).to eq(expected_field)
176
+ expect(subject.field_type(expected_field)).to eq(expected_field)
177
+ expect(subject.field_type(:bool)).to eq(expected_field)
178
+ end
179
+ end
180
+
181
+ context 'when type is not mapped' do
182
+ it 'raises an ArgumentError' do
183
+ expect do
184
+ subject.field_class("boom")
185
+ end.to raise_error
186
+ end
187
+ end
188
+
189
+ end
190
+
191
+ end