File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
spec/lib/rex/image_source Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 149
149
end
150
150
151
151
describe "#index" do
152
+ let ( :found ) { 'FG' }
153
+ let ( :not_found ) { 'XYZ' }
152
154
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
153
187
end
154
188
155
189
end
You can’t perform that action at this time.
0 commit comments