@@ -11,7 +11,20 @@ contract BytesTest is Test {
11
11
12
12
// INDEX OF
13
13
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
+ }
15
28
}
16
29
17
30
function testIndexOf (bytes memory buffer , bytes1 s , uint256 pos ) public pure {
@@ -32,7 +45,20 @@ contract BytesTest is Test {
32
45
}
33
46
34
47
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
+ }
36
62
}
37
63
38
64
function testLastIndexOf (bytes memory buffer , bytes1 s , uint256 pos ) public pure {
0 commit comments