Sha256: c5974748eb414816ee6b5ada835027d3ebf62fa52c7793fc24d90ebc6c3dff03

Contents?: true

Size: 1.38 KB

Versions: 11

Compression:

Stored size: 1.38 KB

Contents

require 'spec_helper'

require 'protobuf/generators/enum_generator'

describe ::Protobuf::Generators::EnumGenerator do

  let(:values) {
    [
      { :name => 'FOO', :number => 1 },
      { :name => 'BAR', :number => 2 },
      { :name => 'BAZ', :number => 3 }
    ]
  }
  let(:options) { nil }
  let(:enum_fields) { { :name => 'TestEnum',
                        :value => values,
                        :options => options } }

  let(:enum) { ::Google::Protobuf::EnumDescriptorProto.new(enum_fields) }

  subject { described_class.new(enum) }

  describe '#compile' do
    let(:compiled) {
      %q{class TestEnum < ::Protobuf::Enum
  define :FOO, 1
  define :BAR, 2
  define :BAZ, 3
end

}
    }

    it 'compiles the enum and it\'s field values' do
      subject.compile
      expect(subject.to_s).to eq(compiled)
    end

    context 'when allow_alias option is set' do
      let(:compiled) {
        %q{class TestEnum < ::Protobuf::Enum
  set_option :allow_alias

  define :FOO, 1
  define :BAR, 2
  define :BAZ, 3
end

}
    }

      let(:options) { { :allow_alias => true } }

      it 'sets the allow_alias option' do
        subject.compile
        expect(subject.to_s).to eq(compiled)
      end
    end
  end

  describe '#build_value' do
    it 'returns a string identifying the given enum value' do
      expect(subject.build_value(enum.value.first)).to eq("define :FOO, 1")
    end
  end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
protobuf-3.3.6 spec/lib/protobuf/generators/enum_generator_spec.rb
protobuf-3.3.5 spec/lib/protobuf/generators/enum_generator_spec.rb
protobuf-3.3.4 spec/lib/protobuf/generators/enum_generator_spec.rb
protobuf-3.3.3 spec/lib/protobuf/generators/enum_generator_spec.rb
protobuf-3.3.2 spec/lib/protobuf/generators/enum_generator_spec.rb
protobuf-3.3.1 spec/lib/protobuf/generators/enum_generator_spec.rb
protobuf-3.3.0 spec/lib/protobuf/generators/enum_generator_spec.rb
protobuf-3.2.1 spec/lib/protobuf/generators/enum_generator_spec.rb
protobuf-3.2.0 spec/lib/protobuf/generators/enum_generator_spec.rb
protobuf-3.1.0 spec/lib/protobuf/generators/enum_generator_spec.rb
protobuf-3.0.5 spec/lib/protobuf/generators/enum_generator_spec.rb