|
|
|
@ -8,13 +8,16 @@ require 'google/protobuf/well_known_types' |
|
|
|
|
require 'generated_code_pb' |
|
|
|
|
|
|
|
|
|
class TestTypeErrors < Test::Unit::TestCase |
|
|
|
|
# Ruby 2.4 unified Fixnum with Integer |
|
|
|
|
IntegerType = Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.4') ? Fixnum : Integer |
|
|
|
|
|
|
|
|
|
def test_bad_string |
|
|
|
|
check_error Google::Protobuf::TypeError, |
|
|
|
|
"Invalid argument for string field 'optional_string' (given Integer)." do |
|
|
|
|
"Invalid argument for string field 'optional_string' (given #{IntegerType.name})." do |
|
|
|
|
A::B::C::TestMessage.new(optional_string: 4) |
|
|
|
|
end |
|
|
|
|
check_error Google::Protobuf::TypeError, |
|
|
|
|
"Invalid argument for string field 'oneof_string' (given Integer)." do |
|
|
|
|
"Invalid argument for string field 'oneof_string' (given #{IntegerType.name})." do |
|
|
|
|
A::B::C::TestMessage.new(oneof_string: 4) |
|
|
|
|
end |
|
|
|
|
check_error ArgumentError, |
|
|
|
@ -151,7 +154,7 @@ class TestTypeErrors < Test::Unit::TestCase |
|
|
|
|
|
|
|
|
|
def test_bad_msg |
|
|
|
|
check_error Google::Protobuf::TypeError, |
|
|
|
|
"Invalid type Integer to assign to submessage field 'optional_msg'." do |
|
|
|
|
"Invalid type #{IntegerType.name} to assign to submessage field 'optional_msg'." do |
|
|
|
|
A::B::C::TestMessage.new(optional_msg: 2) |
|
|
|
|
end |
|
|
|
|
check_error Google::Protobuf::TypeError, |
|
|
|
|