// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.16;

import "forge-std/Test.sol";
import "forge-std/console.sol";
import "./Utils.sol";

contract UtilsTest is Test {
    function testIndexOf() public {
        (bool success, uint256 at) = Utils.indexOf(
            hex"1234567890AbcdEF1234567890aBcdef12345678", hex"1234567890AbcdEF1234567890aBcdef12345678", 0
        );
        assertEq(success, true);
        assertEq(at, 0);
    }

    function testReplace1() public {
        bytes memory replaced = Utils.replace(
            hex"12312312312312312312312312312312312312311234567890AbcdEF1234567890aBcdef123456781231231231231231231231231231231231231231",
            address(0x1234567890AbcdEF1234567890aBcdef12345678),
            address(0x1231231231231231231231231231231231231231)
        );

        assertEq(
            replaced,
            hex"123123123123123123123123123123123123123112312312312312312312312312312312312312311231231231231231231231231231231231231231"
        );
    }

    function testReplace2() public {
        bytes memory replaced = Utils.replace(
            hex"12312312312312312312312312312312312312311234567890AbcdEF1234567890aBcdef1234567812312312312312312312312312312312312312311234567890AbcdEF1234567890aBcdef123456781231231231231231231231231231231231231231",
            address(0x1234567890AbcdEF1234567890aBcdef12345678),
            address(0x1231231231231231231231231231231231231231)
        );

        assertEq(
            replaced,
            hex"12312312312312312312312312312312312312311231231231231231231231231231231231231231123123123123123123123123123123123123123112312312312312312312312312312312312312311231231231231231231231231231231231231231"
        );
    }

    function testReplace3() public {
        bytes memory replaced = Utils.replace(
            hex"12312312312312312312312312312312312312311234567890AbcdEF1234567890aBcdef123456781234567890AbcdEF1234567890aBcdef123456781231231231231231231231231231231231231231",
            address(0x1234567890AbcdEF1234567890aBcdef12345678),
            address(0x1231231231231231231231231231231231231231)
        );

        assertEq(
            replaced,
            hex"1231231231231231231231231231231231231231123123123123123123123123123123123123123112312312312312312312312312312312312312311231231231231231231231231231231231231231"
        );
    }
}
