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

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

Issue 2590803003: Revert "third_party/protobuf: Update to HEAD (83d681ee2c)" (Closed)
Patch Set: Created 4 years 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 e0dba8bddeddef862fa954f853d15f24c4b60c35..77c186ef3516fb09bb9e9aafe5168a7dc7c4b9e5 100644
--- a/third_party/protobuf/ruby/tests/basic.rb
+++ b/third_party/protobuf/ruby/tests/basic.rb
@@ -183,15 +183,12 @@ module BasicTest
def test_hash
m1 = TestMessage.new(:optional_int32 => 42)
- m2 = TestMessage.new(:optional_int32 => 102, repeated_string: ['please', 'work', 'ok?'])
- m3 = TestMessage.new(:optional_int32 => 102, repeated_string: ['please', 'work', 'ok?'])
+ m2 = TestMessage.new(:optional_int32 => 102)
assert m1.hash != 0
assert m2.hash != 0
- assert m3.hash != 0
# relying on the randomness here -- if hash function changes and we are
# unlucky enough to get a collision, then change the values above.
assert m1.hash != m2.hash
- assert_equal m2.hash, m3.hash
end
def test_unknown_field_errors
@@ -258,17 +255,14 @@ module BasicTest
m = TestMessage.new
# Assigning a normal (ASCII or UTF8) string to a bytes field, or
- # ASCII-8BIT to a string field will convert to the proper encoding.
- m.optional_bytes = "Test string ASCII".encode!('ASCII')
- assert m.optional_bytes.frozen?
- assert_equal Encoding::ASCII_8BIT, m.optional_bytes.encoding
- assert_equal "Test string ASCII", m.optional_bytes
-
- assert_raise Encoding::UndefinedConversionError do
+ # ASCII-8BIT to a string field, raises an error.
+ assert_raise TypeError do
+ m.optional_bytes = "Test string ASCII".encode!('ASCII')
+ end
+ assert_raise TypeError do
m.optional_bytes = "Test string UTF-8 \u0100".encode!('UTF-8')
end
-
- assert_raise Encoding::UndefinedConversionError do
+ assert_raise TypeError do
m.optional_string = ["FFFF"].pack('H*')
end
@@ -276,10 +270,11 @@ module BasicTest
m.optional_bytes = ["FFFF"].pack('H*')
m.optional_string = "\u0100"
- # strings are immutable so we can't do this, but serialize should catch it.
+ # strings are mutable so we can do this, but serialize should catch it.
m.optional_string = "asdf".encode!('UTF-8')
- assert_raise RuntimeError do
- m.optional_string.encode!('ASCII-8BIT')
+ m.optional_string.encode!('ASCII-8BIT')
+ assert_raise TypeError do
+ data = TestMessage.encode(m)
end
end
@@ -471,9 +466,9 @@ module BasicTest
assert m.length == 2
m2 = m.dup
- assert_equal m, m2
+ assert m == m2
assert m.hash != 0
- assert_equal m.hash, m2.hash
+ assert m.hash == m2.hash
collected = {}
m.each { |k,v| collected[v] = k }
@@ -563,7 +558,7 @@ module BasicTest
assert_raise TypeError do
m[1] = 1
end
- assert_raise Encoding::UndefinedConversionError do
+ assert_raise TypeError do
bytestring = ["FFFF"].pack("H*")
m[bytestring] = 1
end
@@ -571,8 +566,9 @@ module BasicTest
m = Google::Protobuf::Map.new(:bytes, :int32)
bytestring = ["FFFF"].pack("H*")
m[bytestring] = 1
- # Allowed -- we will automatically convert to ASCII-8BIT.
- m["asdf"] = 1
+ assert_raise TypeError do
+ m["asdf"] = 1
+ end
assert_raise TypeError do
m[1] = 1
end
@@ -707,36 +703,36 @@ module BasicTest
def test_oneof
d = OneofMessage.new
- assert d.a == ""
- assert d.b == 0
+ assert d.a == nil
+ assert d.b == nil
assert d.c == nil
- assert d.d == :Default
+ assert d.d == nil
assert d.my_oneof == nil
d.a = "hi"
assert d.a == "hi"
- assert d.b == 0
+ assert d.b == nil
assert d.c == nil
- assert d.d == :Default
+ assert d.d == nil
assert d.my_oneof == :a
d.b = 42
- assert d.a == ""
+ assert d.a == nil
assert d.b == 42
assert d.c == nil
- assert d.d == :Default
+ assert d.d == nil
assert d.my_oneof == :b
d.c = TestMessage2.new(:foo => 100)
- assert d.a == ""
- assert d.b == 0
+ assert d.a == nil
+ assert d.b == nil
assert d.c.foo == 100
- assert d.d == :Default
+ assert d.d == nil
assert d.my_oneof == :c
d.d = :C
- assert d.a == ""
- assert d.b == 0
+ assert d.a == nil
+ assert d.b == nil
assert d.c == nil
assert d.d == :C
assert d.my_oneof == :d
@@ -752,23 +748,23 @@ module BasicTest
d3 = OneofMessage.decode(
encoded_field_c + encoded_field_a + encoded_field_d)
- assert d3.a == ""
- assert d3.b == 0
+ assert d3.a == nil
+ assert d3.b == nil
assert d3.c == nil
assert d3.d == :B
d4 = OneofMessage.decode(
encoded_field_c + encoded_field_a + encoded_field_d +
encoded_field_c)
- assert d4.a == ""
- assert d4.b == 0
+ assert d4.a == nil
+ assert d4.b == nil
assert d4.c.foo == 1
- assert d4.d == :Default
+ assert d4.d == nil
d5 = OneofMessage.new(:a => "hello")
- assert d5.a == "hello"
+ assert d5.a != nil
d5.a = nil
- assert d5.a == ""
+ assert d5.a == nil
assert OneofMessage.encode(d5) == ''
assert d5.my_oneof == nil
end
@@ -857,22 +853,15 @@ module BasicTest
def test_encode_decode_helpers
m = TestMessage.new(:optional_string => 'foo', :repeated_string => ['bar1', 'bar2'])
- assert_equal 'foo', m.optional_string
- assert_equal ['bar1', 'bar2'], m.repeated_string
-
json = m.to_json
m2 = TestMessage.decode_json(json)
- assert_equal 'foo', m2.optional_string
- assert_equal ['bar1', 'bar2'], m2.repeated_string
- if RUBY_PLATFORM != "java"
- assert m2.optional_string.frozen?
- assert m2.repeated_string[0].frozen?
- end
+ assert m2.optional_string == 'foo'
+ assert m2.repeated_string == ['bar1', 'bar2']
proto = m.to_proto
m2 = TestMessage.decode(proto)
- assert_equal 'foo', m2.optional_string
- assert_equal ['bar1', 'bar2'], m2.repeated_string
+ assert m2.optional_string == 'foo'
+ assert m2.repeated_string == ['bar1', 'bar2']
end
def test_protobuf_encode_decode_helpers
@@ -1181,17 +1170,5 @@ module BasicTest
m2 = MapMessage.decode_json(MapMessage.encode_json(m))
assert m == m2
end
-
- def test_comparison_with_arbitrary_object
- assert MapMessage.new != nil
- end
-
- def test_respond_to
- # This test fails with JRuby 1.7.23, likely because of an old JRuby bug.
- return if RUBY_PLATFORM == "java"
- msg = MapMessage.new
- assert msg.respond_to?(:map_string_int32)
- assert !msg.respond_to?(:bacon)
- end
end
end

Powered by Google App Engine
This is Rietveld 408576698