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
|
# -*- coding: utf-8 -*-
require File.expand_path('../../../spec_helper', __FILE__)
require 'time'
require "amq/protocol/table_value_decoder"
module AMQ
module Protocol
describe TableValueDecoder do
it "is capable of decoding basic arrays TableValueEncoder encodes" do
input1 = [1, 2, 3]
value, offset = described_class.decode_array(TableValueEncoder.encode(input1), 1)
value.size.should == 3
value.first.should == 1
value.should == input1
input2 = ["one", 2, "three"]
value, offset = described_class.decode_array(TableValueEncoder.encode(input2), 1)
value.size.should == 3
value.first.should == "one"
value.should == input2
input3 = ["one", 2, "three", 4.0, 5000000.0]
value, offset = described_class.decode_array(TableValueEncoder.encode(input3), 1)
value.size.should == 5
value.last.should == 5000000.0
value.should == input3
end
it "is capable of decoding arrays TableValueEncoder encodes" do
input1 = [{ "one" => 2 }, 3]
data1 = TableValueEncoder.encode(input1)
# puts(TableValueEncoder.encode({ "one" => 2 }).inspect)
# puts(TableValueEncoder.encode(input1).inspect)
value, offset = described_class.decode_array(data1, 1)
value.size.should == 2
value.first.should == Hash["one" => 2]
value.should == input1
input2 = ["one", 2, { "three" => { "four" => 5.0 } }]
value, offset = described_class.decode_array(TableValueEncoder.encode(input2), 1)
value.size.should == 3
value.last["three"]["four"].should == 5.0
value.should == input2
end
end
end
end
|