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
|
#!/usr/bin/env ruby
require File.expand_path(File.join(File.dirname(__FILE__), "test_helper"))
describe BinData::Uint8Array, "when initialising" do
it "with mutually exclusive parameters :initial_length and :read_until" do
params = {initial_length: 5, read_until: :eof}
_ { BinData::Uint8Array.new(params) }.must_raise ArgumentError
end
it "with :read_until" do
params = {read_until: :not_eof}
_ { BinData::Uint8Array.new(params) }.must_raise ArgumentError
end
it "with no parameters" do
arr = BinData::Uint8Array.new
_(arr.num_bytes).must_equal 0
end
end
describe BinData::Uint8Array, "with :read_until" do
it "reads until :eof" do
arr = BinData::Uint8Array.new(read_until: :eof)
arr.read("\xff\xfe\xfd\xfc")
_(arr).must_equal([255, 254, 253, 252])
end
end
describe BinData::Uint8Array, "with :initial_length" do
it "reads" do
arr = BinData::Uint8Array.new(initial_length: 3)
arr.read("\xff\xfe\xfd\xfc")
_(arr).must_equal([255, 254, 253])
end
end
describe BinData::Uint8Array, "when assigning" do
it "copies data" do
arr = BinData::Uint8Array.new
arr.assign([1, 2, 3])
_(arr).must_equal([1, 2, 3])
end
end
|