• Home
  • Raw
  • Download

Lines Matching full:m

16     m = proto_module::TestMessage.new
17 assert m.optional_int32 == 0
18 assert m.optional_int64 == 0
19 assert m.optional_uint32 == 0
20 assert m.optional_uint64 == 0
21 assert m.optional_bool == false
22 assert m.optional_float == 0.0
23 assert m.optional_double == 0.0
24 assert m.optional_string == ""
25 assert m.optional_bytes == ""
26 assert m.optional_msg == nil
27 assert m.optional_enum == :Default
31 m = proto_module::TestMessage.new
32 m.optional_int32 = -42
33 assert m.optional_int32 == -42
34 m.optional_int64 = -0x1_0000_0000
35 assert m.optional_int64 == -0x1_0000_0000
36 m.optional_uint32 = 0x9000_0000
37 assert m.optional_uint32 == 0x9000_0000
38 m.optional_uint64 = 0x9000_0000_0000_0000
39 assert m.optional_uint64 == 0x9000_0000_0000_0000
40 m.optional_bool = true
41 assert m.optional_bool == true
42 m.optional_float = 0.5
43 assert m.optional_float == 0.5
44 m.optional_double = 0.5
45 assert m.optional_double == 0.5
46 m.optional_string = "hello"
47 assert m.optional_string == "hello"
48 m.optional_string = :hello
49 assert m.optional_string == "hello"
50 m.optional_bytes = "world".encode!('ASCII-8BIT')
51 assert m.optional_bytes == "world"
52 m.optional_msg = proto_module::TestMessage2.new(:foo => 42)
53 assert m.optional_msg == proto_module::TestMessage2.new(:foo => 42)
54 m.optional_msg = nil
55 assert m.optional_msg == nil
56 m.optional_enum = :C
57 assert m.optional_enum == :C
58 m.optional_enum = 'C'
59 assert m.optional_enum == :C
63 m = proto_module::TestMessage.new(:optional_int32 => -42,
67 assert m.optional_int32 == -42
68 assert m.optional_msg.class == proto_module::TestMessage2
69 assert m.repeated_string.length == 3
70 assert m.optional_enum == :C
71 assert m.repeated_string[0] == "hello"
72 assert m.repeated_string[1] == "there"
73 assert m.repeated_string[2] == "world"
77 m = proto_module::TestMessage.new(:optional_enum => 'C', :repeated_enum => ['A', 'B'])
78 assert_equal :C, m.optional_enum
79 assert_equal [:A, :B], m.repeated_enum
81 m = proto_module::TestMessage.new(:optional_string => :foo, :repeated_string => [:foo, :bar])
82 assert_equal 'foo', m.optional_string
83 assert_equal ['foo', 'bar'], m.repeated_string
87m = proto_module::TestMessage.new(:optional_enum => nil, :optional_int32 => nil, :optional_string …
89 assert_equal :Default, m.optional_enum
90 assert_equal 0, m.optional_int32
91 assert_equal "", m.optional_string
92 assert_nil m.optional_msg
96 m = proto_module::TestEmbeddedMessageParent.new(
102 assert_equal 2, m.number
103 assert_equal [10, 20, 30], m.repeated_number
105 assert_not_nil m.child_msg
106 assert_not_nil m.child_msg.sub_child
107 assert_equal m.child_msg.sub_child.optional_int32, 1
109 assert_not_nil m.repeated_msg
110 assert_equal 1, m.repeated_msg.length
111 assert_equal 3, m.repeated_msg.first.sub_child.optional_int32
115 m = proto_module::TestMessage.new(
121 assert_equal expected, m.inspect
122 assert_equal expected, m.to_s
124 m = proto_module::OneofMessage.new(:b => -42)
126 assert_equal expected, m.inspect
127 assert_equal expected, m.to_s
156 m = proto_module::TestMessage.new
158 m.optional_int32 = "hello"
166 m.optional_string = 42
169 m.optional_string = nil
172 m.optional_bool = 42
175 m.optional_msg = proto_module::TestMessage.new # expects TestMessage2
179 m.repeated_int32 = [] # needs RepeatedField
183 m.repeated_int32.push "hello"
187 m.repeated_msg.push proto_module::TestMessage.new
192 m = proto_module::TestMessage.new
196 m.optional_bytes = "Test string ASCII".encode!('ASCII')
197 assert m.optional_bytes.frozen?
198 assert_equal Encoding::ASCII_8BIT, m.optional_bytes.encoding
199 assert_equal "Test string ASCII", m.optional_bytes
202 m.optional_bytes = "Test string UTF-8 \u0100".encode!('UTF-8')
206 m.optional_string = ["FFFF"].pack('H*')
210 m.optional_bytes = ["FFFF"].pack('H*')
211 m.optional_string = "\u0100"
214 m.optional_string = "asdf".encode!('UTF-8')
215 assert_raise(FrozenErrorType) { m.optional_string.encode!('ASCII-8BIT') }
251 m = proto_module::TestMessage.new
252 l.push m
255 m = proto_module::TestMessage.new
256 m.repeated_int32 = l
257 assert m.repeated_int32 == [5, 2, 3, 4, 7, 8]
258 assert m.repeated_int32.object_id == l.object_id
260 assert m.repeated_int32.pop == 42
287 m = proto_module::TestMessage.new
288 assert m.repeated_string == []
289 m.repeated_string << 'ok'
290 m.repeated_string.push('ok2')
291 assert m.repeated_string == ['ok', 'ok2']
292 m.repeated_string += ['ok3']
293 assert m.repeated_string == ['ok', 'ok2', 'ok3']
396 m = Google::Protobuf::Map.new(:string, :int32)
397 m["asdf"] = 1
398 assert m["asdf"] == 1
399 m["jkl;"] = 42
400 assert m == { "jkl;" => 42, "asdf" => 1 }
401 assert m.has_key?("asdf")
402 assert !m.has_key?("qwerty")
403 assert m.length == 2
405 m2 = m.dup
406 assert_equal m, m2
407 assert m.hash != 0
408 assert_equal m.hash, m2.hash
411 m.each { |k,v| collected[v] = k }
414 assert m.delete("asdf") == 1
415 assert !m.has_key?("asdf")
416 assert m["asdf"] == nil
417 assert !m.has_key?("asdf")
422 assert m.inspect == "{\"jkl;\"=>42}"
424 assert m.keys == ["jkl;"]
425 assert m.values == [42]
427 m.clear
428 assert m.length == 0
429 assert m == {}
432 m[1] = 1
435 m["asdf"] = 0x1_0000_0000
440 m = Google::Protobuf::Map.new(:string, :int32,
442 assert m == {"a" => 1, "c" => 3, "b" => 2}
446 m = Google::Protobuf::Map.new(:int32, :int32)
447 m[1] = 42
448 m[-1] = 42
450 m[0x8000_0000] = 1
453 m["asdf"] = 1
456 m = Google::Protobuf::Map.new(:int64, :int32)
457 m[0x1000_0000_0000_0000] = 1
459 m[0x1_0000_0000_0000_0000] = 1
462 m["asdf"] = 1
465 m = Google::Protobuf::Map.new(:uint32, :int32)
466 m[0x8000_0000] = 1
468 m[0x1_0000_0000] = 1
471 m[-1] = 1
474 m = Google::Protobuf::Map.new(:uint64, :int32)
475 m[0x8000_0000_0000_0000] = 1
477 m[0x1_0000_0000_0000_0000] = 1
480 m[-1] = 1
483 m = Google::Protobuf::Map.new(:bool, :int32)
484 m[true] = 1
485 m[false] = 2
487 m[1] = 1
490 m["asdf"] = 1
493 m = Google::Protobuf::Map.new(:string, :int32)
494 m["asdf"] = 1
496 m[1] = 1
500 m[bytestring] = 1
503 m = Google::Protobuf::Map.new(:bytes, :int32)
505 m[bytestring] = 1
507 m["asdf"] = 1
509 m[1] = 1
514 m = Google::Protobuf::Map.new(:string, :message, proto_module::TestMessage)
515 m["asdf"] = proto_module::TestMessage.new
517 m["jkl;"] = proto_module::TestMessage2.new
520 m = Google::Protobuf::Map.new(
524 assert m.length == 2
525 assert m.values.map{|msg| msg.optional_int32}.sort == [42, 84]
527 m = Google::Protobuf::Map.new(:string, :enum, proto_module::TestEnum,
529 assert m.length == 3
530 assert m["z"] == :C
531 m["z"] = 2
532 assert m["z"] == :B
533 m["z"] = 4
534 assert m["z"] == 4
536 m["z"] = :Z
539 m["z"] = "z"
544 m = Google::Protobuf::Map.new(
549 m2 = m.dup
550 assert m == m2
551 assert m.object_id != m2.object_id
552 assert m["a"].object_id == m2["a"].object_id
553 assert m["b"].object_id == m2["b"].object_id
555 m2 = Google::Protobuf.deep_copy(m)
556 assert m == m2
557 assert m.object_id != m2.object_id
558 assert m["a"].object_id != m2["a"].object_id
559 assert m["b"].object_id != m2["b"].object_id
648 m = proto_module::TestMessage.new
649 assert m.optional_enum == :Default
650 m.optional_enum = :A
651 assert m.optional_enum == :A
653 m.optional_enum = :ASDF
655 m.optional_enum = 1
656 assert m.optional_enum == :A
657 m.optional_enum = 100
658 assert m.optional_enum == 100
662 m = proto_module::TestMessage.new
663 m.optional_string = "hello"
664 m.optional_int32 = 42
667 m.repeated_msg.push tm1
668 assert m.repeated_msg[-1] == tm1
669 m.repeated_msg.push tm2
670 assert m.repeated_msg[-1] == tm2
671 m2 = m.dup
672 assert m == m2
673 m.optional_int32 += 1
674 assert m != m2
675 assert m.repeated_msg[0] == m2.repeated_msg[0]
676 assert m.repeated_msg[0].object_id == m2.repeated_msg[0].object_id
680 m = proto_module::TestMessage.new(:optional_int32 => 42,
682 m2 = Google::Protobuf.deep_copy(m)
683 assert m == m2
684 assert m.repeated_msg == m2.repeated_msg
685 assert m.repeated_msg.object_id != m2.repeated_msg.object_id
686 assert m.repeated_msg[0].object_id != m2.repeated_msg[0].object_id
690 m = proto_module::TestMessage.new(:optional_int32 => 42,
694 assert m != m2
712 m = proto_module::TestMessage.new
713 assert_equal proto_module::TestEnum::Default, m.optional_enum_const
714 assert_equal proto_module::TestEnum.const_get(:Default), m.optional_enum_const
716 m = proto_module::TestMessage.new({optional_enum: proto_module::TestEnum::A})
717 assert_equal proto_module::TestEnum::A, m.optional_enum_const
718 assert_equal proto_module::TestEnum.const_get(:A), m.optional_enum_const
720 m = proto_module::TestMessage.new({optional_enum: proto_module::TestEnum::B})
721 assert_equal proto_module::TestEnum::B, m.optional_enum_const
722 assert_equal proto_module::TestEnum.const_get(:B), m.optional_enum_const
724 m = proto_module::TestMessage.new({optional_enum: proto_module::TestEnum::C})
725 assert_equal proto_module::TestEnum::C, m.optional_enum_const
726 assert_equal proto_module::TestEnum.const_get(:C), m.optional_enum_const
728 m = proto_module::TestMessage2.new({foo: 2})
729 assert_equal 2, m.foo
730 assert_raise(NoMethodError) { m.foo_ }
731 assert_raise(NoMethodError) { m.foo_X }
732 assert_raise(NoMethodError) { m.foo_XX }
733 assert_raise(NoMethodError) { m.foo_XXX }
734 assert_raise(NoMethodError) { m.foo_XXXX }
735 assert_raise(NoMethodError) { m.foo_XXXXX }
736 assert_raise(NoMethodError) { m.foo_XXXXXX }
738 m = proto_module::Enumer.new({optional_enum: :B})
739 assert_equal :B, m.optional_enum
740 assert_raise(NoMethodError) { m.optional_enum_ }
741 assert_raise(NoMethodError) { m.optional_enum_X }
742 assert_raise(NoMethodError) { m.optional_enum_XX }
743 assert_raise(NoMethodError) { m.optional_enum_XXX }
744 assert_raise(NoMethodError) { m.optional_enum_XXXX }
745 assert_raise(NoMethodError) { m.optional_enum_XXXXX }
746 assert_raise(NoMethodError) { m.optional_enum_XXXXXX }
750 m = proto_module::Enumer.new(:optional_enum => :B, :repeated_enum => [:A, :C])
752 assert_equal :B, m.optional_enum
753 assert_equal 2, m.optional_enum_const
754 assert_equal proto_module::TestEnum::B, m.optional_enum_const
755 assert_equal [:A, :C], m.repeated_enum
756 assert_equal [1, 3], m.repeated_enum_const
757 assert_equal [proto_module::TestEnum::A, proto_module::TestEnum::C], m.repeated_enum_const
761 m = proto_module::Enumer.new(:const => :C)
763 assert_equal :C, m.const
764 assert_equal 3, m.const_const
765 assert_equal proto_module::TestEnum::C, m.const_const
769 m = proto_module::Enumer.new(:optional_enum => :B, :a_const => 'thing')
771 assert_equal 'thing', m.a_const
772 assert_equal :B, m.optional_enum
774 assert_raise(NoMethodError) { m.a }
775 assert_raise(NoMethodError) { m.a_const_const }
779 m = proto_module::TestMessage.new
781 m.repeated_string += ['one']
782 m.repeated_string += %w[two three]
783 assert_equal %w[one two three], m.repeated_string
785 m.repeated_string.push *['four', 'five']
786 assert_equal %w[one two three four five], m.repeated_string
788 m.repeated_string.push 'six', 'seven'
789 assert_equal %w[one two three four five six seven], m.repeated_string
791 m = proto_module::TestMessage.new
793m.repeated_msg += [proto_module::TestMessage2.new(:foo => 1), proto_module::TestMessage2.new(:foo …
794 m.repeated_msg += [proto_module::TestMessage2.new(:foo => 3)]
795m.repeated_msg.push proto_module::TestMessage2.new(:foo => 4), proto_module::TestMessage2.new(:foo…
796 assert_equal [1, 2, 3, 4, 5], m.repeated_msg.map {|x| x.foo}
800 m = proto_module::TestMessage.new(:optional_int32 => 42,
808 data = proto_module::TestMessage.encode m
810 assert_equal m, m2
812 data = Google::Protobuf.encode m
814 assert m == m2
818m = proto_module::TestMessage.new(:optional_string => 'foo', :repeated_string => ['bar1', 'bar2'])
819 assert_equal 'foo', m.optional_string
820 assert_equal ['bar1', 'bar2'], m.repeated_string
822 json = m.to_json
831 proto = m.to_proto
838m = proto_module::TestMessage.new(:optional_string => 'foo', :repeated_string => ['bar1', 'bar2'])
839 encoded_msg = Google::Protobuf.encode(m)
840 assert_equal m.to_proto, encoded_msg
843 assert_equal proto_module::TestMessage.decode(m.to_proto), decoded_msg
847m = proto_module::TestMessage.new(:optional_string => 'foo', :repeated_string => ['bar1', 'bar2'])
848 encoded_msg = Google::Protobuf.encode_json(m)
849 assert_equal m.to_json, encoded_msg
852 assert_equal proto_module::TestMessage.decode_json(m.to_json), decoded_msg
878m = proto_module::Recursive1.new(:foo => proto_module::Recursive2.new(:foo => proto_module::Recurs…
884 serialized = proto_module::Recursive1.encode(m)
886 assert m == m2
890 m = proto_module::Recursive1.new(:foo => proto_module::Recursive2.new)
891 m.foo.foo = m
893 proto_module::Recursive1.encode(m)
898 m = proto_module::BadFieldNames.new(:dup => 1, :class => 2)
899 m2 = m.dup
900 assert m == m2
901 assert m['dup'] == 1
902 assert m['class'] == 2
903 m['dup'] = 3
904 assert m['dup'] == 3
908 m = proto_module::TestMessage.new
910 m.optional_int32 = 0
911 m.optional_int32 = -0x8000_0000
912 m.optional_int32 = +0x7fff_ffff
913 m.optional_int32 = 1.0
914 m.optional_int32 = -1.0
915 m.optional_int32 = 2e9
917 m.optional_int32 = -0x8000_0001
920 m.optional_int32 = +0x8000_0000
923 m.optional_int32 = +0x1000_0000_0000_0000_0000_0000 # force Bignum
926 m.optional_int32 = 1e12
929 m.optional_int32 = 1.5
932 m.optional_uint32 = 0
933 m.optional_uint32 = +0xffff_ffff
934 m.optional_uint32 = 1.0
935 m.optional_uint32 = 4e9
937 m.optional_uint32 = -1
940 m.optional_uint32 = -1.5
943 m.optional_uint32 = -1.5e12
946 m.optional_uint32 = -0x1000_0000_0000_0000
949 m.optional_uint32 = +0x1_0000_0000
952 m.optional_uint32 = +0x1000_0000_0000_0000_0000_0000 # force Bignum
955 m.optional_uint32 = 1e12
958 m.optional_uint32 = 1.5
961 m.optional_int64 = 0
962 m.optional_int64 = -0x8000_0000_0000_0000
963 m.optional_int64 = +0x7fff_ffff_ffff_ffff
964 m.optional_int64 = 1.0
965 m.optional_int64 = -1.0
966 m.optional_int64 = 8e18
967 m.optional_int64 = -8e18
969 m.optional_int64 = -0x8000_0000_0000_0001
972 m.optional_int64 = +0x8000_0000_0000_0000
975 m.optional_int64 = +0x1000_0000_0000_0000_0000_0000 # force Bignum
978 m.optional_int64 = 1e50
981 m.optional_int64 = 1.5
984 m.optional_uint64 = 0
985 m.optional_uint64 = +0xffff_ffff_ffff_ffff
986 m.optional_uint64 = 1.0
987 m.optional_uint64 = 16e18
989 m.optional_uint64 = -1
992 m.optional_uint64 = -1.5
995 m.optional_uint64 = -1.5e12
998 m.optional_uint64 = -0x1_0000_0000_0000_0000
1001 m.optional_uint64 = +0x1_0000_0000_0000_0000
1004 m.optional_uint64 = +0x1000_0000_0000_0000_0000_0000 # force Bignum
1007 m.optional_uint64 = 1e50
1010 m.optional_uint64 = 1.5
1015 m = proto_module::TestMessage.new
1016 m.optional_int32 = 42
1017 m.optional_int64 = 0x100000000
1018 m.optional_string = "hello world"
1019 10.times do m.repeated_msg.push proto_module::TestMessage2.new(:foo => 42) end
1020 10.times do m.repeated_string.push "hello world" end
1022 data = proto_module::TestMessage.encode(m)
1025 m = proto_module::TestMessage.decode(data)
1026 data_new = proto_module::TestMessage.encode(m)
1033 m = proto_module::TestMessage.new(:optional_int32 => 1234)
1034 msgdef = m.class.descriptor
1042 optional_int32.set(m, 5678)
1043 assert m.optional_int32 == 5678
1044 m.optional_int32 = 1000
1045 assert optional_int32.get(m) == 1000
1050 optional_msg.set(m, optional_msg.subtype.msgclass.new)
1059 optional_enum.set(m, v)
1060 assert optional_enum.get(m) == k
1067 m = proto_module::TestMessage.new(:optional_int32 => 1234,
1083 json_text = proto_module::TestMessage.encode_json(m)
1085 assert_equal m, m2
1103 m = proto_module::TestMessage.new
1129 actual = proto_module::TestMessage.encode_json(m, :emit_defaults => true)
1137 m = proto_module::TestMessage.new(optional_msg: proto_module::TestMessage2.new)
1164 actual = proto_module::TestMessage.encode_json(m, :emit_defaults => true)
1172 m = proto_module::TestMessage.new(repeated_msg: [proto_module::TestMessage2.new])
1198 actual = proto_module::TestMessage.encode_json(m, :emit_defaults => true)
1269 run_asserts = ->(m) {
1270 assert_equal 0.0, m.double.value
1271 assert_equal 0.0, m.float.value
1272 assert_equal 0, m.int32.value
1273 assert_equal 0, m.int64.value
1274 assert_equal 0, m.uint32.value
1275 assert_equal 0, m.uint64.value
1276 assert_equal false, m.bool.value
1277 assert_equal '', m.string.value
1278 assert_equal '', m.bytes.value
1281 m = proto_module::Wrapper.new(
1293 run_asserts.call(m)
1294 m2 = proto_module::Wrapper.decode(m.to_proto)
1296 m3 = proto_module::Wrapper.decode_json(m.to_json)
1300 run_asserts = ->(m) {
1301 assert_equal 2.0, m.double_as_value
1302 assert_equal 2.0, m.double.value
1303 assert_equal 2.0, m.double_as_value
1305 assert_equal 4.0, m.float_as_value
1306 assert_equal 4.0, m.float.value
1307 assert_equal 4.0, m.float_as_value
1309 assert_equal 3, m.int32_as_value
1310 assert_equal 3, m.int32.value
1311 assert_equal 3, m.int32_as_value
1313 assert_equal 4, m.int64_as_value
1314 assert_equal 4, m.int64.value
1315 assert_equal 4, m.int64_as_value
1317 assert_equal 5, m.uint32_as_value
1318 assert_equal 5, m.uint32.value
1319 assert_equal 5, m.uint32_as_value
1321 assert_equal 6, m.uint64_as_value
1322 assert_equal 6, m.uint64.value
1323 assert_equal 6, m.uint64_as_value
1325 assert_equal true, m.bool_as_value
1326 assert_equal true, m.bool.value
1327 assert_equal true, m.bool_as_value
1329 assert_equal "st\nr", m.string_as_value
1330 assert_equal "st\nr", m.string.value
1331 assert_equal "st\nr", m.string_as_value
1333 assert_equal 'fun', m.bytes_as_value
1334 assert_equal 'fun', m.bytes.value
1335 assert_equal 'fun', m.bytes_as_value
1338 m = proto_module::Wrapper.new(
1351 run_asserts.call(m)
1352 serialized = proto_module::Wrapper::encode(m)
1365 assert_equal m5, m
1367 serialized_json = proto_module::Wrapper::encode_json(m)
1369 assert_equal m6, m
1373 run_asserts = ->(m) {
1374 assert_equal 2.0, m.repeated_double[0].value
1375 assert_equal 4.0, m.repeated_float[0].value
1376 assert_equal 3, m.repeated_int32[0].value
1377 assert_equal 4, m.repeated_int64[0].value
1378 assert_equal 5, m.repeated_uint32[0].value
1379 assert_equal 6, m.repeated_uint64[0].value
1380 assert_equal true, m.repeated_bool[0].value
1381 assert_equal 'str', m.repeated_string[0].value
1382 assert_equal 'fun', m.repeated_bytes[0].value
1385 m = proto_module::Wrapper.new(
1397 run_asserts.call(m)
1398 serialized = proto_module::Wrapper::encode(m)
1411 assert_equal m5, m
1417 assert_equal m6, m
1421 run_test = ->(m) {
1422 serialized = proto_module::Wrapper::encode(m)
1428 assert_equal m, m2
1431 serialized_json = proto_module::Wrapper::encode_json(m)
1433 assert_equal m, m3
1436 m = proto_module::Wrapper.new()
1438 run_test.call(m)
1439 m.oneof_double_as_value = 2.0
1440 run_test.call(m)
1441 m.oneof_float_as_value = 4.0
1442 run_test.call(m)
1443 m.oneof_int32_as_value = 3
1444 run_test.call(m)
1445 m.oneof_int64_as_value = 5
1446 run_test.call(m)
1447 m.oneof_uint32_as_value = 6
1448 run_test.call(m)
1449 m.oneof_uint64_as_value = 7
1450 run_test.call(m)
1451 m.oneof_string_as_value = 'str'
1452 run_test.call(m)
1453 m.oneof_bytes_as_value = 'fun'
1454 run_test.call(m)
1461 m = klass.new(value: val)
1462 serialized = klass::encode(m)
1468 assert_equal m, m2
1471 serialized_json = klass::encode_json(m)
1490 run_asserts = ->(m) {
1491 m.double_as_value = 4.8
1492 assert_equal 4.8, m.double_as_value
1493 assert_equal Google::Protobuf::DoubleValue.new(value: 4.8), m.double
1494 m.float_as_value = 2.4
1495 assert_in_delta 2.4, m.float_as_value
1496 assert_in_delta Google::Protobuf::FloatValue.new(value: 2.4).value, m.float.value
1497 m.int32_as_value = 5
1498 assert_equal 5, m.int32_as_value
1499 assert_equal Google::Protobuf::Int32Value.new(value: 5), m.int32
1500 m.int64_as_value = 15
1501 assert_equal 15, m.int64_as_value
1502 assert_equal Google::Protobuf::Int64Value.new(value: 15), m.int64
1503 m.uint32_as_value = 50
1504 assert_equal 50, m.uint32_as_value
1505 assert_equal Google::Protobuf::UInt32Value.new(value: 50), m.uint32
1506 m.uint64_as_value = 500
1507 assert_equal 500, m.uint64_as_value
1508 assert_equal Google::Protobuf::UInt64Value.new(value: 500), m.uint64
1509 m.bool_as_value = false
1510 assert_equal false, m.bool_as_value
1511 assert_equal Google::Protobuf::BoolValue.new(value: false), m.bool
1512 m.string_as_value = 'xy'
1513 assert_equal 'xy', m.string_as_value
1514 assert_equal Google::Protobuf::StringValue.new(value: 'xy'), m.string
1515 m.bytes_as_value = '123'
1516 assert_equal '123', m.bytes_as_value
1517 assert_equal Google::Protobuf::BytesValue.new(value: '123'), m.bytes
1519 m.double_as_value = nil
1520 assert_nil m.double
1521 assert_nil m.double_as_value
1522 m.float_as_value = nil
1523 assert_nil m.float
1524 assert_nil m.float_as_value
1525 m.int32_as_value = nil
1526 assert_nil m.int32
1527 assert_nil m.int32_as_value
1528 m.int64_as_value = nil
1529 assert_nil m.int64
1530 assert_nil m.int64_as_value
1531 m.uint32_as_value = nil
1532 assert_nil m.uint32
1533 assert_nil m.uint32_as_value
1534 m.uint64_as_value = nil
1535 assert_nil m.uint64
1536 assert_nil m.uint64_as_value
1537 m.bool_as_value = nil
1538 assert_nil m.bool
1539 assert_nil m.bool_as_value
1540 m.string_as_value = nil
1541 assert_nil m.string
1542 assert_nil m.string_as_value
1543 m.bytes_as_value = nil
1544 assert_nil m.bytes
1545 assert_nil m.bytes_as_value
1548 m = proto_module::Wrapper.new
1571 run_asserts = ->(m) {
1572 m.double = Google::Protobuf::DoubleValue.new(value: 4.8)
1573 assert_equal 4.8, m.double_as_value
1574 assert_equal Google::Protobuf::DoubleValue.new(value: 4.8), m.double
1575 m.float = Google::Protobuf::FloatValue.new(value: 2.4)
1576 assert_in_delta 2.4, m.float_as_value
1577 assert_in_delta Google::Protobuf::FloatValue.new(value: 2.4).value, m.float.value
1578 m.int32 = Google::Protobuf::Int32Value.new(value: 5)
1579 assert_equal 5, m.int32_as_value
1580 assert_equal Google::Protobuf::Int32Value.new(value: 5), m.int32
1581 m.int64 = Google::Protobuf::Int64Value.new(value: 15)
1582 assert_equal 15, m.int64_as_value
1583 assert_equal Google::Protobuf::Int64Value.new(value: 15), m.int64
1584 m.uint32 = Google::Protobuf::UInt32Value.new(value: 50)
1585 assert_equal 50, m.uint32_as_value
1586 assert_equal Google::Protobuf::UInt32Value.new(value: 50), m.uint32
1587 m.uint64 = Google::Protobuf::UInt64Value.new(value: 500)
1588 assert_equal 500, m.uint64_as_value
1589 assert_equal Google::Protobuf::UInt64Value.new(value: 500), m.uint64
1590 m.bool = Google::Protobuf::BoolValue.new(value: false)
1591 assert_equal false, m.bool_as_value
1592 assert_equal Google::Protobuf::BoolValue.new(value: false), m.bool
1593 m.string = Google::Protobuf::StringValue.new(value: 'xy')
1594 assert_equal 'xy', m.string_as_value
1595 assert_equal Google::Protobuf::StringValue.new(value: 'xy'), m.string
1596 m.bytes = Google::Protobuf::BytesValue.new(value: '123')
1597 assert_equal '123', m.bytes_as_value
1598 assert_equal Google::Protobuf::BytesValue.new(value: '123'), m.bytes
1600 m.double = nil
1601 assert_nil m.double
1602 assert_nil m.double_as_value
1603 m.float = nil
1604 assert_nil m.float
1605 assert_nil m.float_as_value
1606 m.int32 = nil
1607 assert_nil m.int32
1608 assert_nil m.int32_as_value
1609 m.int64 = nil
1610 assert_nil m.int64
1611 assert_nil m.int64_as_value
1612 m.uint32 = nil
1613 assert_nil m.uint32
1614 assert_nil m.uint32_as_value
1615 m.uint64 = nil
1616 assert_nil m.uint64
1617 assert_nil m.uint64_as_value
1618 m.bool = nil
1619 assert_nil m.bool
1620 assert_nil m.bool_as_value
1621 m.string = nil
1622 assert_nil m.string
1623 assert_nil m.string_as_value
1624 m.bytes = nil
1625 assert_nil m.bytes
1626 assert_nil m.bytes_as_value
1629 m = proto_module::Wrapper.new
1630 run_asserts.call(m)
1653 m = proto_module::Wrapper.new(real_string: 'hi', string_in_oneof: 'there')
1655 assert_raise(NoMethodError) { m.real_string_as_value }
1656 assert_raise(NoMethodError) { m.as_value }
1657 assert_raise(NoMethodError) { m._as_value }
1658 assert_raise(NoMethodError) { m.string_in_oneof_as_value }
1660 m = proto_module::Wrapper.new
1661 m.string_as_value = 'you'
1662 assert_equal 'you', m.string.value
1663 assert_equal 'you', m.string_as_value
1664 assert_raise(NoMethodError) { m.string_ }
1665 assert_raise(NoMethodError) { m.string_X }
1666 assert_raise(NoMethodError) { m.string_XX }
1667 assert_raise(NoMethodError) { m.string_XXX }
1668 assert_raise(NoMethodError) { m.string_XXXX }
1669 assert_raise(NoMethodError) { m.string_XXXXX }
1670 assert_raise(NoMethodError) { m.string_XXXXXX }
1671 assert_raise(NoMethodError) { m.string_XXXXXXX }
1672 assert_raise(NoMethodError) { m.string_XXXXXXXX }
1673 assert_raise(NoMethodError) { m.string_XXXXXXXXX }
1674 assert_raise(NoMethodError) { m.string_XXXXXXXXXX }
1678 m = proto_module::TimeMessage.new
1680 m.timestamp = Google::Protobuf::Timestamp.new(seconds: 5, nanos: 6)
1681 assert_kind_of Google::Protobuf::Timestamp, m.timestamp
1682 assert_equal 5, m.timestamp.seconds
1683 assert_equal 6, m.timestamp.nanos
1685 m.timestamp = Time.at(9466, 123456.789)
1686 assert_equal Google::Protobuf::Timestamp.new(seconds: 9466, nanos: 123456789), m.timestamp
1688 m = proto_module::TimeMessage.new(timestamp: Time.at(1))
1689 assert_equal Google::Protobuf::Timestamp.new(seconds: 1, nanos: 0), m.timestamp
1691 assert_raise(Google::Protobuf::TypeError) { m.timestamp = 2 }
1692 assert_raise(Google::Protobuf::TypeError) { m.timestamp = 2.4 }
1693 assert_raise(Google::Protobuf::TypeError) { m.timestamp = '4' }
1694 assert_raise(Google::Protobuf::TypeError) { m.timestamp = proto_module::TimeMessage.new }
1710 m = proto_module::TimeMessage.new
1712 m.duration = Google::Protobuf::Duration.new(seconds: 2, nanos: 22)
1713 assert_kind_of Google::Protobuf::Duration, m.duration
1714 assert_equal 2, m.duration.seconds
1715 assert_equal 22, m.duration.nanos
1717 m.duration = 10.5
1718 assert_equal Google::Protobuf::Duration.new(seconds: 10, nanos: 500_000_000), m.duration
1720 m.duration = 200
1721 assert_equal Google::Protobuf::Duration.new(seconds: 200, nanos: 0), m.duration
1723 m.duration = Rational(3, 2)
1724 assert_equal Google::Protobuf::Duration.new(seconds: 1, nanos: 500_000_000), m.duration
1726 m.duration = BigDecimal("5")
1727 assert_equal Google::Protobuf::Duration.new(seconds: 5, nanos: 0), m.duration
1729 m = proto_module::TimeMessage.new(duration: 1.1)
1730 assert_equal Google::Protobuf::Duration.new(seconds: 1, nanos: 100_000_000), m.duration
1732 assert_raise(Google::Protobuf::TypeError) { m.duration = '2' }
1733 assert_raise(Google::Protobuf::TypeError) { m.duration = proto_module::TimeMessage.new }
1737 m = proto_module::TestMessage.new
1738 m.optional_int32 = 10
1739 m.freeze
1741 frozen_error = assert_raise(FrozenErrorType) { m.optional_int32 = 20 }
1743 assert_equal 10, m.optional_int32
1744 assert_equal true, m.frozen?
1746 assert_raise(FrozenErrorType) { m.optional_int64 = 2 }
1747 assert_raise(FrozenErrorType) { m.optional_uint32 = 3 }
1748 assert_raise(FrozenErrorType) { m.optional_uint64 = 4 }
1749 assert_raise(FrozenErrorType) { m.optional_bool = true }
1750 assert_raise(FrozenErrorType) { m.optional_float = 6.0 }
1751 assert_raise(FrozenErrorType) { m.optional_double = 7.0 }
1752 assert_raise(FrozenErrorType) { m.optional_string = '8' }
1753 assert_raise(FrozenErrorType) { m.optional_bytes = nil }
1754 assert_raise(FrozenErrorType) { m.optional_msg = proto_module::TestMessage2.new }
1755 assert_raise(FrozenErrorType) { m.optional_enum = :A }
1756 assert_raise(FrozenErrorType) { m.repeated_int32 = 1 }
1757 assert_raise(FrozenErrorType) { m.repeated_int64 = 2 }
1758 assert_raise(FrozenErrorType) { m.repeated_uint32 = 3 }
1759 assert_raise(FrozenErrorType) { m.repeated_uint64 = 4 }
1760 assert_raise(FrozenErrorType) { m.repeated_bool = true }
1761 assert_raise(FrozenErrorType) { m.repeated_float = 6.0 }
1762 assert_raise(FrozenErrorType) { m.repeated_double = 7.0 }
1763 assert_raise(FrozenErrorType) { m.repeated_string = '8' }
1764 assert_raise(FrozenErrorType) { m.repeated_bytes = nil }
1765 assert_raise(FrozenErrorType) { m.repeated_msg = proto_module::TestMessage2.new }
1766 assert_raise(FrozenErrorType) { m.repeated_enum = :A }