File: bigint_spec.rb

package info (click to toggle)
ruby-msgpack 1.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 972 kB
  • sloc: ruby: 4,789; ansic: 4,309; java: 1,809; makefile: 4
file content (26 lines) | stat: -rw-r--r-- 920 bytes parent folder | download | duplicates (2)
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
require 'spec/spec_helper'

describe MessagePack::Bigint do
  it 'serialize and deserialize arbitrary sized integer' do
    [
      1,
      -1,
      120938120391283122132313,
      -21903120391203912391023920332103,
      210290021321301203912933021323,
    ].each do |int|
      expect(MessagePack::Bigint.from_msgpack_ext(MessagePack::Bigint.to_msgpack_ext(int))).to be == int
    end
  end

  it 'has a stable format' do
    {
      120938120391283122132313 => "\x00\x9F\xF4UY\x11\x92\x9A?\x00\x00\x19\x9C".b,
      -21903120391203912391023920332103 => "\x01/\xB2\xBDG\xBD\xDE\xAA\xEBt\xCC\x8A\xC1\x00\x00\x01\x14".b,
      210290021321301203912933021323 => "\x00\xC4\xD8\x96\x8Bm\xCB\xC7\x03\xA7{\xD4\"\x00\x00\x00\x02".b,
    }.each do |int, payload|
      expect(MessagePack::Bigint.to_msgpack_ext(int)).to be == payload
      expect(MessagePack::Bigint.from_msgpack_ext(payload)).to be == int
    end
  end
end