bindata 2.4.15 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ChangeLog.rdoc +16 -0
- data/README.md +7 -10
- data/bindata.gemspec +5 -4
- data/examples/list.rb +1 -1
- data/lib/bindata/alignment.rb +15 -7
- data/lib/bindata/array.rb +54 -54
- data/lib/bindata/base.rb +14 -25
- data/lib/bindata/base_primitive.rb +24 -20
- data/lib/bindata/bits.rb +5 -5
- data/lib/bindata/buffer.rb +89 -11
- data/lib/bindata/choice.rb +9 -6
- data/lib/bindata/count_bytes_remaining.rb +1 -1
- data/lib/bindata/delayed_io.rb +10 -10
- data/lib/bindata/dsl.rb +34 -32
- data/lib/bindata/float.rb +3 -3
- data/lib/bindata/framework.rb +8 -10
- data/lib/bindata/int.rb +9 -9
- data/lib/bindata/io.rb +276 -253
- data/lib/bindata/name.rb +1 -1
- data/lib/bindata/params.rb +9 -7
- data/lib/bindata/primitive.rb +3 -3
- data/lib/bindata/registry.rb +46 -51
- data/lib/bindata/rest.rb +1 -1
- data/lib/bindata/sanitize.rb +9 -16
- data/lib/bindata/section.rb +97 -0
- data/lib/bindata/skip.rb +140 -51
- data/lib/bindata/string.rb +9 -9
- data/lib/bindata/stringz.rb +12 -10
- data/lib/bindata/struct.rb +83 -66
- data/lib/bindata/trace.rb +35 -42
- data/lib/bindata/transform/brotli.rb +35 -0
- data/lib/bindata/transform/lz4.rb +35 -0
- data/lib/bindata/transform/lzma.rb +35 -0
- data/lib/bindata/transform/xor.rb +19 -0
- data/lib/bindata/transform/xz.rb +35 -0
- data/lib/bindata/transform/zlib.rb +33 -0
- data/lib/bindata/transform/zstd.rb +35 -0
- data/lib/bindata/uint8_array.rb +2 -2
- data/lib/bindata/version.rb +1 -1
- data/lib/bindata/virtual.rb +4 -7
- data/lib/bindata/warnings.rb +1 -1
- data/lib/bindata.rb +3 -2
- data/test/array_test.rb +10 -8
- data/test/buffer_test.rb +9 -0
- data/test/choice_test.rb +1 -1
- data/test/delayed_io_test.rb +16 -0
- data/test/io_test.rb +54 -246
- data/test/registry_test.rb +1 -1
- data/test/section_test.rb +111 -0
- data/test/skip_test.rb +55 -10
- data/test/string_test.rb +4 -4
- data/test/stringz_test.rb +8 -0
- data/test/struct_test.rb +87 -12
- data/test/system_test.rb +119 -1
- data/test/test_helper.rb +30 -15
- data/test/warnings_test.rb +12 -0
- metadata +20 -18
- data/lib/bindata/offset.rb +0 -94
- data/test/offset_test.rb +0 -100
data/test/offset_test.rb
DELETED
@@ -1,100 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require File.expand_path(File.join(File.dirname(__FILE__), "test_helper"))
|
4
|
-
require 'bindata/offset'
|
5
|
-
|
6
|
-
describe BinData::Base, "offsets" do
|
7
|
-
class ThreeByteReader < BinData::Base
|
8
|
-
def do_read(io)
|
9
|
-
@val = io.readbytes(3)
|
10
|
-
end
|
11
|
-
|
12
|
-
def snapshot
|
13
|
-
@val
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class TenByteOffsetBase < BinData::Base
|
18
|
-
def self.create(params)
|
19
|
-
obj = self.new
|
20
|
-
obj.initialize_child(params)
|
21
|
-
obj
|
22
|
-
end
|
23
|
-
|
24
|
-
def initialize_child(params)
|
25
|
-
@child = ThreeByteReader.new(params, self)
|
26
|
-
end
|
27
|
-
|
28
|
-
def snapshot
|
29
|
-
@child.snapshot
|
30
|
-
end
|
31
|
-
|
32
|
-
def do_read(io)
|
33
|
-
io.seekbytes(10)
|
34
|
-
@child.do_read(io)
|
35
|
-
end
|
36
|
-
|
37
|
-
def clear
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
let(:data) { "0123456789abcdefghijk" }
|
42
|
-
let(:io) { StringIO.new(data) }
|
43
|
-
|
44
|
-
describe "with :check_offset" do
|
45
|
-
it "fails when offset is incorrect" do
|
46
|
-
io.seek(2)
|
47
|
-
obj = TenByteOffsetBase.create(check_offset: 10 - 4)
|
48
|
-
_ { obj.read(io) }.must_raise BinData::ValidityError
|
49
|
-
end
|
50
|
-
|
51
|
-
it "succeeds when offset is correct" do
|
52
|
-
io.seek(3)
|
53
|
-
obj = TenByteOffsetBase.create(check_offset: 10)
|
54
|
-
_(obj.read(io).snapshot).must_equal data[3 + 10, 3]
|
55
|
-
end
|
56
|
-
|
57
|
-
it "fails when :check_offset fails" do
|
58
|
-
io.seek(4)
|
59
|
-
obj = TenByteOffsetBase.create(check_offset: -> { offset == 10 + 1 } )
|
60
|
-
_ { obj.read(io) }.must_raise BinData::ValidityError
|
61
|
-
end
|
62
|
-
|
63
|
-
it "succeeds when :check_offset succeeds" do
|
64
|
-
io.seek(5)
|
65
|
-
obj = TenByteOffsetBase.create(check_offset: -> { offset == 10 } )
|
66
|
-
_(obj.read(io).snapshot).must_equal data[5 + 10, 3]
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe "with :adjust_offset" do
|
71
|
-
it "is mutually exclusive with :check_offset" do
|
72
|
-
params = { check_offset: 8, adjust_offset: 8 }
|
73
|
-
_ { TenByteOffsetBase.create(params) }.must_raise ArgumentError
|
74
|
-
end
|
75
|
-
|
76
|
-
it "adjust offset when incorrect" do
|
77
|
-
w, $-w = $-w, false
|
78
|
-
|
79
|
-
begin
|
80
|
-
io.seek(2)
|
81
|
-
obj = TenByteOffsetBase.create(adjust_offset: 13)
|
82
|
-
_(obj.read(io).snapshot).must_equal data[2 + 13, 3]
|
83
|
-
ensure
|
84
|
-
$-w = w
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
it "succeeds when offset is correct" do
|
89
|
-
io.seek(3)
|
90
|
-
obj = TenByteOffsetBase.create(adjust_offset: 10)
|
91
|
-
_(obj.read(io).snapshot).must_equal data[3 + 10, 3]
|
92
|
-
end
|
93
|
-
|
94
|
-
it "fails if cannot adjust offset" do
|
95
|
-
io.seek(4)
|
96
|
-
obj = TenByteOffsetBase.create(adjust_offset: -5)
|
97
|
-
_ { obj.read(io) }.must_raise BinData::ValidityError
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|