Sha256: 3c558fb8c72b93c9df6549527e6dbf6a3f83aace7800ff4a4b6abdea3d320b9b

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

require 'test/unit'
require 'protobuf/message/message'
require 'protobuf/message/enum'
require 'test/proto/addressbook.pb'
require 'test/proto/addressbook_base.pb'

class EnumValueTest < Test::Unit::TestCase
  def test_enum_value
    e = Protobuf::EnumValue.new(Object, :name, 100)
    assert_kind_of(Protobuf::EnumValue, e)
    assert_equal(:name, e.name)
    assert_equal(100, e.value)
    assert_equal('name', e.to_s)
    assert_equal('name', "#{e}")
    assert(e == 100)
    assert(100 == e)
    assert(101, e + 1)
    assert(101, 1 + e)
  end

  def test_enum_field_and_enum_value
    phone_number = Tutorial::Person::PhoneNumber.new

    assert_kind_of(Protobuf::EnumValue, phone_number.type)
    assert_equal(Tutorial::Person::PhoneType::HOME, phone_number.type)

    phone_number.type = 1
    assert_kind_of(Protobuf::EnumValue, phone_number.type)
    assert_equal(Tutorial::Person::PhoneType::HOME, phone_number.type)
    assert_equal(1, phone_number.type)

    phone_number.type = :HOME
    assert_equal(Tutorial::Person::PhoneType::HOME, phone_number.type)

    phone_number.type = 'HOME'
    assert_equal(Tutorial::Person::PhoneType::HOME, phone_number.type)

    assert_raise(TypeError) do
      phone_number.type = TutorialExt::Person::PhoneType::HOME
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby_protobuf-0.4.6 test/test_enum_value.rb