Sha256: 5b1860d01668f4b2593c7aacf06a44813386386fb05a8c830e44068a9fbccfaa

Contents?: true

Size: 684 Bytes

Versions: 2

Compression:

Stored size: 684 Bytes

Contents

# coding: utf-8
require_relative "spec_helper"

describe 'ZScan binary scanning methods' do
  it "#unpack" do
    z = ZScan.new "\x01\x02\x03"
    assert_raise ArgumentError do
      z.unpack '@1C'
    end
    assert_equal [1, 2], (z.unpack 'CC')
    assert_equal 2, z.pos
    assert_equal nil, (z.unpack 'I')
    assert_equal 2, z.pos
  end

  it "#scan_binary" do
    s = ZScan.binary_spec do
      int8        # once
      uint32_le 2 # little endian, twice
      double_be 1 # big endian, once
      single 1
    end

    a = [-1, 2, 3, 4.0, 3.0]
    z = ZScan.new(a.pack('cI<2Gf') + 'rest')
    b = z.scan_binary s
    assert_equal 'rest', z.rest
    assert_equal a, b
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
zscan-1.3 spec/binary_scan_spec.rb
zscan-1.2 spec/binary_scan_spec.rb