File: count_bytes_remaining_test.rb

package info (click to toggle)
ruby-bindata 2.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 652 kB
  • sloc: ruby: 8,896; makefile: 4
file content (41 lines) | stat: -rwxr-xr-x 924 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env ruby

require File.expand_path(File.join(File.dirname(__FILE__), "test_helper"))

describe BinData::CountBytesRemaining do
  let(:obj) { BinData::CountBytesRemaining.new }

  it "initial state" do
    _(obj).must_equal 0
    _(obj.num_bytes).must_equal 0
  end

  it "counts till end of stream" do
    data = "abcdefghij"
    _(obj.read(data)).must_equal 10
  end

  it "does not read any data" do
    io = StringIO.new "abcdefghij"
    obj.read(io)

    _(io.pos).must_equal 0
  end

  it "does not write any data" do
    _(obj.to_binary_s).must_equal_binary ""
  end

  it "allows setting value for completeness" do
    obj.assign("123")
    _(obj).must_equal "123"
    _(obj.to_binary_s).must_equal_binary ""
  end

  it "accepts BinData::BasePrimitive parameters" do
    count = BinData::CountBytesRemaining.new(assert: 2)
    _ {
      count.read("xyz")
    }.must_raise BinData::ValidityError
  end
end