Sha256: 856b336ef90429b04f3128aafa22178b879113eceba8086a5d1acce6a446ce5f

Contents?: true

Size: 1.05 KB

Versions: 4

Compression:

Stored size: 1.05 KB

Contents

require 'spec_helper'

RSpec.describe Protobuf::Field::Int64Field do

  it_behaves_like :packable_field, described_class

  let(:message) do
    Class.new(::Protobuf::Message) do
      optional :int64, :some_field, 1
    end
  end

  # https://developers.google.com/protocol-buffers/docs/proto3#json
  describe '.{to_json, from_json}' do
    it 'serialises 0' do
      instance = message.new(some_field: 0)
      expect(instance.to_json(proto3: true)).to eq('{}')
      expect(instance.to_json).to eq('{"some_field":0}')
    end

    it 'serialises max value' do
      instance = message.new(some_field: described_class.max)
      expect(instance.to_json(proto3: true)).to eq('{"someField":"9223372036854775807"}')
      expect(instance.to_json).to eq('{"some_field":9223372036854775807}')
    end

    it 'serialises min value' do
      instance = message.new(some_field: described_class.min)
      expect(instance.to_json(proto3: true)).to eq('{"someField":"-9223372036854775808"}')
      expect(instance.to_json).to eq('{"some_field":-9223372036854775808}')
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
protobuf-cucumber-3.10.8 spec/lib/protobuf/field/int64_field_spec.rb
protobuf-cucumber-3.10.7 spec/lib/protobuf/field/int64_field_spec.rb
protobuf-cucumber-3.10.6 spec/lib/protobuf/field/int64_field_spec.rb
protobuf-cucumber-3.10.5 spec/lib/protobuf/field/int64_field_spec.rb