aboutsummaryrefslogtreecommitdiffhomepage
path: root/ruby/tests
diff options
context:
space:
mode:
authorGravatar parker <parker@shundaojia.com>2017-11-06 12:18:12 +0800
committerGravatar parker <parker@shundaojia.com>2017-11-17 11:43:14 +0800
commit8695997eb5adb3c504c3615f0e6f3891a9b7ebde (patch)
tree21890635a98c360ce0465aeeb1e41a4f27a1277c /ruby/tests
parentbcda919ceeae8bd854c07a8300d8996ef52315db (diff)
Google::Protobuf::Struct can access a missing key (#3846)
Diffstat (limited to 'ruby/tests')
-rw-r--r--ruby/tests/well_known_types_test.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/ruby/tests/well_known_types_test.rb b/ruby/tests/well_known_types_test.rb
index bd24c328..3ce659a6 100644
--- a/ruby/tests/well_known_types_test.rb
+++ b/ruby/tests/well_known_types_test.rb
@@ -60,6 +60,9 @@ class TestWellKnownTypes < Test::Unit::TestCase
assert_equal(Google::Protobuf::ListValue.from_a(sublist),
struct["sublist"])
+ assert_equal true, struct.has_key?("null")
+ assert_equal false, struct.has_key?("missing_key")
+
should_equal = {
"number" => 12345,
"boolean-true" => true,
@@ -82,6 +85,9 @@ class TestWellKnownTypes < Test::Unit::TestCase
# to_h returns a fully-flattened Ruby structure (Hash and Array).
assert_equal(should_equal, struct.to_h)
+ # Test that we can safely access a missing key
+ assert_equal(nil, struct["missing_key"])
+
# Test that we can assign Struct and ListValue directly.
struct["substruct"] = Google::Protobuf::Struct.from_hash(substruct)
struct["sublist"] = Google::Protobuf::ListValue.from_a(sublist)