Skip to content

Commit a612caf

Browse files
committed
Finish examples for Memory#read
1 parent df7ee55 commit a612caf

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

spec/lib/rex/image_source/memory_spec.rb

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
end
3535

3636
describe "#read" do
37-
context "when offset and len inside range" do
37+
context "when offset is positive" do
3838
let(:offset) { 1 }
3939
let(:len) { 10 }
4040

@@ -46,10 +46,49 @@
4646
expect(subject.read(offset, len).length).to eq(10)
4747
end
4848

49-
it "returns an String with contents starting at provided offset" do
49+
it "returns an String with _raw_data contents starting at provided offset" do
5050
expect(subject.read(offset, len)).to start_with('BCD')
5151
end
5252
end
53+
54+
context "when offset is negative" do
55+
let(:offset) { -5 }
56+
let(:len) { 2 }
57+
58+
it "returns an String" do
59+
expect(subject.read(offset, len)).to be_a_kind_of(String)
60+
end
61+
62+
it "returns an String of provided length" do
63+
expect(subject.read(offset, len).length).to eq(2)
64+
end
65+
66+
it "offset is counted from the end of the _raw_data" do
67+
expect(subject.read(offset, len)).to eq('LM')
68+
end
69+
end
70+
71+
context "when offset is out of range" do
72+
let(:offset) { 20 }
73+
let(:len) { 2 }
74+
75+
it "returns nil" do
76+
expect(subject.read(offset, len)).to be_nil
77+
end
78+
end
79+
80+
context "when len is bigger than _raw_data" do
81+
let(:offset) { 0 }
82+
let(:len) { 20 }
83+
84+
it "returns an String" do
85+
expect(subject.read(offset, len)).to be_a_kind_of(String)
86+
end
87+
88+
it "returns an String truncated to available contents" do
89+
expect(subject.read(offset, len).length).to eq(raw_data.length)
90+
end
91+
end
5392
end
5493

5594
describe "#subsource" do

0 commit comments

Comments
 (0)