Sha256: 5e7dcd5c3669276ba93058029da152270da96d912e79c928ba9036cdb0e1a1ba

Contents?: true

Size: 1.46 KB

Versions: 7

Compression:

Stored size: 1.46 KB

Contents

require 'spec_helper'
require 'ffi/msgpack/unpacker'

require 'stringio'

describe MsgPack::Unpacker do
  before(:all) do
    @packed = "\x01\x02\x03"
  end

  before(:each) do
    @unpacker = MsgPack::Unpacker.create(1024)
  end

  describe "buffer" do
    it "should enqueue data into the buffer" do
      size1 = @unpacker[:used]
      @unpacker << @packed
      size2 = @unpacker[:used]

      (size2 - size1).should == @packed.length
    end

    it "should enqueue data from IO objects into the buffer" do
      io = StringIO.new(@packed)

      size1 = @unpacker[:used]
      @unpacker.read(io).should == true
      size2 = @unpacker[:used]

      (size2 - size1).should == @packed.length
    end
  end

  describe "each_object" do
    it "should unpack each Msg Object from the buffer" do
      objs = []
      expected = [
        [:positive_integer, 1],
        [:positive_integer, 2],
        [:positive_integer, 3]
      ]

      @unpacker << @packed
      @unpacker.each_object do |obj|
        objs << [obj.type, obj.values[:u64]]
      end

      objs.should == expected
    end

    it "should unpack each Msg Object from a stream" do
      io = StringIO.new(@packed)
      objs = []
      expected = [
        [:positive_integer, 1],
        [:positive_integer, 2],
        [:positive_integer, 3]
      ]

      @unpacker.stream = io
      @unpacker.each_object do |obj|
        objs << [obj.type, obj.values[:u64]]
      end

      objs.should == expected
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ffi-msgpack-0.2.1 spec/unpacker_spec.rb
ffi-msgpack-0.2.0 spec/unpacker_spec.rb
ffi-msgpack-0.1.4 spec/unpacker_spec.rb
ffi-msgpack-0.1.3 spec/unpacker_spec.rb
ffi-msgpack-0.1.2 spec/unpacker_spec.rb
ffi-msgpack-0.1.1 spec/unpacker_spec.rb
ffi-msgpack-0.1.0 spec/unpacker_spec.rb