1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
# encoding: ascii-8bit
require 'spec/spec_helper'
require 'stringio'
if defined?(Encoding)
Encoding.default_external = 'ASCII-8BIT'
end
describe MessagePack do
it 'MessagePack.unpack symbolize_keys' do
symbolized_hash = {:a => 'b', :c => 'd'}
MessagePack.load(MessagePack.pack(symbolized_hash), :symbolize_keys => true).should == symbolized_hash
MessagePack.unpack(MessagePack.pack(symbolized_hash), :symbolize_keys => true).should == symbolized_hash
end
it 'Unpacker#read symbolize_keys' do
unpacker = MessagePack::Unpacker.new(:symbolize_keys => true)
symbolized_hash = {:a => 'b', :c => 'd'}
unpacker.feed(MessagePack.pack(symbolized_hash)).read.should == symbolized_hash
end
it "msgpack str 8 type" do
MessagePack.unpack([0xd9, 0x00].pack('C*')).should == ""
MessagePack.unpack([0xd9, 0x01].pack('C*') + 'a').should == "a"
MessagePack.unpack([0xd9, 0x02].pack('C*') + 'aa').should == "aa"
end
it "msgpack str 16 type" do
MessagePack.unpack([0xda, 0x00, 0x00].pack('C*')).should == ""
MessagePack.unpack([0xda, 0x00, 0x01].pack('C*') + 'a').should == "a"
MessagePack.unpack([0xda, 0x00, 0x02].pack('C*') + 'aa').should == "aa"
end
it "msgpack str 32 type" do
MessagePack.unpack([0xdb, 0x00, 0x00, 0x00, 0x00].pack('C*')).should == ""
MessagePack.unpack([0xdb, 0x00, 0x00, 0x00, 0x01].pack('C*') + 'a').should == "a"
MessagePack.unpack([0xdb, 0x00, 0x00, 0x00, 0x02].pack('C*') + 'aa').should == "aa"
end
it "msgpack bin 8 type" do
MessagePack.unpack([0xc4, 0x00].pack('C*')).should == ""
MessagePack.unpack([0xc4, 0x01].pack('C*') + 'a').should == "a"
MessagePack.unpack([0xc4, 0x02].pack('C*') + 'aa').should == "aa"
end
it "msgpack bin 16 type" do
MessagePack.unpack([0xc5, 0x00, 0x00].pack('C*')).should == ""
MessagePack.unpack([0xc5, 0x00, 0x01].pack('C*') + 'a').should == "a"
MessagePack.unpack([0xc5, 0x00, 0x02].pack('C*') + 'aa').should == "aa"
end
it "msgpack bin 32 type" do
MessagePack.unpack([0xc6, 0x00, 0x00, 0x00, 0x00].pack('C*')).should == ""
MessagePack.unpack([0xc6, 0x00, 0x00, 0x00, 0x01].pack('C*') + 'a').should == "a"
MessagePack.unpack([0xc6, 0x00, 0x00, 0x00, 0x02].pack('C*') + 'aa').should == "aa"
end
end
|