Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions test/LibBit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,18 @@ contract LibBitTest is SoladyTest {
}
}

function testCountZeroBytesDifferential(bytes32) public {
testCountZeroBytesDifferential(_randomSmallBytes());
}

function testCountZeroBytesDifferential(bytes memory s) public {
assertEq(LibBit.countZeroBytes(s), _countZeroBytesOriginal(s));
}

function testCountZeroBytesCalldataDifferential(bytes32) public {
this.testCountZeroBytesCalldataDifferential(_randomSmallBytes());
}

function testCountZeroBytesCalldataDifferential(bytes calldata s) public {
assertEq(LibBit.countZeroBytesCalldata(s), _countZeroBytesOriginal(s));
}
Expand All @@ -312,4 +320,19 @@ contract LibBitTest is SoladyTest {
return c;
}
}

function _randomSmallBytes() internal returns (bytes memory) {
uint256 n = _bound(_random(), 0, 100);
uint256 r = _randomUniform();
uint256 x = r >> 248;
bytes memory s = new bytes(n);
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, r)
for { let i := 0 } lt(i, n) { i := add(i, 1) } {
if and(1, shr(i, r)) { mstore8(add(add(s, 0x20), i), x) }
}
}
return s;
}
}
3 changes: 3 additions & 0 deletions test/SemVerLib.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -264,5 +264,8 @@ contract SemVerLibTest is SoladyTest {

_checkEq("01.002.0003", "1.2.3");
_checkEq("v01.2.03", "1.2.3");

_checkLt("", "1.0.0");
_checkEq("", "0.0.0");
}
}
Loading