forked from foundry-rs/foundry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStringUtils.t.sol
54 lines (46 loc) · 1.73 KB
/
StringUtils.t.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
import "ds-test/test.sol";
import "cheats/Vm.sol";
contract StringManipulationTest is DSTest {
Vm constant vm = Vm(HEVM_ADDRESS);
function testToLowercase() public {
string memory original = "Hello World";
string memory lowercased = vm.toLowercase(original);
assertEq("hello world", lowercased);
}
function testToUppercase() public {
string memory original = "Hello World";
string memory uppercased = vm.toUppercase(original);
assertEq("HELLO WORLD", uppercased);
}
function testTrim() public {
string memory original = " Hello World ";
string memory trimmed = vm.trim(original);
assertEq("Hello World", trimmed);
}
function testReplace() public {
string memory original = "Hello World";
string memory replaced = vm.replace(original, "World", "Reth");
assertEq("Hello Reth", replaced);
}
function testSplit() public {
string memory original = "Hello,World,Reth";
string[] memory splitResult = vm.split(original, ",");
assertEq(3, splitResult.length);
assertEq("Hello", splitResult[0]);
assertEq("World", splitResult[1]);
assertEq("Reth", splitResult[2]);
}
function testIndexOf() public {
string memory input = "Hello, World!";
string memory key1 = "Hello,";
string memory key2 = "World!";
string memory key3 = "";
string memory key4 = "foundry";
assertEq(vm.indexOf(input, key1), 0);
assertEq(vm.indexOf(input, key2), 7);
assertEq(vm.indexOf(input, key3), 0);
assertEq(vm.indexOf(input, key4), type(uint256).max);
}
}