google-protobuf 3.7.0 → 3.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of google-protobuf might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/ext/google/protobuf_c/defs.c +942 -833
- data/ext/google/protobuf_c/encode_decode.c +521 -300
- data/ext/google/protobuf_c/extconf.rb +2 -4
- data/ext/google/protobuf_c/map.c +41 -54
- data/ext/google/protobuf_c/message.c +212 -86
- data/ext/google/protobuf_c/protobuf.c +30 -15
- data/ext/google/protobuf_c/protobuf.h +114 -60
- data/ext/google/protobuf_c/repeated_field.c +55 -23
- data/ext/google/protobuf_c/storage.c +350 -171
- data/ext/google/protobuf_c/upb.c +5630 -9131
- data/ext/google/protobuf_c/upb.h +4590 -7568
- data/lib/google/protobuf/any_pb.rb +1 -1
- data/lib/google/protobuf/api_pb.rb +3 -3
- data/lib/google/protobuf/duration_pb.rb +1 -1
- data/lib/google/protobuf/empty_pb.rb +1 -1
- data/lib/google/protobuf/field_mask_pb.rb +1 -1
- data/lib/google/protobuf/source_context_pb.rb +1 -1
- data/lib/google/protobuf/struct_pb.rb +4 -4
- data/lib/google/protobuf/timestamp_pb.rb +1 -1
- data/lib/google/protobuf/type_pb.rb +8 -8
- data/lib/google/protobuf/well_known_types.rb +8 -2
- data/lib/google/protobuf/wrappers_pb.rb +9 -9
- data/lib/google/protobuf.rb +70 -0
- data/tests/basic.rb +250 -68
- data/tests/generated_code_test.rb +0 -0
- data/tests/stress.rb +0 -0
- metadata +18 -12
data/tests/basic.rb
CHANGED
@@ -17,7 +17,6 @@ module BasicTest
|
|
17
17
|
add_message "BadFieldNames" do
|
18
18
|
optional :dup, :int32, 1
|
19
19
|
optional :class, :int32, 2
|
20
|
-
optional :"a.b", :int32, 3
|
21
20
|
end
|
22
21
|
end
|
23
22
|
|
@@ -33,11 +32,11 @@ module BasicTest
|
|
33
32
|
include CommonTests
|
34
33
|
|
35
34
|
def test_has_field
|
36
|
-
m =
|
37
|
-
assert !m.
|
38
|
-
m.
|
39
|
-
assert m.
|
40
|
-
assert
|
35
|
+
m = TestSingularFields.new
|
36
|
+
assert !m.has_singular_msg?
|
37
|
+
m.singular_msg = TestMessage2.new
|
38
|
+
assert m.has_singular_msg?
|
39
|
+
assert TestSingularFields.descriptor.lookup('singular_msg').has?(m)
|
41
40
|
|
42
41
|
m = OneofMessage.new
|
43
42
|
assert !m.has_my_oneof?
|
@@ -46,32 +45,31 @@ module BasicTest
|
|
46
45
|
assert_raise NoMethodError do
|
47
46
|
m.has_a?
|
48
47
|
end
|
49
|
-
|
50
|
-
OneofMessage.descriptor.lookup('a').has?(m)
|
51
|
-
end
|
48
|
+
assert_true OneofMessage.descriptor.lookup('a').has?(m)
|
52
49
|
|
53
|
-
m =
|
50
|
+
m = TestSingularFields.new
|
54
51
|
assert_raise NoMethodError do
|
55
|
-
m.
|
52
|
+
m.has_singular_int32?
|
56
53
|
end
|
57
54
|
assert_raise ArgumentError do
|
58
|
-
|
55
|
+
TestSingularFields.descriptor.lookup('singular_int32').has?(m)
|
59
56
|
end
|
60
57
|
|
61
58
|
assert_raise NoMethodError do
|
62
|
-
m.
|
59
|
+
m.has_singular_string?
|
63
60
|
end
|
64
61
|
assert_raise ArgumentError do
|
65
|
-
|
62
|
+
TestSingularFields.descriptor.lookup('singular_string').has?(m)
|
66
63
|
end
|
67
64
|
|
68
65
|
assert_raise NoMethodError do
|
69
|
-
m.
|
66
|
+
m.has_singular_bool?
|
70
67
|
end
|
71
68
|
assert_raise ArgumentError do
|
72
|
-
|
69
|
+
TestSingularFields.descriptor.lookup('singular_bool').has?(m)
|
73
70
|
end
|
74
71
|
|
72
|
+
m = TestMessage.new
|
75
73
|
assert_raise NoMethodError do
|
76
74
|
m.has_repeated_msg?
|
77
75
|
end
|
@@ -80,40 +78,59 @@ module BasicTest
|
|
80
78
|
end
|
81
79
|
end
|
82
80
|
|
81
|
+
def test_no_presence
|
82
|
+
m = TestSingularFields.new
|
83
|
+
|
84
|
+
# Explicitly setting to zero does not cause anything to be serialized.
|
85
|
+
m.singular_int32 = 0
|
86
|
+
assert_equal "", TestSingularFields.encode(m)
|
87
|
+
|
88
|
+
# Explicitly setting to a non-zero value *does* cause serialization.
|
89
|
+
m.singular_int32 = 1
|
90
|
+
assert_not_equal "", TestSingularFields.encode(m)
|
91
|
+
|
92
|
+
m.singular_int32 = 0
|
93
|
+
assert_equal "", TestSingularFields.encode(m)
|
94
|
+
end
|
95
|
+
|
83
96
|
def test_set_clear_defaults
|
84
|
-
m =
|
97
|
+
m = TestSingularFields.new
|
98
|
+
|
99
|
+
m.singular_int32 = -42
|
100
|
+
assert_equal -42, m.singular_int32
|
101
|
+
m.clear_singular_int32
|
102
|
+
assert_equal 0, m.singular_int32
|
103
|
+
|
104
|
+
m.singular_int32 = 50
|
105
|
+
assert_equal 50, m.singular_int32
|
106
|
+
TestSingularFields.descriptor.lookup('singular_int32').clear(m)
|
107
|
+
assert_equal 0, m.singular_int32
|
108
|
+
|
109
|
+
m.singular_string = "foo bar"
|
110
|
+
assert_equal "foo bar", m.singular_string
|
111
|
+
m.clear_singular_string
|
112
|
+
assert_equal "", m.singular_string
|
113
|
+
|
114
|
+
m.singular_string = "foo"
|
115
|
+
assert_equal "foo", m.singular_string
|
116
|
+
TestSingularFields.descriptor.lookup('singular_string').clear(m)
|
117
|
+
assert_equal "", m.singular_string
|
118
|
+
|
119
|
+
m.singular_msg = TestMessage2.new(:foo => 42)
|
120
|
+
assert_equal TestMessage2.new(:foo => 42), m.singular_msg
|
121
|
+
assert m.has_singular_msg?
|
122
|
+
m.clear_singular_msg
|
123
|
+
assert_equal nil, m.singular_msg
|
124
|
+
assert !m.has_singular_msg?
|
125
|
+
|
126
|
+
m.singular_msg = TestMessage2.new(:foo => 42)
|
127
|
+
assert_equal TestMessage2.new(:foo => 42), m.singular_msg
|
128
|
+
TestSingularFields.descriptor.lookup('singular_msg').clear(m)
|
129
|
+
assert_equal nil, m.singular_msg
|
130
|
+
end
|
85
131
|
|
86
|
-
|
87
|
-
|
88
|
-
m.clear_optional_int32
|
89
|
-
assert_equal 0, m.optional_int32
|
90
|
-
|
91
|
-
m.optional_int32 = 50
|
92
|
-
assert_equal 50, m.optional_int32
|
93
|
-
TestMessage.descriptor.lookup('optional_int32').clear(m)
|
94
|
-
assert_equal 0, m.optional_int32
|
95
|
-
|
96
|
-
m.optional_string = "foo bar"
|
97
|
-
assert_equal "foo bar", m.optional_string
|
98
|
-
m.clear_optional_string
|
99
|
-
assert_equal "", m.optional_string
|
100
|
-
|
101
|
-
m.optional_string = "foo"
|
102
|
-
assert_equal "foo", m.optional_string
|
103
|
-
TestMessage.descriptor.lookup('optional_string').clear(m)
|
104
|
-
assert_equal "", m.optional_string
|
105
|
-
|
106
|
-
m.optional_msg = TestMessage2.new(:foo => 42)
|
107
|
-
assert_equal TestMessage2.new(:foo => 42), m.optional_msg
|
108
|
-
assert m.has_optional_msg?
|
109
|
-
m.clear_optional_msg
|
110
|
-
assert_equal nil, m.optional_msg
|
111
|
-
assert !m.has_optional_msg?
|
112
|
-
|
113
|
-
m.optional_msg = TestMessage2.new(:foo => 42)
|
114
|
-
assert_equal TestMessage2.new(:foo => 42), m.optional_msg
|
115
|
-
TestMessage.descriptor.lookup('optional_msg').clear(m)
|
116
|
-
assert_equal nil, m.optional_msg
|
132
|
+
def test_clear_repeated_fields
|
133
|
+
m = TestMessage.new
|
117
134
|
|
118
135
|
m.repeated_int32.push(1)
|
119
136
|
assert_equal [1], m.repeated_int32
|
@@ -129,6 +146,7 @@ module BasicTest
|
|
129
146
|
m.a = "foo"
|
130
147
|
assert_equal "foo", m.a
|
131
148
|
assert m.has_my_oneof?
|
149
|
+
assert_equal :a, m.my_oneof
|
132
150
|
m.clear_a
|
133
151
|
assert !m.has_my_oneof?
|
134
152
|
|
@@ -144,7 +162,6 @@ module BasicTest
|
|
144
162
|
assert !m.has_my_oneof?
|
145
163
|
end
|
146
164
|
|
147
|
-
|
148
165
|
def test_initialization_map_errors
|
149
166
|
e = assert_raise ArgumentError do
|
150
167
|
TestMessage.new(:hello => "world")
|
@@ -154,12 +171,12 @@ module BasicTest
|
|
154
171
|
e = assert_raise ArgumentError do
|
155
172
|
MapMessage.new(:map_string_int32 => "hello")
|
156
173
|
end
|
157
|
-
assert_equal e.message, "Expected Hash object as initializer value for map field 'map_string_int32'."
|
174
|
+
assert_equal e.message, "Expected Hash object as initializer value for map field 'map_string_int32' (given String)."
|
158
175
|
|
159
176
|
e = assert_raise ArgumentError do
|
160
177
|
TestMessage.new(:repeated_uint32 => "hello")
|
161
178
|
end
|
162
|
-
assert_equal e.message, "Expected array as initializer value for repeated field 'repeated_uint32'."
|
179
|
+
assert_equal e.message, "Expected array as initializer value for repeated field 'repeated_uint32' (given String)."
|
163
180
|
end
|
164
181
|
|
165
182
|
def test_map_field
|
@@ -170,10 +187,12 @@ module BasicTest
|
|
170
187
|
m = MapMessage.new(
|
171
188
|
:map_string_int32 => {"a" => 1, "b" => 2},
|
172
189
|
:map_string_msg => {"a" => TestMessage2.new(:foo => 1),
|
173
|
-
"b" => TestMessage2.new(:foo => 2)}
|
190
|
+
"b" => TestMessage2.new(:foo => 2)},
|
191
|
+
:map_string_enum => {"a" => :A, "b" => :B})
|
174
192
|
assert m.map_string_int32.keys.sort == ["a", "b"]
|
175
193
|
assert m.map_string_int32["a"] == 1
|
176
194
|
assert m.map_string_msg["b"].foo == 2
|
195
|
+
assert m.map_string_enum["a"] == :A
|
177
196
|
|
178
197
|
m.map_string_int32["c"] = 3
|
179
198
|
assert m.map_string_int32["c"] == 3
|
@@ -202,12 +221,27 @@ module BasicTest
|
|
202
221
|
end
|
203
222
|
end
|
204
223
|
|
224
|
+
def test_map_field_with_symbol
|
225
|
+
m = MapMessage.new
|
226
|
+
assert m.map_string_int32 == {}
|
227
|
+
assert m.map_string_msg == {}
|
228
|
+
|
229
|
+
m = MapMessage.new(
|
230
|
+
:map_string_int32 => {a: 1, "b" => 2},
|
231
|
+
:map_string_msg => {a: TestMessage2.new(:foo => 1),
|
232
|
+
b: TestMessage2.new(:foo => 10)})
|
233
|
+
assert_equal 1, m.map_string_int32[:a]
|
234
|
+
assert_equal 2, m.map_string_int32[:b]
|
235
|
+
assert_equal 10, m.map_string_msg[:b].foo
|
236
|
+
end
|
237
|
+
|
205
238
|
def test_map_inspect
|
206
239
|
m = MapMessage.new(
|
207
240
|
:map_string_int32 => {"a" => 1, "b" => 2},
|
208
241
|
:map_string_msg => {"a" => TestMessage2.new(:foo => 1),
|
209
|
-
"b" => TestMessage2.new(:foo => 2)}
|
210
|
-
|
242
|
+
"b" => TestMessage2.new(:foo => 2)},
|
243
|
+
:map_string_enum => {"a" => :A, "b" => :B})
|
244
|
+
expected = "<BasicTest::MapMessage: map_string_int32: {\"b\"=>2, \"a\"=>1}, map_string_msg: {\"b\"=><BasicTest::TestMessage2: foo: 2>, \"a\"=><BasicTest::TestMessage2: foo: 1>}, map_string_enum: {\"b\"=>:B, \"a\"=>:A}>"
|
211
245
|
assert_equal expected, m.inspect
|
212
246
|
end
|
213
247
|
|
@@ -218,6 +252,128 @@ module BasicTest
|
|
218
252
|
m.map_string_int32['aaa'] = 3
|
219
253
|
end
|
220
254
|
|
255
|
+
def test_map_wrappers
|
256
|
+
run_asserts = ->(m) {
|
257
|
+
assert_equal 2.0, m.map_double[0].value
|
258
|
+
assert_equal 4.0, m.map_float[0].value
|
259
|
+
assert_equal 3, m.map_int32[0].value
|
260
|
+
assert_equal 4, m.map_int64[0].value
|
261
|
+
assert_equal 5, m.map_uint32[0].value
|
262
|
+
assert_equal 6, m.map_uint64[0].value
|
263
|
+
assert_equal true, m.map_bool[0].value
|
264
|
+
assert_equal 'str', m.map_string[0].value
|
265
|
+
assert_equal 'fun', m.map_bytes[0].value
|
266
|
+
}
|
267
|
+
|
268
|
+
m = proto_module::Wrapper.new(
|
269
|
+
map_double: {0 => Google::Protobuf::DoubleValue.new(value: 2.0)},
|
270
|
+
map_float: {0 => Google::Protobuf::FloatValue.new(value: 4.0)},
|
271
|
+
map_int32: {0 => Google::Protobuf::Int32Value.new(value: 3)},
|
272
|
+
map_int64: {0 => Google::Protobuf::Int64Value.new(value: 4)},
|
273
|
+
map_uint32: {0 => Google::Protobuf::UInt32Value.new(value: 5)},
|
274
|
+
map_uint64: {0 => Google::Protobuf::UInt64Value.new(value: 6)},
|
275
|
+
map_bool: {0 => Google::Protobuf::BoolValue.new(value: true)},
|
276
|
+
map_string: {0 => Google::Protobuf::StringValue.new(value: 'str')},
|
277
|
+
map_bytes: {0 => Google::Protobuf::BytesValue.new(value: 'fun')},
|
278
|
+
)
|
279
|
+
|
280
|
+
run_asserts.call(m)
|
281
|
+
serialized = proto_module::Wrapper::encode(m)
|
282
|
+
m2 = proto_module::Wrapper::decode(serialized)
|
283
|
+
run_asserts.call(m2)
|
284
|
+
|
285
|
+
# Test the case where we are serializing directly from the parsed form
|
286
|
+
# (before anything lazy is materialized).
|
287
|
+
m3 = proto_module::Wrapper::decode(serialized)
|
288
|
+
serialized2 = proto_module::Wrapper::encode(m3)
|
289
|
+
m4 = proto_module::Wrapper::decode(serialized2)
|
290
|
+
run_asserts.call(m4)
|
291
|
+
|
292
|
+
# Test that the lazy form compares equal to the expanded form.
|
293
|
+
m5 = proto_module::Wrapper::decode(serialized2)
|
294
|
+
assert_equal m5, m
|
295
|
+
end
|
296
|
+
|
297
|
+
def test_map_wrappers_with_default_values
|
298
|
+
run_asserts = ->(m) {
|
299
|
+
assert_equal 0.0, m.map_double[0].value
|
300
|
+
assert_equal 0.0, m.map_float[0].value
|
301
|
+
assert_equal 0, m.map_int32[0].value
|
302
|
+
assert_equal 0, m.map_int64[0].value
|
303
|
+
assert_equal 0, m.map_uint32[0].value
|
304
|
+
assert_equal 0, m.map_uint64[0].value
|
305
|
+
assert_equal false, m.map_bool[0].value
|
306
|
+
assert_equal '', m.map_string[0].value
|
307
|
+
assert_equal '', m.map_bytes[0].value
|
308
|
+
}
|
309
|
+
|
310
|
+
m = proto_module::Wrapper.new(
|
311
|
+
map_double: {0 => Google::Protobuf::DoubleValue.new(value: 0.0)},
|
312
|
+
map_float: {0 => Google::Protobuf::FloatValue.new(value: 0.0)},
|
313
|
+
map_int32: {0 => Google::Protobuf::Int32Value.new(value: 0)},
|
314
|
+
map_int64: {0 => Google::Protobuf::Int64Value.new(value: 0)},
|
315
|
+
map_uint32: {0 => Google::Protobuf::UInt32Value.new(value: 0)},
|
316
|
+
map_uint64: {0 => Google::Protobuf::UInt64Value.new(value: 0)},
|
317
|
+
map_bool: {0 => Google::Protobuf::BoolValue.new(value: false)},
|
318
|
+
map_string: {0 => Google::Protobuf::StringValue.new(value: '')},
|
319
|
+
map_bytes: {0 => Google::Protobuf::BytesValue.new(value: '')},
|
320
|
+
)
|
321
|
+
|
322
|
+
run_asserts.call(m)
|
323
|
+
serialized = proto_module::Wrapper::encode(m)
|
324
|
+
m2 = proto_module::Wrapper::decode(serialized)
|
325
|
+
run_asserts.call(m2)
|
326
|
+
|
327
|
+
# Test the case where we are serializing directly from the parsed form
|
328
|
+
# (before anything lazy is materialized).
|
329
|
+
m3 = proto_module::Wrapper::decode(serialized)
|
330
|
+
serialized2 = proto_module::Wrapper::encode(m3)
|
331
|
+
m4 = proto_module::Wrapper::decode(serialized2)
|
332
|
+
run_asserts.call(m4)
|
333
|
+
|
334
|
+
# Test that the lazy form compares equal to the expanded form.
|
335
|
+
m5 = proto_module::Wrapper::decode(serialized2)
|
336
|
+
assert_equal m5, m
|
337
|
+
end
|
338
|
+
|
339
|
+
def test_map_wrappers_with_no_value
|
340
|
+
run_asserts = ->(m) {
|
341
|
+
assert_equal 0.0, m.map_double[0].value
|
342
|
+
assert_equal 0.0, m.map_float[0].value
|
343
|
+
assert_equal 0, m.map_int32[0].value
|
344
|
+
assert_equal 0, m.map_int64[0].value
|
345
|
+
assert_equal 0, m.map_uint32[0].value
|
346
|
+
assert_equal 0, m.map_uint64[0].value
|
347
|
+
assert_equal false, m.map_bool[0].value
|
348
|
+
assert_equal '', m.map_string[0].value
|
349
|
+
assert_equal '', m.map_bytes[0].value
|
350
|
+
}
|
351
|
+
|
352
|
+
m = proto_module::Wrapper.new(
|
353
|
+
map_double: {0 => Google::Protobuf::DoubleValue.new()},
|
354
|
+
map_float: {0 => Google::Protobuf::FloatValue.new()},
|
355
|
+
map_int32: {0 => Google::Protobuf::Int32Value.new()},
|
356
|
+
map_int64: {0 => Google::Protobuf::Int64Value.new()},
|
357
|
+
map_uint32: {0 => Google::Protobuf::UInt32Value.new()},
|
358
|
+
map_uint64: {0 => Google::Protobuf::UInt64Value.new()},
|
359
|
+
map_bool: {0 => Google::Protobuf::BoolValue.new()},
|
360
|
+
map_string: {0 => Google::Protobuf::StringValue.new()},
|
361
|
+
map_bytes: {0 => Google::Protobuf::BytesValue.new()},
|
362
|
+
)
|
363
|
+
run_asserts.call(m)
|
364
|
+
|
365
|
+
serialized = proto_module::Wrapper::encode(m)
|
366
|
+
m2 = proto_module::Wrapper::decode(serialized)
|
367
|
+
run_asserts.call(m2)
|
368
|
+
|
369
|
+
# Test the case where we are serializing directly from the parsed form
|
370
|
+
# (before anything lazy is materialized).
|
371
|
+
m3 = proto_module::Wrapper::decode(serialized)
|
372
|
+
serialized2 = proto_module::Wrapper::encode(m3)
|
373
|
+
m4 = proto_module::Wrapper::decode(serialized2)
|
374
|
+
run_asserts.call(m4)
|
375
|
+
end
|
376
|
+
|
221
377
|
def test_concurrent_decoding
|
222
378
|
o = Outer.new
|
223
379
|
o.items[0] = Inner.new
|
@@ -237,7 +393,8 @@ module BasicTest
|
|
237
393
|
m = MapMessage.new(
|
238
394
|
:map_string_int32 => {"a" => 1, "b" => 2},
|
239
395
|
:map_string_msg => {"a" => TestMessage2.new(:foo => 1),
|
240
|
-
"b" => TestMessage2.new(:foo => 2)}
|
396
|
+
"b" => TestMessage2.new(:foo => 2)},
|
397
|
+
:map_string_enum => {"a" => :A, "b" => :B})
|
241
398
|
m2 = MapMessage.decode(MapMessage.encode(m))
|
242
399
|
assert m == m2
|
243
400
|
|
@@ -267,6 +424,14 @@ module BasicTest
|
|
267
424
|
assert_match(/No such field: not_in_message/, e.message)
|
268
425
|
end
|
269
426
|
|
427
|
+
#def test_json_quoted_string
|
428
|
+
# m = TestMessage.decode_json(%q(
|
429
|
+
# "optionalInt64": "1",,
|
430
|
+
# }))
|
431
|
+
# puts(m)
|
432
|
+
# assert_equal 1, m.optional_int32
|
433
|
+
#end
|
434
|
+
|
270
435
|
def test_to_h
|
271
436
|
m = TestMessage.new(:optional_bool => true, :optional_double => -10.100001, :optional_string => 'foo', :repeated_string => ['bar1', 'bar2'], :repeated_msg => [TestMessage2.new(:foo => 100)])
|
272
437
|
expected_result = {
|
@@ -298,10 +463,12 @@ module BasicTest
|
|
298
463
|
m = MapMessage.new(
|
299
464
|
:map_string_int32 => {"a" => 1, "b" => 2},
|
300
465
|
:map_string_msg => {"a" => TestMessage2.new(:foo => 1),
|
301
|
-
"b" => TestMessage2.new(:foo => 2)}
|
466
|
+
"b" => TestMessage2.new(:foo => 2)},
|
467
|
+
:map_string_enum => {"a" => :A, "b" => :B})
|
302
468
|
expected_result = {
|
303
469
|
:map_string_int32 => {"a" => 1, "b" => 2},
|
304
|
-
:map_string_msg => {"a" => {:foo => 1}, "b" => {:foo => 2}}
|
470
|
+
:map_string_msg => {"a" => {:foo => 1}, "b" => {:foo => 2}},
|
471
|
+
:map_string_enum => {"a" => :A, "b" => :B}
|
305
472
|
}
|
306
473
|
assert_equal expected_result, m.to_h
|
307
474
|
end
|
@@ -311,26 +478,26 @@ module BasicTest
|
|
311
478
|
# TODO: Fix JSON in JRuby version.
|
312
479
|
return if RUBY_PLATFORM == "java"
|
313
480
|
m = MapMessage.new(:map_string_int32 => {"a" => 1})
|
314
|
-
expected = {mapStringInt32: {a: 1}, mapStringMsg: {}}
|
315
|
-
expected_preserve = {map_string_int32: {a: 1}, map_string_msg: {}}
|
316
|
-
|
481
|
+
expected = {mapStringInt32: {a: 1}, mapStringMsg: {}, mapStringEnum: {}}
|
482
|
+
expected_preserve = {map_string_int32: {a: 1}, map_string_msg: {}, map_string_enum: {}}
|
483
|
+
assert_equal JSON.parse(MapMessage.encode_json(m), :symbolize_names => true), expected
|
317
484
|
|
318
485
|
json = MapMessage.encode_json(m, :preserve_proto_fieldnames => true)
|
319
|
-
|
486
|
+
assert_equal JSON.parse(json, :symbolize_names => true), expected_preserve
|
320
487
|
|
321
488
|
m2 = MapMessage.decode_json(MapMessage.encode_json(m))
|
322
|
-
|
489
|
+
assert_equal m, m2
|
323
490
|
end
|
324
491
|
|
325
492
|
def test_json_maps_emit_defaults_submsg
|
326
493
|
# TODO: Fix JSON in JRuby version.
|
327
494
|
return if RUBY_PLATFORM == "java"
|
328
495
|
m = MapMessage.new(:map_string_msg => {"a" => TestMessage2.new})
|
329
|
-
expected = {mapStringInt32: {}, mapStringMsg: {a: {foo: 0}}}
|
496
|
+
expected = {mapStringInt32: {}, mapStringMsg: {a: {foo: 0}}, mapStringEnum: {}}
|
330
497
|
|
331
498
|
actual = MapMessage.encode_json(m, :emit_defaults => true)
|
332
499
|
|
333
|
-
|
500
|
+
assert_equal JSON.parse(actual, :symbolize_names => true), expected
|
334
501
|
end
|
335
502
|
|
336
503
|
def test_respond_to
|
@@ -351,11 +518,26 @@ module BasicTest
|
|
351
518
|
assert nil != file_descriptor
|
352
519
|
assert_equal "tests/basic_test.proto", file_descriptor.name
|
353
520
|
assert_equal :proto3, file_descriptor.syntax
|
521
|
+
end
|
354
522
|
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
523
|
+
# Ruby 2.5 changed to raise FrozenError instead of RuntimeError
|
524
|
+
FrozenErrorType = Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.5') ? RuntimeError : FrozenError
|
525
|
+
|
526
|
+
def test_map_freeze
|
527
|
+
m = proto_module::MapMessage.new
|
528
|
+
m.map_string_int32['a'] = 5
|
529
|
+
m.map_string_msg['b'] = proto_module::TestMessage2.new
|
530
|
+
|
531
|
+
m.map_string_int32.freeze
|
532
|
+
m.map_string_msg.freeze
|
533
|
+
|
534
|
+
assert m.map_string_int32.frozen?
|
535
|
+
assert m.map_string_msg.frozen?
|
536
|
+
|
537
|
+
assert_raise(FrozenErrorType) { m.map_string_int32['foo'] = 1 }
|
538
|
+
assert_raise(FrozenErrorType) { m.map_string_msg['bar'] = proto_module::TestMessage2.new }
|
539
|
+
assert_raise(FrozenErrorType) { m.map_string_int32.delete('a') }
|
540
|
+
assert_raise(FrozenErrorType) { m.map_string_int32.clear }
|
359
541
|
end
|
360
542
|
end
|
361
543
|
end
|
File without changes
|
data/tests/stress.rb
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,43 +1,49 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-protobuf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Protobuf Authors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler-dock
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 1.0.1
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2.0'
|
20
23
|
type: :development
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.0.1
|
30
|
+
- - "<"
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
32
|
+
version: '2.0'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: rake-compiler
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - "~>"
|
32
38
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
39
|
+
version: 1.1.0
|
34
40
|
type: :development
|
35
41
|
prerelease: false
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
37
43
|
requirements:
|
38
44
|
- - "~>"
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
46
|
+
version: 1.1.0
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: test-unit
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -111,7 +117,8 @@ files:
|
|
111
117
|
homepage: https://developers.google.com/protocol-buffers
|
112
118
|
licenses:
|
113
119
|
- BSD-3-Clause
|
114
|
-
metadata:
|
120
|
+
metadata:
|
121
|
+
source_code_uri: https://github.com/protocolbuffers/protobuf/tree/v3.13.0/ruby
|
115
122
|
post_install_message:
|
116
123
|
rdoc_options: []
|
117
124
|
require_paths:
|
@@ -120,15 +127,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
120
127
|
requirements:
|
121
128
|
- - ">="
|
122
129
|
- !ruby/object:Gem::Version
|
123
|
-
version: '
|
130
|
+
version: '2.3'
|
124
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
132
|
requirements:
|
126
133
|
- - ">="
|
127
134
|
- !ruby/object:Gem::Version
|
128
135
|
version: '0'
|
129
136
|
requirements: []
|
130
|
-
|
131
|
-
rubygems_version: 2.7.8
|
137
|
+
rubygems_version: 3.1.4
|
132
138
|
signing_key:
|
133
139
|
specification_version: 4
|
134
140
|
summary: Protocol Buffers
|