Skip to content

Commit 655c3c0

Browse files
committed
independant fuzz tests of and without pos
1 parent edf974e commit 655c3c0

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

test/utils/Bytes.t.sol

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,20 @@ contract BytesTest is Test {
1111

1212
// INDEX OF
1313
function testIndexOf(bytes memory buffer, bytes1 s) public pure {
14-
testIndexOf(buffer, s, 0);
14+
uint256 result = Bytes.indexOf(buffer, s);
15+
16+
if (buffer.length == 0) {
17+
// Case 0: buffer is empty
18+
assertEq(result, type(uint256).max);
19+
} else if (result == type(uint256).max) {
20+
// Case 1: search value could not be found
21+
for (uint256 i = 0; i < buffer.length; ++i) assertNotEq(buffer[i], s);
22+
} else {
23+
// Case 2: search value was found
24+
assertEq(buffer[result], s);
25+
// search value is not present anywhere before the found location
26+
for (uint256 i = 0; i < result; ++i) assertNotEq(buffer[i], s);
27+
}
1528
}
1629

1730
function testIndexOf(bytes memory buffer, bytes1 s, uint256 pos) public pure {
@@ -32,7 +45,20 @@ contract BytesTest is Test {
3245
}
3346

3447
function testLastIndexOf(bytes memory buffer, bytes1 s) public pure {
35-
testLastIndexOf(buffer, s, 0);
48+
uint256 result = Bytes.lastIndexOf(buffer, s);
49+
50+
if (buffer.length == 0) {
51+
// Case 0: buffer is empty
52+
assertEq(result, type(uint256).max);
53+
} else if (result == type(uint256).max) {
54+
// Case 1: search value could not be found
55+
for (uint256 i = 0; i < buffer.length; ++i) assertNotEq(buffer[i], s);
56+
} else {
57+
// Case 2: search value was found
58+
assertEq(buffer[result], s);
59+
// search value is not present anywhere after the found location
60+
for (uint256 i = result + 1; i < buffer.length; ++i) assertNotEq(buffer[i], s);
61+
}
3662
}
3763

3864
function testLastIndexOf(bytes memory buffer, bytes1 s, uint256 pos) public pure {

0 commit comments

Comments
 (0)