Sha256: 16d58da82eedf55123d730cdce96689e0c73129128efd5a0ef4a623d4d26c3f3

Contents?: true

Size: 1.6 KB

Versions: 10

Compression:

Stored size: 1.6 KB

Contents

# encoding: binary

require 'spec_helper'
require 'protobuf/code_generator'

RSpec.describe 'code generation' do
  it "generates code for google's unittest.proto" do
    bytes = IO.read(PROTOS_PATH.join('google_unittest.bin'), :mode => 'rb')

    expected_files =
      ["google_unittest_import_public.pb.rb", "google_unittest_import.pb.rb", "google_unittest.pb.rb"]

    expected_file_descriptors = expected_files.map do |file_name|
      file_content = File.open(PROTOS_PATH.join(file_name), "r:UTF-8", &:read)
      ::Google::Protobuf::Compiler::CodeGeneratorResponse::File.new(
        :name => "protos/" + file_name, :content => file_content)
    end

    expected_output =
      ::Google::Protobuf::Compiler::CodeGeneratorResponse.encode(:file => expected_file_descriptors)

    code_generator = ::Protobuf::CodeGenerator.new(bytes)
    code_generator.eval_unknown_extensions!
    expect(code_generator.response_bytes).to eq(expected_output)
  end

  it "generates code (including service stubs) with custom field and method options" do
    expected_unittest_custom_options =
      File.open(PROTOS_PATH.join('google_unittest_custom_options.pb.rb'), "r:UTF-8", &:read)

    bytes = IO.read(PROTOS_PATH.join('google_unittest_custom_options.bin'), :mode => 'rb')
    code_generator = ::Protobuf::CodeGenerator.new(bytes)
    code_generator.eval_unknown_extensions!
    response = ::Google::Protobuf::Compiler::CodeGeneratorResponse.decode(code_generator.response_bytes)
    expect(response.file.find { |f| f.name == 'protos/google_unittest_custom_options.pb.rb' }.content)
      .to eq(expected_unittest_custom_options)
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
protobuf-3.7.5 spec/functional/code_generator_spec.rb
protobuf-3.7.4 spec/functional/code_generator_spec.rb
protobuf-3.7.3 spec/functional/code_generator_spec.rb
protobuf-3.7.2 spec/functional/code_generator_spec.rb
protobuf-3.7.2.pre1 spec/functional/code_generator_spec.rb
protobuffy-4.0.1 spec/functional/code_generator_spec.rb
protobuf-3.7.1 spec/functional/code_generator_spec.rb
protobuf-3.7.0 spec/functional/code_generator_spec.rb
protobuf-3.7.0.pre3 spec/functional/code_generator_spec.rb
protobuffy-4.0.0 spec/functional/code_generator_spec.rb