-
Notifications
You must be signed in to change notification settings - Fork 125
Expand file tree
/
Copy pathunpack_spec.rb
More file actions
92 lines (75 loc) · 3.27 KB
/
Copy pathunpack_spec.rb
File metadata and controls
92 lines (75 loc) · 3.27 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# encoding: ascii-8bit
require 'spec_helper'
require 'stringio'
if defined?(Encoding)
Encoding.default_external = 'ASCII-8BIT'
end
describe MessagePack do
let(:eof_error) do
IS_JRUBY ? MessagePack::UnderflowError : EOFError
end
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
it "msgpack fixmap type" do
MessagePack.unpack([0x81, 0xa1, 0x61, 0x01].pack('C*')).should == {"a" => 1}
expect {
MessagePack.unpack([0x82, 0xa1, 0x61, 0x01].pack('C*'))
}.to raise_error(eof_error)
end
it "msgpack map 16 type" do
MessagePack.unpack([0xde, 0x00, 0x01, 0xa1, 0x61, 0x1].pack('C*')).should == {"a" => 1}
expect {
MessagePack.unpack([0xde, 0x00, 0x02, 0xa1, 0x61, 0x1].pack('C*'))
}.to raise_error(eof_error)
expect {
MessagePack.unpack([0xde, 0x80, 0x01, 0xa1, 0x61, 0x1].pack('C*'))
}.to raise_error(eof_error)
end
it "msgpack map 32 type" do
MessagePack.unpack([0xdf, 0x00, 0x00, 0x00, 0x01, 0xa1, 0x61, 0x1].pack('C*')).should == {"a" => 1}
expect {
MessagePack.unpack([0xdf, 0x00, 0x00, 0x00, 0x02, 0xa1, 0x61, 0x1].pack('C*'))
}.to raise_error(eof_error)
expect {
p MessagePack.unpack([0xdf, 0x80, 0x00, 0x00, 0x01, 0xa1, 0x61, 0x1].pack('C*'))
}.to raise_error(eof_error)
end
end