Skip to content

Commit f804d42

Browse files
committed
Add specs for Memory#index
1 parent b121764 commit f804d42

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

spec/lib/rex/image_source/memory_spec.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,41 @@
149149
end
150150

151151
describe "#index" do
152+
let(:found) { 'FG' }
153+
let(:not_found) { 'XYZ' }
152154

155+
context "when search available substring" do
156+
it "returns the index of the first occurrence" do
157+
expect(subject.index(found)).to eq(5)
158+
end
159+
160+
context "when using negative offset" do
161+
let(:offset) { -14 }
162+
it "returns the index of the first occurrence" do
163+
expect(subject.index(found, offset)).to eq(5)
164+
end
165+
end
166+
167+
context "when using positive offset" do
168+
let(:offset) { 1 }
169+
it "returns the index of the first occurrence" do
170+
expect(subject.index(found, offset)).to eq(5)
171+
end
172+
end
173+
end
174+
175+
context "when search not available substring" do
176+
it "returns nil" do
177+
expect(subject.index(not_found)).to be_nil
178+
end
179+
end
180+
181+
context "when using negative offset" do
182+
let(:offset) { -1 }
183+
it "start to search from offset from the end of the string" do
184+
expect(subject.index(found, offset)).to be_nil
185+
end
186+
end
153187
end
154188

155189
end

0 commit comments

Comments
 (0)