Fixed: incorrect tests

pull/8254/head
Joel Courtney 3 years ago
parent 947a51a464
commit 4d94a7cd93
  1. 4
      ruby/lib/google/protobuf/well_known_types.rb
  2. 16
      ruby/tests/well_known_types_test.rb

@ -138,13 +138,13 @@ module Google
end
def self.from_ruby(value)
Value.new.from_ruby(value)
self.new.from_ruby(value)
end
def from_ruby(value)
case value
when NilClass
self.null_value = 0
self.null_value = :NULL_VALUE
when Numeric
self.number_value = value
when String

@ -1,7 +1,7 @@
#!/usr/bin/ruby
require 'test/unit'
require 'google/protobuf/well_known_types'
require 'lib/google/protobuf/well_known_types'
class TestWellKnownTypes < Test::Unit::TestCase
def test_timestamp
@ -218,7 +218,7 @@ class TestWellKnownTypes < Test::Unit::TestCase
def test_from_ruby
pb = Google::Protobuf::Value.from_ruby(nil)
assert_equal pb.null_value, 0
assert_equal pb.null_value, :NULL_VALUE
pb = Google::Protobuf::Value.from_ruby(1.23)
assert_equal pb.number_value, 1.23
@ -232,16 +232,16 @@ class TestWellKnownTypes < Test::Unit::TestCase
pb = Google::Protobuf::Value.from_ruby(false)
assert_equal pb.bool_value, false
pb = Google::Protobuf::Value.from_ruby(Google::Protobuf::Struct.from_hash({ a: 1, b: '2', c: [1, 2, 3] }))
assert_equal pb.struct_value, Google::Protobuf::Struct.from_hash({ a: 1, b: '2', c: [1, 2, 3] })
pb = Google::Protobuf::Value.from_ruby(Google::Protobuf::Struct.from_hash({ 'a' => 1, 'b' => '2', 'c' => [1, 2, 3], 'd' => nil, 'e' => true }))
assert_equal pb.struct_value, Google::Protobuf::Struct.from_hash({ 'a' => 1, 'b' => '2', 'c' => [1, 2, 3], 'd' => nil, 'e' => true })
pb = Google::Protobuf::Value.from_ruby({ a: 1, b: '2', c: [1, 2, 3] })
assert_equal pb.struct_value, Google::Protobuf::Struct.from_hash({ a: 1, b: '2', c: [1, 2, 3] })
pb = Google::Protobuf::Value.from_ruby({ 'a' => 1, 'b' => '2', 'c' => [1, 2, 3], 'd' => nil, 'e' => true })
assert_equal pb.struct_value, Google::Protobuf::Struct.from_hash({ 'a' => 1, 'b' => '2', 'c' => [1, 2, 3], 'd' => nil, 'e' => true })
pb = Google::Protobuf::Value.from_ruby(Google::Protobuf::ListValue.from_a([1, 2, 3]))
assert_equal pb.struct_value, Google::Protobuf::ListValue.from_a([1, 2, 3])
assert_equal pb.list_value, Google::Protobuf::ListValue.from_a([1, 2, 3])
pb = Google::Protobuf::Value.from_ruby([1, 2, 3])
assert_equal pb.struct_value, Google::Protobuf::ListValue.from_a([1, 2, 3])
assert_equal pb.list_value, Google::Protobuf::ListValue.from_a([1, 2, 3])
end
end

Loading…
Cancel
Save