Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Unified Diff: third_party/protobuf/ruby/tests/basic.rb

Issue 1983203003: Update third_party/protobuf to protobuf-v3.0.0-beta-3 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: owners Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/protobuf/ruby/tests/basic.rb
diff --git a/third_party/protobuf/ruby/tests/basic.rb b/third_party/protobuf/ruby/tests/basic.rb
index 40c200786beb7526bee5f1b79cef9b3e957b915d..77c186ef3516fb09bb9e9aafe5168a7dc7c4b9e5 100644
--- a/third_party/protobuf/ruby/tests/basic.rb
+++ b/third_party/protobuf/ruby/tests/basic.rb
@@ -191,6 +191,35 @@ module BasicTest
assert m1.hash != m2.hash
end
+ def test_unknown_field_errors
+ e = assert_raise NoMethodError do
+ TestMessage.new.hello
+ end
+ assert_match(/hello/, e.message)
+
+ e = assert_raise NoMethodError do
+ TestMessage.new.hello = "world"
+ end
+ assert_match(/hello/, e.message)
+ end
+
+ def test_initialization_map_errors
+ e = assert_raise ArgumentError do
+ TestMessage.new(:hello => "world")
+ end
+ assert_match(/hello/, e.message)
+
+ e = assert_raise ArgumentError do
+ MapMessage.new(:map_string_int32 => "hello")
+ end
+ assert_equal e.message, "Expected Hash object as initializer value for map field 'map_string_int32'."
+
+ e = assert_raise ArgumentError do
+ TestMessage.new(:repeated_uint32 => "hello")
+ end
+ assert_equal e.message, "Expected array as initializer value for repeated field 'repeated_uint32'."
+ end
+
def test_type_errors
m = TestMessage.new
assert_raise TypeError do
@@ -1131,8 +1160,13 @@ module BasicTest
# TODO: Fix JSON in JRuby version.
return if RUBY_PLATFORM == "java"
m = MapMessage.new(:map_string_int32 => {"a" => 1})
- expected = '{"map_string_int32":{"a":1},"map_string_msg":{}}'
+ expected = '{"mapStringInt32":{"a":1},"mapStringMsg":{}}'
+ expected_preserve = '{"map_string_int32":{"a":1},"map_string_msg":{}}'
assert MapMessage.encode_json(m) == expected
+
+ json = MapMessage.encode_json(m, :preserve_proto_fieldnames => true)
+ assert json == expected_preserve
+
m2 = MapMessage.decode_json(MapMessage.encode_json(m))
assert m == m2
end
« no previous file with comments | « third_party/protobuf/ruby/src/main/sentinel.proto ('k') | third_party/protobuf/ruby/tests/generated_code.rb » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698