PHP code example of gzhegow / lib

1. Go to this page and download the library: Download gzhegow/lib library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gzhegow / lib example snippets




define('__DIR_ROOT__', __DIR__ . '/..');

// > некоторые CMS сами по себе применяют настройки глубоко в ядре
// > с помощью этого класса можно указать при загрузке свои собственные и вызвав методы ->use{smtg}() вернуть указанные
\Gzhegow\Lib\Lib::entrypoint()
    ->setAllRecommended()
    //
    ->setCustomDirRoot(__DIR__ . '/..')
    //
    ->useAll()
    //
    ->lock()
;


$theTest = \Gzhegow\Lib\Lib::test();
$theDebug = \Gzhegow\Lib\Lib::debug();


// >>> TEST
// > тесты Promise ( да, я написал ECMAScript-like Promise на PHP :D )
$fn = function () use ($theDebug) {
    $theDebug->dump_value('[ Promise ]');
    echo "\n";


    \Gzhegow\Lib\Modules\Async\Promise\Promise::delay(900)
        ->then(function () use ($theDebug) {
            echo "\n";
            $theDebug->dump_value("[ 900 | THEN 1.1 ]");

            return 123;
        })
        ->then(function ($value) use ($theDebug) {
            $theDebug->dump_all_value([ "[ 900 | THEN 1.2 ]", $value ]);

            throw new \Gzhegow\Lib\Exception\RuntimeException('123');
        })
        ->catch(function ($reason) use ($theDebug) {
            $theDebug->dump_all_value([ "[ 900 | CATCH 1.3 ]", $reason ]);

            return \Gzhegow\Lib\Modules\Async\Promise\Promise::rejected($reason);
        })
        ->catch(function ($reason) use ($theDebug) {
            $theDebug->dump_all_value([ "[ 900 | CATCH 1.4 ]", $reason ]);

            return $reason;
        })
        ->then(function ($value) use ($theDebug) {
            $theDebug->dump_all_value([ "[ 900 | THEN 1.5 ]", $value ]);
            echo "\n";

            return $value;
        })
    ;


    \Gzhegow\Lib\Modules\Async\Promise\Promise::delay(800)
        ->then(function () use ($theDebug) {
            echo "\n";
            $theDebug->dump_value("[ 800 | THEN 2.1 ]");

            return 123;
        })
        ->then(function ($value) use ($theDebug) {
            $theDebug->dump_all_value([ "[ 800 | THEN 2.2 ]", $value ]);

            $var = yield \Gzhegow\Lib\Modules\Async\Promise\Promise::delay(400)
                ->then(function () {
                    return 456;
                })
            ;

            return $var;
        })
        ->then(function ($value) use ($theDebug) {
            $theDebug->dump_all_value([ "[ 800+400 | THEN 2.3 ]", $value ]);
            echo "\n";

            return $value;
        })
    ;


    \Gzhegow\Lib\Modules\Async\Promise\Promise::timeout(
        \Gzhegow\Lib\Modules\Async\Promise\Promise::delay(700),
        600
    )
        ->catch(function ($value) use ($theDebug) {
            echo "\n";
            $theDebug->dump_all_value([ "[ 600 | TIMEOUT ]", $value ]);
            echo "\n";

            return true;
        })
    ;


    $ps = [
        '[ 100 | ALL ] 1',
        \Gzhegow\Lib\Modules\Async\Promise\Promise::delay(100)->then(function () { return '[ 100 | ALL ] 2'; }),
        \Gzhegow\Lib\Modules\Async\Promise\Promise::resolved('[ 100 | ALL ] 3'),
    ];
    \Gzhegow\Lib\Modules\Async\Promise\Promise::allResolvedOf($ps)
        ->then(function ($res) use ($theDebug) {
            echo "\n";
            $theDebug->dump_array_multiline($res);
            echo "\n";

            return $res;
        })
    ;


    $ps = [
        \Gzhegow\Lib\Modules\Async\Promise\Promise::resolved('[ 200 | ALL SETTLED ] 1'),
        \Gzhegow\Lib\Modules\Async\Promise\Promise::delay(200)->then(function () { return '[ 200 | ALL SETTLED ] 2'; }),
        \Gzhegow\Lib\Modules\Async\Promise\Promise::rejected('[ 200 | ALL SETTLED ] 3'),
        \Gzhegow\Lib\Modules\Async\Promise\Promise::delay(100)->then(function () { return '[ 200 | ALL SETTLED ] 4'; }),
    ];
    \Gzhegow\Lib\Modules\Async\Promise\Promise::allOf($ps)
        ->then(function ($res) use ($theDebug) {
            echo "\n";
            $theDebug->dump_array_multiline($res, 2);
            echo "\n";

            return $res;
        })
    ;


    $ps = [
        \Gzhegow\Lib\Modules\Async\Promise\Promise::delay(400)->then(function () { return '[ 400 | RACE ] 1'; }),
        \Gzhegow\Lib\Modules\Async\Promise\Promise::delay(300)->then(function () { return '[ 300 | RACE ] 2'; }),
    ];
    \Gzhegow\Lib\Modules\Async\Promise\Promise::firstOf($ps)
        ->then(function ($res) use ($theDebug) {
            echo "\n";
            $theDebug->dump_value($res);
            echo "\n";

            return $res;
        })
    ;


    $ps = [
        \Gzhegow\Lib\Modules\Async\Promise\Promise::delay(500)->then(function () { return '[ 500 | ANY ] 1'; }),
        \Gzhegow\Lib\Modules\Async\Promise\Promise::rejected('[ 500 | ANY ] 2'),
    ];
    \Gzhegow\Lib\Modules\Async\Promise\Promise::firstResolvedOf($ps)
        ->then(function ($res) use ($theDebug) {
            echo "\n";
            $theDebug->dump_value($res);
            echo "\n";

            return $res;
        })
    ;


    \Gzhegow\Lib\Modules\Async\Loop\AsyncLoop::runLoop();
};
$test = $theTest->newCase($fn);
$test->expectStdout('
"[ Promise ]"


###
[
  "[ 100 | ALL ] 1",
  "[ 100 | ALL ] 2",
  "[ 100 | ALL ] 3"
]
###


###
[
  0 => [
    "status" => "resolved",
    "value" => "[ 200 | ALL SETTLED ] 1"
  ],
  2 => [
    "status" => "rejected",
    "reason" => "[ 200 | ALL SETTLED ] 3"
  ],
  3 => [
    "status" => "resolved",
    "value" => "[ 200 | ALL SETTLED ] 4"
  ],
  1 => [
    "status" => "resolved",
    "value" => "[ 200 | ALL SETTLED ] 2"
  ]
]
###


"[ 300 | RACE ] 2"


"[ 500 | ANY ] 1"


"[ 600 | TIMEOUT ]" | { object(iterable stringable) # Gzhegow\Lib\Exception\RuntimeException # "Timeout: 600ms" }


"[ 800 | THEN 2.1 ]"
"[ 800 | THEN 2.2 ]" | 123

"[ 900 | THEN 1.1 ]"
"[ 900 | THEN 1.2 ]" | 123
"[ 900 | CATCH 1.3 ]" | { object(iterable stringable) # Gzhegow\Lib\Exception\RuntimeException # "123" }
"[ 900 | CATCH 1.4 ]" | { object(iterable stringable) # Gzhegow\Lib\Exception\RuntimeException # "123" }
"[ 900 | THEN 1.5 ]" | { object(iterable stringable) # Gzhegow\Lib\Exception\RuntimeException # "123" }

"[ 800+400 | THEN 2.3 ]" | 456
');
$test->expectSecondsMin(1.2);
$test->expectSecondsMax(1.3);
$test->run();



// // >>> TEST
// // > Тест закомментирован, поскольку приводит к поднятию дополнительных процессов
// // > Если неверные права пользователя в Unix, с этим будут проблемы, раскоментируйте, чтобы протестировать
// $fn = function () use ($theDebug) {
//     $theDebug->dump_value('[ Fetch ]');
//     echo "\n";
//
//
//     \Gzhegow\Lib\Lib::async()
//         ->promiseManager()
//         ->useFetchApiWakeup(true)
//     ;
//
//     $p1 = \Gzhegow\Lib\Modules\Async\Promise\Promise::fetchCurl('https://google.com');
//     $p1->then(function ($result) use ($theDebug) {
//         $url = $result['url'];
//         $httpCode = $result['http_code'];
//
//         $theDebug->dump_value("{$url} - HTTP: {$httpCode}");
//     });
//
//     $p2 = \Gzhegow\Lib\Modules\Async\Promise\Promise::fetchCurl('https://yandex.ru');
//     $p2->then(function ($result) use ($theDebug) {
//         $url = $result['url'];
//         $httpCode = $result['http_code'];
//
//         $theDebug->dump_value("{$url} - HTTP: {$httpCode}");
//     });
//
//     \Gzhegow\Lib\Modules\Async\Loop\AsyncLoop::runLoop();
// };
// $test = $theTest->newCase($fn);
// $test->expectStdout('
// "[ Fetch ]"
//
// "https://google.com/ - HTTP: 200"
// "https://yandex.ru/ - HTTP: 200"
// ');
// $test->run();
// die();



// >>> TEST
// > тесты Ret ( один из современных паттернов это возврат одновременно статуса, ошибок и результата Result<T,E> называется )
$fn = function () use ($theDebug) {
    $theDebug->dump_value('[ Ret ]');
    echo "\n";

    $tz = 'UTC';
    $ret = \Gzhegow\Lib\Lib::type()->timezone_nameabbr($tz);
    $theDebug->dump_value($ret);
    $theDebug->dump_array_multiline([
        // > [ bool, bool ]
        $ret->getStatus(),
        //
        // > [ mixed|throw, mixed|null, mixed|null ]
        $ret->getValue(),
        //
        // > [ \stdClass[]|array[], \stdClass[] ]
        $ret->getErrors($isAssociative = true),
        //
        // > [ mixed|throw, mixed|NAN, mixed|throw, mixed|NAN ]
        $ret->orFallback($fallback = [ NAN ]),
    ], 4);

    echo "\n";

    $tz = '[ INVALID_TIMEZONE ]';
    $ret = \Gzhegow\Lib\Lib::type()->timezone_nameabbr($tz);
    $theDebug->dump_value($ret);
    $theDebug->dump_array_multiline([
        // > [ bool, bool ]
        $ret->getStatus(),
        //
        // > [ 0: mixed|throw, 1: mixed|null, 2: mixed|null ]
        // > commented, needs try/catch around otherwise
        // $ret->getValue(),
        [],
        //
        // > [ \stdClass[]|array[], \stdClass[] ]
        $ret->getErrors($isAssociative = true),
        //
        // > [ 0: mixed|throw, 1: mixed|throw, 2: mixed|NAN, 3: mixed|NAN ]
        $ret->orFallback($fallback = [ NAN ]),
    ], 4);
};
$test = $theTest->newCase($fn);
$test->expectStdoutIf((PHP_VERSION_ID >= 80200), '
"[ Ret ]"

{ object # Gzhegow\Lib\Modules\Type\Ret\PHP8\Ret }
###
[
  TRUE,
  "{ object(serializable) # DateTimeZone }",
  [],
  "{ object(serializable) # DateTimeZone }"
]
###

{ object # Gzhegow\Lib\Modules\Type\Ret\PHP8\Ret }
###
[
  FALSE,
  [],
  [
    [
      "The `timezoneOrNameOrAbbr` should be valid timezone",
      "[ INVALID_TIMEZONE ]"
    ]
  ],
  NAN
]
###
');
$test->expectStdoutIf(((PHP_VERSION_ID >= 80000) && (PHP_VERSION_ID < 80200)), '
"[ Ret ]"

{ object # Gzhegow\Lib\Modules\Type\Ret\PHP8\Ret }
###
[
  TRUE,
  "{ object # DateTimeZone }",
  [],
  "{ object # DateTimeZone }"
]
###

{ object # Gzhegow\Lib\Modules\Type\Ret\PHP8\Ret }
###
[
  FALSE,
  [],
  [
    [
      "The `timezoneOrNameOrAbbr` should be valid timezone",
      "[ INVALID_TIMEZONE ]"
    ]
  ],
  NAN
]
###
');
$test->expectStdoutIf((PHP_VERSION_ID < 80000), '
"[ Ret ]"

{ object # Gzhegow\Lib\Modules\Type\Ret\PHP7\Ret }
###
[
  TRUE,
  "{ object # DateTimeZone }",
  [],
  "{ object # DateTimeZone }"
]
###

{ object # Gzhegow\Lib\Modules\Type\Ret\PHP7\Ret }
###
[
  FALSE,
  [],
  [
    [
      "The `timezoneOrNameOrAbbr` should be valid timezone",
      "[ INVALID_TIMEZONE ]"
    ]
  ],
  NAN
]
###
');
$test->run();



// >>> TEST
// > тесты Exception
$fn = function () use ($theDebug) {
    $theDebug->dump_value('[ Exception ]');
    echo "\n";

    $theDebugThrowabler = \Gzhegow\Lib\Lib::debugThrowabler();

    $eeee1 = new \Exception('eeee1', 0);
    $eeee2 = new \Exception('eeee2', 0);

    $previousList = [ $eeee1, $eeee2 ];
    $eee0 = new \Gzhegow\Lib\Exception\LogicException('eee', ...$previousList);

    $ee1 = new \Exception('ee1', 0, $previous = $eee0);
    $ee2 = new \Exception('ee2', 0, $previous = $eee0);

    $previousList = [ $ee1, $ee2 ];
    $e0 = new \Gzhegow\Lib\Exception\RuntimeException('e', 0, ...$previousList);

    $messages = $theDebugThrowabler
        ->getMessagesLines(
            $e0,
            0
            | _DEBUG_THROWABLER_INFO_WITHOUT_FILE
        )
    ;

    echo implode("\n", $messages);
};
$test = $theTest->newCase($fn);
$test->expectStdout('
"[ Exception ]"

[ 0 ] e
-- [ 0.0 ] ee1
---- [ 0.0.0 ] eee
------ [ 0.0.0.0 ] eeee1
------ [ 0.0.0.1 ] eeee2
-- [ 0.1 ] ee2
---- [ 0.1.0 ] eee
------ [ 0.1.0.0 ] eeee1
------ [ 0.1.0.1 ] eeee2
');
$test->run();



// >>> TEST
// > тесты ArrayOf
$fn = function () use ($theDebug) {
    $theDebug->dump_value('[ ArrayOf ]');
    echo "\n";


    $notAnObject = 1;
    $objectStdClass = new \stdClass();
    $objectArrayObject = new ArrayObject();
    $objectAnonymousStdClass = new class extends \stdClass {
    };


    // > осторожно, `ArrayOf` не проверяет типы при добавлении, для этого есть `ArrayOfType` или `ArrayOfClass`
    // > этот объект сделан для того, чтобы убедится, что другой разработчик создал его с правильным типом
    // > при этом он может положить туда что захочет, это похоже на указание PHPDoc
    $theArrayOf = \Gzhegow\Lib\Modules\Arr\ArrayOf\ArrayOf::new('object');
    $theArrayOf[] = $notAnObject;
    $theDebug->dump_value($theArrayOf);
    $theDebug->dump_all_value([ $theArrayOf->isOfType('object'), $theArrayOf->getValues() ]);

    echo "\n";


    $theArrayOf = \Gzhegow\Lib\Modules\Arr\ArrayOf\ArrayOfType::new('object');
    $theArrayOf[] = $objectStdClass;
    $theArrayOf[] = $objectArrayObject;

    try {
        $theArrayOf[] = $notAnObject;
    }
    catch ( \Throwable $e ) {
        $theDebug->dump_value('[ CATCH ] ' . $e->getMessage());
    }
    $theDebug->dump_value($theArrayOf);
    $theDebug->dump_all_value([ $theArrayOf->isOfType('object'), $theArrayOf->getValues() ]);

    echo "\n";


    $theArrayOf = \Gzhegow\Lib\Modules\Arr\ArrayOf\ArrayOfClass::new(\stdClass::class);
    $theArrayOf[] = $objectStdClass;

    try {
        $theArrayOf[] = $objectArrayObject;
    }
    catch ( \Throwable $e ) {
        $theDebug->dump_value('[ CATCH ] ' . $e->getMessage());
    }

    try {
        $theArrayOf[] = $objectAnonymousStdClass;
    }
    catch ( \Throwable $e ) {
        $theDebug->dump_value('[ CATCH ] ' . $e->getMessage());
    }

    try {
        $theArrayOf[] = $notAnObject;
    }
    catch ( \Throwable $e ) {
        $theDebug->dump_value('[ CATCH ] ' . $e->getMessage());
    }
    $theDebug->dump_value($theArrayOf);
    $theDebug->dump_all_value([ $theArrayOf->isOfType('object'), $theArrayOf->getValues() ]);

    echo "\n";


    /**
     * @var \Gzhegow\Lib\Modules\Arr\Map\PHP8\Map $theMap
     */
    $theMap = \Gzhegow\Lib\Modules\Arr\Map\Map::new();
    $theMap[$stdClass = new \stdClass()] = 1;
    $theMap[$array = [ 1, 2, 3 ]] = 1;
    $theDebug->dump_value($theMap);
    $theDebug->dump_all_value([ isset($theMap[$stdClass]), isset($theMap[$array]) ]);
    $theDebug->dump_array($theMap->keys(), 1);
    $theDebug->dump_array($theMap->values(), 2);
};
$test = $theTest->newCase($fn);
$test->expectStdoutIf(PHP_VERSION_ID >= 80000, '
"[ ArrayOf ]"

{ object(countable(1) iterable serializable) # Gzhegow\Lib\Modules\Arr\ArrayOf\PHP8\ArrayOf }
TRUE | [ 1 ]

"[ CATCH ] The `value` should be a value of type: object"
{ object(countable(2) iterable serializable) # Gzhegow\Lib\Modules\Arr\ArrayOf\PHP8\ArrayOfType }
TRUE | [ "{ object # stdClass }", "{ object(countable(0) iterable serializable) # ArrayObject }" ]

"[ CATCH ] The `value` should be an instance of the class: stdClass"
"[ CATCH ] The `value` should be an instance of the class: stdClass"
"[ CATCH ] The `value` should be an object"
{ object(countable(1) iterable serializable) # Gzhegow\Lib\Modules\Arr\ArrayOf\PHP8\ArrayOfClass }
TRUE | [ "{ object # stdClass }" ]

{ object(countable(2) iterable serializable) # Gzhegow\Lib\Modules\Arr\Map\PHP8\Map }
TRUE | TRUE
[ "{ object # stdClass }", "{ array(3) }" ]
[ 1, 1 ]
');
$test->expectStdoutIf(PHP_VERSION_ID < 80000, '
"[ ArrayOf ]"

{ object(countable(1) iterable serializable) # Gzhegow\Lib\Modules\Arr\ArrayOf\PHP7\ArrayOf }
TRUE | [ 1 ]

"[ CATCH ] The `value` should be a value of type: object"
{ object(countable(2) iterable serializable) # Gzhegow\Lib\Modules\Arr\ArrayOf\PHP7\ArrayOfType }
TRUE | [ "{ object # stdClass }", "{ object(countable(0) iterable serializable) # ArrayObject }" ]

"[ CATCH ] The `value` should be an instance of the class: stdClass"
"[ CATCH ] The `value` should be an instance of the class: stdClass"
"[ CATCH ] The `value` should be an object"
{ object(countable(1) iterable serializable) # Gzhegow\Lib\Modules\Arr\ArrayOf\PHP7\ArrayOfClass }
TRUE | [ "{ object # stdClass }" ]

{ object(countable(2) iterable serializable) # Gzhegow\Lib\Modules\Arr\Map\PHP7\Map }
TRUE | TRUE
[ "{ object # stdClass }", "{ array(3) }" ]
[ 1, 1 ]
');
$test->run();



// >>> TEST
// > тесты Config
$fn = function () use ($theDebug) {
    $theDebug->dump_value('[ Config ]');
    echo "\n";

    /**
     * @property \TestConfigChild $child
     */
    class TestConfig extends \Gzhegow\Lib\Config\AbstractConfig
    {
        protected $child;

        public function __construct()
        {
            $this->child = new \TestConfigChild();

            parent::__construct();
        }
    }

    /**
     * @property string $foo
     */
    class TestConfigChild extends \Gzhegow\Lib\Config\AbstractConfig
    {
        protected $foo = 'bar';
    }

    /**
     * @property \TestConfigChildValidate $child
     */
    class ConfigValidateDummy extends \Gzhegow\Lib\Config\AbstractConfig
    {
        protected $child;

        public function __construct()
        {
            $this->child = new \TestConfigChildValidate();

            parent::__construct();
        }
    }

    /**
     * @property int $foo
     * @property int $foo2
     */
    class TestConfigChildValidate extends \Gzhegow\Lib\Config\AbstractConfig
    {
        protected $foo = 1;
        protected $foo2;

        protected function validation(array $context = []) : bool
        {
            if ( $this->foo2 !== $this->foo ) {
                return false;
            }

            return true;
        }
    }


    $config = new \TestConfig();

    $configChildDefault = $config->child;

    $configChildNewFooValue = 'baz';
    $configChildNew = new \TestConfigChild();
    $configChildNew->foo = $configChildNewFooValue;

    $config->child = $configChildNew;

    $theDebug->dump_value($config);
    $theDebug->dump_all_value([ $config->child, $config->child === $configChildDefault ]);
    $theDebug->dump_all_value([ $config->child->foo, $config->child->foo === $configChildNew->foo ]);

    echo "\n";


    $config = new \TestConfig();
    $configChildDefault = $config->child;

    $configChildNewFooValue = 'baz';
    $config->load(
        [
            'hello' => 'world',
            'foo'   => 'bar',
            'child' => [
                'foo' => $configChildNewFooValue,
            ],
        ]
    );

    $theDebug->dump_value($config);
    $theDebug->dump_all_value([ $config->child, $config->child === $configChildDefault ]);
    $theDebug->dump_all_value([ $config->child->foo, $config->child->foo === $configChildNewFooValue ]);

    echo "\n";


    $configArray = $config->toArray();
    $config->load($configArray);

    $theDebug->dump_value($config);
    $theDebug->dump_all_value([ $config->child, $config->child === $configChildDefault ]);
    $theDebug->dump_all_value([ $config->child->foo, $config->child->foo === $configChildNewFooValue ]);

    echo "\n";


    $config = new \ConfigValidateDummy();
    try {
        $config->validate();
    }
    catch ( \Throwable $e ) {
        $theDebug->dump_value('[ CATCH ] ' . $e->getMessage());
    }
};
$test = $theTest->newCase($fn);
$test->expectStdout('
"[ Config ]"

{ object # TestConfig }
{ object # TestConfigChild } | TRUE
"baz" | TRUE

{ object # TestConfig }
{ object # TestConfigChild } | TRUE
"baz" | TRUE

{ object # TestConfig }
{ object # TestConfigChild } | TRUE
"baz" | TRUE

"[ CATCH ] Configuration is invalid"
');
$test->run();



// >>> TEST
// > тесты ErrorBag
$fn = function () use ($theDebug) {
    $theDebug->dump_value('[ ErrorBag ]');
    echo "\n";

    \Gzhegow\Lib\Lib::newErrorBag($b);

    for ( $i = 0; $i < 2; $i++ ) {
        $tag = 'tag' . $i;

        for ( $ii = 0; $ii < 2; $ii++ ) {
            $ttag = 'ttag' . $ii;

            for ( $iii = 0; $iii < 2; $iii++ ) {
                $tttag = 'tttag' . $iii;

                $b->error("[ Error ] {$i}.{$ii}.{$iii}", [ $tag, $ttag, $tttag ], [ __FILE__, __LINE__ ]);
            }
        }
    }

    $list = $b->getErrorsByTags([ 'tttag0' ]); // 4

    $print = [];
    foreach ( $list as $l ) {
        $print[] = [ $l->error, $l ];
    }

    $theDebug->dump_array_multiline($print, 2);
};
$test = $theTest->newCase($fn);
$test->expectStdout('
"[ ErrorBag ]"

###
[
  [
    "[ Error ] 0.0.0",
    "{ object # Gzhegow\Lib\Modules\Php\ErrorBag\ErrorBagError }"
  ],
  [
    "[ Error ] 0.1.0",
    "{ object # Gzhegow\Lib\Modules\Php\ErrorBag\ErrorBagError }"
  ],
  [
    "[ Error ] 1.0.0",
    "{ object # Gzhegow\Lib\Modules\Php\ErrorBag\ErrorBagError }"
  ],
  [
    "[ Error ] 1.1.0",
    "{ object # Gzhegow\Lib\Modules\Php\ErrorBag\ErrorBagError }"
  ]
]
###
');
$test->run();



// >>> TEST
// > тесты Microtimer
$fn = function () use ($theDebug) {
    $theDebug->dump_value('[ Microtimer ]');
    echo "\n";


    $mt = \Gzhegow\Lib\Lib::newMicrotimer();

    $tag = 'tag';

    $mt($tag);

    for ( $i = 0; $i < 2; $i++ ) {
        $ttag = 'ttag_' . $i;

        $mt($ttag);

        for ( $ii = 0; $ii < 2; $ii++ ) {
            $tttag = 'tttag_' . $i . '_' . $ii;

            $mt($tttag);

            usleep(1e4);

            $mt($tttag, 1);
        }

        $mt($ttag, 1);
    }

    $mt($tag, 1);

    $report = $mt();

    $expect = [
        'tag'       => (4 * 1e-4),
        //
        'ttag_0'    => (2 * 1e-4),
        'ttag_1'    => (2 * 1e-4),
        //
        'tttag_0_0' => (1e-4),
        'tttag_0_1' => (1e-4),
        'tttag_1_0' => (1e-4),
        'tttag_1_1' => (1e-4),
    ];

    foreach ( $report as $tag => $floats ) {
        $report[$tag] = ($expect[$tag] < array_sum($floats));
    }

    $theDebug->dump_array_multiline($report, 2);
};
$test = $theTest->newCase($fn);
$test->expectStdout('
"[ Microtimer ]"

###
[
  "tag" => TRUE,
  "ttag_0" => TRUE,
  "tttag_0_0" => TRUE,
  "tttag_0_1" => TRUE,
  "ttag_1" => TRUE,
  "tttag_1_0" => TRUE,
  "tttag_1_1" => TRUE
]
###
');
$test->run();



// >>> TEST
// > тесты Pipe
$fn = function () use ($theDebug) {
    $theDebug->dump_value('[ Pipe ]');
    echo "\n";


    $fnStrval = function ($input) {
        echo '> fnStrval' . "\n";

        return strval($input);
    };
    $fnStrlen = function ($input) {
        echo '> fnStrlen' . "\n";

        return strlen($input);
    };
    $fnTapCustom = function ($input) use ($theDebug) {
        echo '> fnTapCustom' . "\n";

        $theDebug->dump_value($input);

        throw new \Gzhegow\Lib\Exception\RuntimeException('This is the exception');
    };
    $fnIntval = function ($value) {
        echo '> fnIntval' . "\n";

        return intval($value);
    };

    $fnCatch = function (\Throwable $e, $input, $context, array $args = []) {
        echo '> fnCatch' . "\n";

        if ( $e instanceof \RuntimeException ) {
            return $args[2];
        }

        return $e;
    };
    $fnCatchArgs = [
        // 0 => null, // > ключ будет добавлен и заполнен NULL
        // 1 => null, // > ключ будет добавлен и заполнен NULL
        2 => 'new_result',
    ];

    $fnMiddleware = function ($fnNext, $input) {
        echo '> fnMiddleware::before' . "\n";

        $result = $fnNext($input);

        echo '> fnMiddleware::after' . "\n";

        return $result;
    };
    $fnMiddlewareStep1 = function ($input) {
        echo '> fnMiddlewareStep1' . "\n";

        return $input . '1';
    };
    $fnMiddlewareStep2 = function ($input) {
        echo '> fnMiddlewareStep2' . "\n";

        return $input . '2';
    };


    $pipe = \Gzhegow\Lib\Lib::func()->newPipe();
    $pipe
        // > этот шаг может заменить значение, в данном случае приведя его к строке
        ->map($fnStrval)
        //
        // > этот шаг может очистить значение (в последующих шаг будет использоваться NULL)
        ->filter($fnStrlen)
        //
        // > этот шаг может выполнить сторонние действия, а возврат метода игнорируется
        ->tap($fnTapCustom)
        //
        // > этот шаг никогда не начнется, поскольку в прошлом шаге было выброшено исключение
        ->map($fnIntval)
        //
        // > или можно обрабатывать исключения обычным способом через callable
        ->catch($fnCatch, $fnCatchArgs)
        //
        // > ещё можно добавить обёртки-middleware
        ->middleware($fnMiddleware)
        /**/ ->map($fnMiddlewareStep1)
        /**/ ->map($fnMiddlewareStep2)
        ->endMiddleware()
    ;


    $result = $pipe->run(0);
    $theDebug->dump_value($result);
    echo "\n";

    $result = $pipe->run(1);
    $theDebug->dump_value($result);
    echo "\n";


    $result = $pipe('');
    $theDebug->dump_value($result);
    echo "\n";

    $result = $pipe('0');
    $theDebug->dump_value($result);
    echo "\n";

    $result = $pipe('1');
    $theDebug->dump_value($result);
};
$test = $theTest->newCase($fn);
$test->expectStdout('
"[ Pipe ]"

> fnStrval
> fnStrlen
> fnTapCustom
"0"
> fnCatch
> fnMiddleware::before
> fnMiddlewareStep1
> fnMiddlewareStep2
> fnMiddleware::after
"new_result12"

> fnStrval
> fnStrlen
> fnTapCustom
"1"
> fnCatch
> fnMiddleware::before
> fnMiddlewareStep1
> fnMiddlewareStep2
> fnMiddleware::after
"new_result12"

> fnStrval
> fnStrlen
> fnTapCustom
NULL
> fnCatch
> fnMiddleware::before
> fnMiddlewareStep1
> fnMiddlewareStep2
> fnMiddleware::after
"new_result12"

> fnStrval
> fnStrlen
> fnTapCustom
"0"
> fnCatch
> fnMiddleware::before
> fnMiddlewareStep1
> fnMiddlewareStep2
> fnMiddleware::after
"new_result12"

> fnStrval
> fnStrlen
> fnTapCustom
"1"
> fnCatch
> fnMiddleware::before
> fnMiddlewareStep1
> fnMiddlewareStep2
> fnMiddleware::after
"new_result12"
');
$test->run();



// >>> TEST
// > тесты ArrModule
$fn = function () use ($theDebug) {
    $theDebug->dump_value('[ ArrModule ]');
    echo "\n";


    $arr0 = [];
    $arr1 = [ true ];
    $arr2 = [ [ true ] ];
    $arr3 = [ [ [ true ] ] ];

    $statusArray = [];
    $statusArray[] = \Gzhegow\Lib\Lib::arr()->type_array_recursive(null, $arr0, 1)->isOk();
    $statusArray[] = \Gzhegow\Lib\Lib::arr()->type_array_recursive(null, $arr0, 2)->isOk();
    $statusArray[] = \Gzhegow\Lib\Lib::arr()->type_array_recursive(null, $arr0, 3)->isOk();
    $theDebug->dump_value($statusArray);

    $statusArray = [];
    $statusArray[] = \Gzhegow\Lib\Lib::arr()->type_array_recursive(null, $arr1, 1)->isOk();
    $statusArray[] = \Gzhegow\Lib\Lib::arr()->type_array_recursive(null, $arr1, 2)->isOk();
    $statusArray[] = \Gzhegow\Lib\Lib::arr()->type_array_recursive(null, $arr1, 3)->isOk();
    $theDebug->dump_value($statusArray);

    $statusArray = [];
    $statusArray[] = \Gzhegow\Lib\Lib::arr()->type_array_recursive(null, $arr2, 1)->isOk();
    $statusArray[] = \Gzhegow\Lib\Lib::arr()->type_array_recursive(null, $arr2, 2)->isOk();
    $statusArray[] = \Gzhegow\Lib\Lib::arr()->type_array_recursive(null, $arr2, 3)->isOk();
    $theDebug->dump_value($statusArray);

    $statusArray = [];
    $statusArray[] = \Gzhegow\Lib\Lib::arr()->type_array_recursive(null, $arr3, 1)->isOk();
    $statusArray[] = \Gzhegow\Lib\Lib::arr()->type_array_recursive(null, $arr3, 2)->isOk();
    $statusArray[] = \Gzhegow\Lib\Lib::arr()->type_array_recursive(null, $arr3, 3)->isOk();
    $theDebug->dump_value($statusArray);

    echo "\n";


    $arr = [ [ [ true ] ] ];

    $has = \Gzhegow\Lib\Lib::arr()->has($arr, '0.0');
    $get = \Gzhegow\Lib\Lib::arr()->get($arr, '0.0');
    $theDebug->dump_value($has);
    $theDebug->dump_array_multiline($get, 2);

    echo "\n";

    $has = \Gzhegow\Lib\Lib::arr()->has($arr, '0.1');
    $get = \Gzhegow\Lib\Lib::arr()->get($arr, '0.1', [ null ]);
    $theDebug->dump_all_value([ $has, $get ]);

    try {
        \Gzhegow\Lib\Lib::arr()->get($arr, '0.1');
    }
    catch ( \Throwable $e ) {
        $theDebug->dump_value('[ CATCH ] ' . $e->getMessage());
    }

    echo "\n";


    $cases = [
        [ [ 1, 2, 3 ], [ 2, 3, 4 ] ],
        [ [ 1, '2', 3 ], [ 2, 3 ] ],
        [ [ '1', '2', '3' ], [ 1, 2 ] ],
        [ [ 1, 2, 2, 3 ], [ 2 ] ],
        [ [ 'x' => 100, 'y' => 200, 'z' => 300 ], [ 200, 300, 400 ] ],
    ];

    foreach ( $cases as [$a, $b] ) {
        $resStrict = \Gzhegow\Lib\Lib::arr()->intersect($a, $b);
        $resNonStrict = \Gzhegow\Lib\Lib::arr()->intersect_non_strict($a, $b);
        $theDebug->dump_all_value([
            $resStrict,
            $resNonStrict,
            $resNonStrict === array_intersect($a, $b),
        ]);

        $resStrict = \Gzhegow\Lib\Lib::arr()->diff($a, $b);
        $resNonStrict = \Gzhegow\Lib\Lib::arr()->diff_non_strict($a, $b);
        $theDebug->dump_all_value([
            $resStrict,
            $resNonStrict,
            $resNonStrict === array_diff($a, $b),
        ]);
    }

    echo "\n";


    $arr = [
        0 => '',
        1 => [],
        2 => [ 1, 2, 3 ],
        3 => [
            '',
            [],
            [ 1, 2, 3 ],
        ],
        4 => [
            'key0' => '',
            'key1' => [],
        ],
        5 => [
            'key0' => '',
            'key1' => [],
            'key2' => [ 1, 2, 3 ],
        ],

        'key0' => '',
        'key1' => [],
        'key2' => [ 1, 2, 3 ],
        'key3' => [
            '',
            [],
            [ 1, 2, 3 ],
        ],
        'key4' => [
            'key0' => '',
            'key1' => [],
        ],
        'key5' => [
            'key0' => '',
            'key1' => [],
            'key2' => [ 1, 2, 3 ],
        ],

        6      => [
            0 => '',
            1 => [],
            2 => [ 1, 2, 3 ],
            3 => [
                '',
                [],
                [ 1, 2, 3 ],
            ],
            4 => [
                'key0' => '',
                'key1' => [],
            ],
            5 => [
                'key0' => '',
                'key1' => [],
                'key2' => [ 1, 2, 3 ],
            ],

            'key0' => '',
            'key1' => [],
            'key2' => [ 1, 2, 3 ],
            'key3' => [
                '',
                [],
                [ 1, 2, 3 ],
            ],
            'key4' => [
                'key0' => '',
                'key1' => [],
            ],
            'key5' => [
                'key0' => '',
                'key1' => [],
                'key2' => [ 1, 2, 3 ],
            ],
        ],
        'key6' => [
            0 => '',
            1 => [],
            2 => [ 1, 2, 3 ],
            3 => [
                '',
                [],
                [ 1, 2, 3 ],
            ],
            4 => [
                'key0' => '',
                'key1' => [],
            ],
            5 => [
                'key0' => '',
                'key1' => [],
                'key2' => [ 1, 2, 3 ],
            ],

            'key0' => '',
            'key1' => [],
            'key2' => [ 1, 2, 3 ],
            'key3' => [
                '',
                [],
                [ 1, 2, 3 ],
            ],
            'key4' => [
                'key0' => '',
                'key1' => [],
            ],
            'key5' => [
                'key0' => '',
                'key1' => [],
                'key2' => [ 1, 2, 3 ],
            ],
        ],
    ];
    $res = \Gzhegow\Lib\Lib::arr()->dot(
        $arr, '.', [],
        _ARR_WALK_WITH_EMPTY_ARRAYS | _ARR_WALK_WITH_LISTS | _ARR_WALK_WITH_DICTS
    );
    $theDebug->dump_array_multiline($res, 2);
    echo "\n";


    $arr = [
        'prop' => 1,

        0 => [
            'prop' => 1,

            0 => [
                'prop' => 1,

                0 => [
                    'prop' => 1,
                ],
            ],
        ],
    ];

    $objStdClass = \Gzhegow\Lib\Lib::arr()->map_to_object($arr);
    $theDebug->dump_all_value([ $objStdClass, (array) $objStdClass ]);

    $target = new \stdClass();
    $objStdClass = \Gzhegow\Lib\Lib::arr()->map_to_object($arr, $target);
    $theDebug->dump_all_value([ $objStdClass, (array) $objStdClass ]);

    $target = new class {
        protected $prop;
    };
    $objAnonymous = \Gzhegow\Lib\Lib::arr()->map_to_object($arr, $target);
    $theDebug->dump_all_value([ $objAnonymous, (array) $objAnonymous ]);
};
$test = $theTest->newCase($fn);
$test->expectStdout('
"[ ArrModule ]"

[ TRUE, TRUE, TRUE ]
[ TRUE, TRUE, TRUE ]
[ FALSE, TRUE, TRUE ]
[ FALSE, FALSE, TRUE ]

TRUE
###
[
  TRUE
]
###

FALSE | NULL
"[ CATCH ] Missing array path"

[ 1 => 2, 2 => 3 ] | [ 1 => 2, 2 => 3 ] | TRUE
[ 1 ] | [ 1 ] | TRUE
[ 2 => 3 ] | [ 1 => "2", 2 => 3 ] | TRUE
[ 1, "2" ] | [ 1 ] | TRUE
[] | [ "1", "2" ] | TRUE
[ "1", "2", "3" ] | [ 2 => "3" ] | TRUE
[ 1 => 2, 2 => 2 ] | [ 1 => 2, 2 => 2 ] | TRUE
[ 0 => 1, 3 => 3 ] | [ 0 => 1, 3 => 3 ] | TRUE
[ "y" => 200, "z" => 300 ] | [ "y" => 200, "z" => 300 ] | TRUE
[ "x" => 100 ] | [ "x" => 100 ] | TRUE

###
[
  0 => "",
  1 => [],
  2 => [
    1,
    2,
    3
  ],
  "3.0" => "",
  "3.1" => [],
  "3.2" => [
    1,
    2,
    3
  ],
  "4.key0" => "",
  "4.key1" => [],
  "5.key0" => "",
  "5.key1" => [],
  "5.key2" => [
    1,
    2,
    3
  ],
  "key0" => "",
  "key1" => [],
  "key2" => [
    1,
    2,
    3
  ],
  "key3.0" => "",
  "key3.1" => [],
  "key3.2" => [
    1,
    2,
    3
  ],
  "key4.key0" => "",
  "key4.key1" => [],
  "key5.key0" => "",
  "key5.key1" => [],
  "key5.key2" => [
    1,
    2,
    3
  ],
  "6.0" => "",
  "6.1" => [],
  "6.2" => [
    1,
    2,
    3
  ],
  "6.3.0" => "",
  "6.3.1" => [],
  "6.3.2" => [
    1,
    2,
    3
  ],
  "6.4.key0" => "",
  "6.4.key1" => [],
  "6.5.key0" => "",
  "6.5.key1" => [],
  "6.5.key2" => [
    1,
    2,
    3
  ],
  "6.key0" => "",
  "6.key1" => [],
  "6.key2" => [
    1,
    2,
    3
  ],
  "6.key3.0" => "",
  "6.key3.1" => [],
  "6.key3.2" => [
    1,
    2,
    3
  ],
  "6.key4.key0" => "",
  "6.key4.key1" => [],
  "6.key5.key0" => "",
  "6.key5.key1" => [],
  "6.key5.key2" => [
    1,
    2,
    3
  ],
  "key6.0" => "",
  "key6.1" => [],
  "key6.2" => [
    1,
    2,
    3
  ],
  "key6.3.0" => "",
  "key6.3.1" => [],
  "key6.3.2" => [
    1,
    2,
    3
  ],
  "key6.4.key0" => "",
  "key6.4.key1" => [],
  "key6.5.key0" => "",
  "key6.5.key1" => [],
  "key6.5.key2" => [
    1,
    2,
    3
  ],
  "key6.key0" => "",
  "key6.key1" => [],
  "key6.key2" => [
    1,
    2,
    3
  ],
  "key6.key3.0" => "",
  "key6.key3.1" => [],
  "key6.key3.2" => [
    1,
    2,
    3
  ],
  "key6.key4.key0" => "",
  "key6.key4.key1" => [],
  "key6.key5.key0" => "",
  "key6.key5.key1" => [],
  "key6.key5.key2" => [
    1,
    2,
    3
  ]
]
###
' . "
{ object # stdClass } | [ \"prop\" => 1, 0 => \"{ object # stdClass }\" ]
{ object # stdClass } | [ \"prop\" => 1, 0 => \"{ object # stdClass }\" ]
{ object # class@anonymous } | [ \"\x00*\x00prop\" => 1, 0 => \"{ object # stdClass }\" ]
");
$test->run();



// >>> TEST
// > тесты BcmathModule
$fn = function () use ($theDebug) {
    $theDebug->dump_value('[ BcmathModule ]');
    echo "\n";

    $result = \Gzhegow\Lib\Lib::bcmath()->bc_abs($a = 0);
    $theDebug->dump_all_value([ 'bc_abs', $a, (string) $result, $result ]);
    $result = \Gzhegow\Lib\Lib::bcmath()->bc_abs($a = 1.005);
    $theDebug->dump_all_value([ 'bc_abs', $a, (string) $result, $result ]);
    $result = \Gzhegow\Lib\Lib::bcmath()->bc_abs($a = -1.005);
    $theDebug->dump_all_value([ 'bc_abs', $a, (string) $result, $result ]);
    echo "\n";

    $result = \Gzhegow\Lib\Lib::bcmath()->bc_ceil($a = 0);
    $theDebug->dump_all_value([ 'bc_ceil', $a, (string) $result, $result ]);
    $result = \Gzhegow\Lib\Lib::bcmath()->bc_ceil($a = 1.005);
    $theDebug->dump_all_value([ 'bc_ceil', $a, (string) $result, $result ]);
    $result = \Gzhegow\Lib\Lib::bcmath()->bc_ceil($a = -1.005);
    $theDebug->dump_all_value([ 'bc_ceil', $a, (string) $result, $result ]);
    echo "\n";

    $result = \Gzhegow\Lib\Lib::bcmath()->bc_floor($a = 0);
    $theDebug->dump_all_value([ 'bc_floor', $a, (string) $result, $result ]);
    $result = \Gzhegow\Lib\Lib::bcmath()->bc_floor($a = 1.005);
    $theDebug->dump_all_value([ 'bc_floor', $a, (string) $result, $result ]);
    $result = \Gzhegow\Lib\Lib::bcmath()->bc_floor($a = -1.005);
    $theDebug->dump_all_value([ 'bc_floor', $a, (string) $result, $result ]);
    echo "\n";
    echo "\n";


    $result = \Gzhegow\Lib\Lib::bcmath()->bc_add($a = 1.123, $b = 1.456, 1, [ &$frac ]);
    $theDebug->dump_all_value([ 'bc_add', $a, $b, (string) $result, (string) $frac, $result ]);
    $result = \Gzhegow\Lib\Lib::bcmath()->bc_sub($a = 1.456, $b = 1.123, 1, [ &$frac ]);
    $theDebug->dump_all_value([ 'bc_sub', $a, $b, (string) $result, (string) $frac, $result ]);
    $result = \Gzhegow\Lib\Lib::bcmath()->bc_mul($a = 1.456, $b = 3, 1, [ &$frac ]);
    $theDebug->dump_all_value([ 'bc_mul', $a, $b, (string) $result, (string) $frac, $result ]);
    $result = \Gzhegow\Lib\Lib::bcmath()->bc_div($a = 4.777, $b = 3, 1, [ &$frac ]);
    $theDebug->dump_all_value([ 'bc_div', $a, $b, (string) $result, (string) $frac, $result ]);
    echo "\n";

    $result = \Gzhegow\Lib\Lib::bcmath()->bc_pow($a = 4.777, $b = 2, 1, [ &$frac ]);
    $theDebug->dump_all_value([ 'bc_pow', $a, $b, (string) $result, (string) $frac, $result ]);
    $result = \Gzhegow\Lib\Lib::bcmath()->bc_sqrt($a = 4.777, 2, [ &$frac ]);
    $theDebug->dump_all_value([ 'bc_sqrt', $a, (string) $result, (string) $frac, $result ]);
    echo "\n";
    echo "\n";


    $result = \Gzhegow\Lib\Lib::bcmath()->bc_mod($a = 5.75, $b = 2);
    $theDebug->dump_all_value([ 'bc_mod', $a, $b, (string) $result, $result ]);
    $result = \Gzhegow\Lib\Lib::bcmath()->bc_mod($a = -5.75, $b = 2);
    $theDebug->dump_all_value([ 'bc_mod', $a, $b, (string) $result, $result ]);
    $result = \Gzhegow\Lib\Lib::bcmath()->bc_mod($a = 5.75, $b = 2.25);
    $theDebug->dump_all_value([ 'bc_mod', $a, $b, (string) $result, $result ]);
    $result = \Gzhegow\Lib\Lib::bcmath()->bc_mod($a = -5.75, $b = 2.25);
    $theDebug->dump_all_value([ 'bc_mod', $a, $b, (string) $result, $result ]);
    echo "\n";

    $result = \Gzhegow\Lib\Lib::bcmath()->bc_fmod($a = 5.75, $b = 2, 2);
    $theDebug->dump_all_value([ 'bc_fmod', $a, $b, (string) $result, $result ]);
    $result = \Gzhegow\Lib\Lib::bcmath()->bc_fmod($a = -5.75, $b = 2, 2);
    $theDebug->dump_all_value([ 'bc_fmod', $a, $b, (string) $result, $result ]);
    $result = \Gzhegow\Lib\Lib::bcmath()->bc_fmod($a = 5.75, $b = 2.25, 2);
    $theDebug->dump_all_value([ 'bc_fmod', $a, $b, (string) $result, $result ]);
    $result = \Gzhegow\Lib\Lib::bcmath()->bc_fmod($a = -5.75, $b = 2.25, 2);
    $theDebug->dump_all_value([ 'bc_fmod', $a, $b, (string) $result, $result ]);
    echo "\n";
    echo "\n";


    $result = \Gzhegow\Lib\Lib::bcmath()->bc_gcd(8, 12);
    $theDebug->dump_all_value([ 'bc_gcd', 8, 12, (string) $result, $result ]);
    $result = \Gzhegow\Lib\Lib::bcmath()->bc_gcd(7, 13);
    $theDebug->dump_all_value([ 'bc_gcd', 7, 13, (string) $result, $result ]);
    echo "\n";

    $result = \Gzhegow\Lib\Lib::bcmath()->bc_lcm(8, 6);
    $theDebug->dump_all_value([ 'bc_lcm', 8, 6, (string) $result, $result ]);
    $result = \Gzhegow\Lib\Lib::bcmath()->bc_lcm(8, 5);
    $theDebug->dump_all_value([ 'bc_lcm', 8, 5, (string) $result, $result ]);
    $result = \Gzhegow\Lib\Lib::bcmath()->bc_lcm(8, 10);
    $theDebug->dump_all_value([ 'bc_lcm', 8, 10, (string) $result, $result ]);
    echo "\n";
    echo "\n";


    $values = [];
    $values[] = [
        -2.4,
        -2.04,
        -2.004,
        -1.4,
        -1.04,
        -1.004,
        -0.4,
        -0.04,
        -0.004,
        0,
        0.004,
        0.04,
        0.4,
        1.004,
        1.04,
        1.4,
        2.004,
        2.04,
        2.4,
    ];
    $values[] = [
        -2.5,
        -2.05,
        -2.005,
        -1.5,
        -1.05,
        -1.005,
        -0.5,
        -0.05,
        -0.005,
        0,
        0.005,
        0.05,
        0.5,
        1.005,
        1.05,
        1.5,
        2.005,
        2.05,
        2.5,
    ];
    $values[] = [
        -2.6,
        -2.06,
        -2.006,
        -1.6,
        -1.06,
        -1.006,
        -0.6,
        -0.06,
        -0.006,
        0,
        0.006,
        0.06,
        0.6,
        1.006,
        1.06,
        1.6,
        2.006,
        2.06,
        2.6,
    ];

    $scales = [ 0, 2 ];

    $modes = [];
    $modes['ROUNDING'] = [
        'R_AWAY_FROM_ZERO'  => _NUM_ROUND_AWAY_FROM_ZERO,
        'R_TOWARD_ZERO'     => _NUM_ROUND_TOWARD_ZERO,
        'R_TO_POSITIVE_INF' => _NUM_ROUND_TO_POSITIVE_INF,
        'R_TO_NEGATIVE_INF' => _NUM_ROUND_TO_NEGATIVE_INF,
        'R_EVEN'            => _NUM_ROUND_EVEN,
        'R_ODD'             => _NUM_ROUND_ODD,
    ];


    // $dumpPath = __DIR__ . '/../var/dump/bc_mathround_2.txt';
    // if (is_file($dumpPath)) unlink($dumpPath);

    foreach ( $values as $array ) {
        $table = [];
        foreach ( $array as $v ) {
            foreach ( $scales as $scale ) {
                foreach ( $modes['ROUNDING'] as $n => $f ) {
                    $vString = $theDebug->print_value($v);

                    $nString = ".{$scale}|{$n}";

                    $res = \Gzhegow\Lib\Lib::bcmath()->bc_mathround(
                        $v, $scale,
                        $f, $f
                    );

                    $resString = $theDebug->print_value((string) $res);

                    $table[$nString][$vString] = $resString;
                }
            }
        }

        // $content = $theDebug->dump_table($table, 1);
        // file_put_contents($dumpPath, $content . "\n" . "\n", FILE_APPEND);

        // dump($theDebug->dump_table($table, 1));
        echo md5(serialize($table)) . "\n";
    }


    // $dumpPath = __DIR__ . '/../var/dump/bc_moneyround_2.txt';
    // if (is_file($dumpPath)) unlink($dumpPath);

    foreach ( $values as $array ) {
        $table = [];
        foreach ( $array as $v ) {
            foreach ( $scales as $scale ) {
                foreach ( $modes['ROUNDING'] as $n => $f ) {
                    $vString = $theDebug->print_value($v);

                    $nString = ".{$scale}|{$n}";

                    $res = \Gzhegow\Lib\Lib::bcmath()->bc_moneyround(
                        $v, $scale,
                        $f, $f
                    );

                    $resString = $theDebug->print_value((string) $res);

                    $table[$nString][$vString] = $resString;
                }
            }
        }

        // $content = $theDebug->dump_table($table, 1);
        // file_put_contents($dumpPath, $content . "\n" . "\n", FILE_APPEND);

        // dump($theDebug->dump_table($table, 1));
        echo md5(serialize($table)) . "\n";
    }
};
$test = $theTest->newCase($fn);
$test->expectStdout('
"[ BcmathModule ]"

"bc_abs" | 0 | "0" | { object(stringable) # Gzhegow\Lib\Modules\Bcmath\Bcnumber }
"bc_abs" | 1.005 | "1.005" | { object(stringable) # Gzhegow\Lib\Modules\Bcmath\Bcnumber }
"bc_abs" | -1.005 | "1.005" | { object(stringable) # Gzhegow\Lib\Modules\Bcmath\Bcnumber }

"bc_ceil" | 0 | "0" | { object(stringable) # Gzhegow\Lib\Modules\Bcmath\Bcnumber }
"bc_ceil" | 1.005 | "2" | { object(stringable) # Gzhegow\Lib\Modules\Bcmath\Bcnumber }
"bc_ceil" | -1.005 | "-1" | { object(stringable) # Gzhegow\Lib\Modules\Bcmath\Bcnumber }

"bc_floor" | 0 | "0" | { object(stringable) # Gzhegow\Lib\Modules\Bcmath\Bcnumber }
"bc_floor" | 1.005 | "1" | { object(stringable) # Gzhegow\Lib\Modules\Bcmath\Bcnumber }
"bc_floor" | -1.005 | "-2" | { object(stringable) # Gzhegow\Lib\Modules\Bcmath\Bcnumber }


"bc_add" | 1.123 | 1.456 | "2.5" | "0.079" | { object(stringable) # Gzhegow\Lib\Modules\Bcmath\Bcnumber }
"bc_sub" | 1.456 | 1.123 | "0.3" | "0.033" | { object(stringable) # Gzhegow\Lib\Modules\Bcmath\Bcnumber }
"bc_mul" | 1.456 | 3 | "4.3" | "0.068" | { object(stringable) # Gzhegow\Lib\Modules\Bcmath\Bcnumber }
"bc_div" | 4.777 | 3 | "1.5" | "0.09233" | { object(stringable) # Gzhegow\Lib\Modules\Bcmath\Bcnumber }

"bc_pow" | 4.777 | 2 | "22.8" | "0.019729" | { object(stringable) # Gzhegow\Lib\Modules\Bcmath\Bcnumber }
"bc_sqrt" | 4.777 | "2.18" | "0.005634" | { object(stringable) # Gzhegow\Lib\Modules\Bcmath\Bcnumber }


"bc_mod" | 5.75 | 2 | "1" | { object(stringable) # Gzhegow\Lib\Modules\Bcmath\Bcnumber }
"bc_mod" | -5.75 | 2 | "-1" | { object(stringable) # Gzhegow\Lib\Modules\Bcmath\Bcnumber }
"bc_mod" | 5.75 | 2.25 | "1" | { object(stringable) # Gzhegow\Lib\Modules\Bcmath\Bcnumber }
"bc_mod" | -5.75 | 2.25 | "-1" | { object(stringable) # Gzhegow\Lib\Modules\Bcmath\Bcnumber }

"bc_fmod" | 5.75 | 2 | "1.75" | { object(stringable) # Gzhegow\Lib\Modules\Bcmath\Bcnumber }
"bc_fmod" | -5.75 | 2 | "-1.75" | { object(stringable) # Gzhegow\Lib\Modules\Bcmath\Bcnumber }
"bc_fmod" | 5.75 | 2.25 | "1.25" | { object(stringable) # Gzhegow\Lib\Modules\Bcmath\Bcnumber }
"bc_fmod" | -5.75 | 2.25 | "-1.25" | { object(stringable) # Gzhegow\Lib\Modules\Bcmath\Bcnumber }


"bc_gcd" | 8 | 12 | "4" | { object(stringable) # Gzhegow\Lib\Modules\Bcmath\Bcnumber }
"bc_gcd" | 7 | 13 | "1" | { object(stringable) # Gzhegow\Lib\Modules\Bcmath\Bcnumber }

"bc_lcm" | 8 | 6 | "24" | { object(stringable) # Gzhegow\Lib\Modules\Bcmath\Bcnumber }
"bc_lcm" | 8 | 5 | "40" | { object(stringable) # Gzhegow\Lib\Modules\Bcmath\Bcnumber }
"bc_lcm" | 8 | 10 | "40" | { object(stringable) # Gzhegow\Lib\Modules\Bcmath\Bcnumber }


2a521995645a33b211fe8d256de4fc1e
3fbd1316b366e26ca5f2a655052a772a
74cdbaa3f5de6194337fb075c5eae9ff
099579a899298f5e03f36377c9412a30
5b9a198f45fc24ba897b0627a38397fe
3ad9e060542787e4b0eac224a6044986
');
$test->run();



// >>> TEST
// > тесты CmpModule
$fn = function () use ($theDebug) {
    $theDebug->dump_value('[ CmpModule ]');
    echo "\n";

    $object = new \StdClass();

    $resourceOpenedStdout = \Gzhegow\Lib\Lib::php()->stdout();
    $resourceOpenedStderr = \Gzhegow\Lib\Lib::php()->stderr();
    $resourceClosed = fopen('php://memory', 'wb');
    fclose($resourceClosed);

    $valuesXX = [
        0  => [
            NAN,
            null,
            new \Gzhegow\Lib\Modules\Php\Nil(),
        ],
        1  => [
            ((string) NAN),
            'NULL',
            ((string) (new \Gzhegow\Lib\Modules\Php\Nil())),
        ],
        2  => [
            false,
            true,
        ],
        3  => [
            0,
            1,
        ],
        4  => [
            0.0,
            1.0,
            1.1,
            1e1,
            1.1e1, // 11
            1.1e-1, // 0.11
        ],
        5  => [
            PHP_INT_MAX, // > int
            PHP_INT_MIN, // > int
            (PHP_INT_MAX + 1), // > float
            (PHP_INT_MIN - 1), // > float
        ],
        6  => [
            PHP_FLOAT_MAX,
            -PHP_FLOAT_MAX,
            //
            // > практическая польза нулевая, но для проверки дополнительный вызов и куча работы со строками
            // PHP_FLOAT_MIN,
            // -PHP_FLOAT_MIN,
        ],
        7  => [
            INF,
            -INF,
        ],
        8  => [
            '',
            'a',
            'b',
            'ab',
            'ba',
        ],
        9  => [
            '0',
            '1',
        ],
        10 => [
            '0.0',
            '1.0',
            '1.1',
            '1e1',
            '1.1e1', // 11
            '1.1e-1', // 0.11
        ],
        11 => [
            ((string) PHP_INT_MAX), // > int
            ((string) PHP_INT_MIN), // > int
            ((string) (PHP_INT_MAX + 1)), // > float
            ((string) (PHP_INT_MIN - 1)), // > float
        ],
        12 => [
            ((string) PHP_FLOAT_MAX),
            ((string) (-PHP_FLOAT_MAX)),
            //
            // > практическая польза нулевая, но для проверки дополнительный вызов и куча работы со строками
            // ((string) PHP_FLOAT_MIN),
            // ((string) (-PHP_FLOAT_MIN)),
        ],
        13 => [
            ((string) INF),
            ((string) -INF),
        ],
        14 => [
            $resourceOpenedStdout,
            $resourceOpenedStderr,
            $resourceClosed,
        ],
        15 => [
            [],
            [ '' ],
            [ 'a' ],
            [ 'a', 'b' ],
        ],
        16 => [
            (new \DateTime('1970-01-01 00:00:00')),
            (new \DateTime('1970-01-01 00:00:01')),
            (new \DateTime('1970-01-01 00:00:01'))->modify('+500ms'),
        ],
        17 => [
            $object,
            new \StdClass(),
        ],
        18 => [
            (object) [],
            (object) [ '' ],
            (object) [ 'a' ],
            (object) [ 'a', 'b' ],
        ],
        19 => [
            new ArrayObject([]),
            new ArrayObject([ '' ]),
            new ArrayObject([ 'a' ]),
            new ArrayObject([ 'a', 'b' ]),
        ],
    ];


    $valuesYY = $valuesXX;

    // > commented, should be the same object
    // $valuesYY[ 17 ][ 0 ] = clone $valuesYY[ 17 ][ 0 ];
    //
    $valuesYY[17][1] = clone $valuesYY[17][1];
    $valuesYY[18][0] = clone $valuesYY[18][0];
    $valuesYY[18][1] = clone $valuesYY[18][1];
    $valuesYY[18][2] = clone $valuesYY[18][2];
    $valuesYY[18][3] = clone $valuesYY[18][3];
    $valuesYY[19][0] = clone $valuesYY[19][0];
    $valuesYY[19][1] = clone $valuesYY[19][1];
    $valuesYY[19][2] = clone $valuesYY[19][2];
    $valuesYY[19][3] = clone $valuesYY[19][3];

    $valuesY = array_merge(...$valuesYY);

    $theCmp = \Gzhegow\Lib\Lib::cmp();

    $fnCmpName = null;
    $fnCmpSizeName = null;

    $fnCmp = $theCmp->fnCompareValues(
        _CMP_MODE_TYPE_TYPECAST_OR_CONTINUE | _CMP_MODE_DATE_VS_SEC,
        _CMP_RESULT_NAN_RETURN,
        [ &$fnCmpName ]
    );
    $fnCmpSize = $theCmp->fnCompareSizes(
        _CMP_MODE_TYPE_TYPECAST_OR_CONTINUE | _CMP_MODE_DATE_VS_SEC,
        _CMP_RESULT_NAN_RETURN,
        [ &$fnCmpSizeName ]
    );


    // $dumpPath = __DIR__ . '/../var/dump/cmp_fn_compare_2.txt';
    // if ( is_file($dumpPath) ) unlink($dumpPath);

    $xi = 0;
    foreach ( $valuesXX as $valuesX ) {
        $table = [];
        $tableSize = [];
        foreach ( $valuesX as $x ) {
            $xKey = "A@{$xi} | " . $theDebug->print_value($x);

            $yi = 0;
            foreach ( $valuesY as $y ) {
                $yKey = "B@{$yi} | " . $theDebug->print_value($y);

                $result = $fnCmp($x, $y);
                $resultSize = $fnCmpSize($x, $y);

                $row = $yKey;
                $col = $xKey;

                $table[$row][$col] = "{$result} ? {$fnCmpName}";
                $tableSize[$row][$col] = "{$resultSize} ? {$fnCmpSizeName}";

                $yi++;
            }

            $xi++;
        }

        // $content = $theDebug->dump_table($table, 1);
        // file_put_contents($dumpPath, $content . "\n" . "\n", FILE_APPEND);

        // dd($theDebug->dump_table($table, 1));
        // dd($theDebug->dump_table($tableSize, 1));
        echo md5(serialize($table)) . "\n";
        echo md5(serialize($tableSize)) . "\n";
        echo "\n";
    }
    unset($table);
};
$test = $theTest->newCase($fn);
$test->expectStdoutIf(PHP_VERSION_ID >= 80200, '
"[ CmpModule ]"

8fb8614dff541044ba946a4163a2e607
8fb8614dff541044ba946a4163a2e607

d827876272749d840cc3d9f1039376ca
527257dcc105a7e6f440e53234a3a8c2

b8f55599f99d468259a5b42a4f06e3cf
bee34c6dc82128567cb48d42130a2ab5

ae89a652942f04701f6b8ee224d8536a
24103e0a5985953a83e932e8638e220c

79a6e40f32634b7ca333eae8c1474368
79d78c1d9c89bae865f1f261e4e3b27b

37f9ec7049b61cb5658c1ed9bf85016e
8d3f5fd785c7ae4ea8eda649e2e8f6ba

f685db70cfdafd6c189e4dc5c9625b25
cf9d1a8041ae85e0b171f978f4eec426

4ac6e9f08bc3d58a95df48b894d6586a
5f33e1430202634f76f82b69f27678e4

e7730b1480752e67c3ea56315777b3a6
c0cddeffa5d533a217a9d672d3bf304c

5e592b2dc710665901c138fab618bf40
7977561d2cbbde4003338e894dca0211

1671741996021a4fb708c74b574e0d5b
2bdf896eabc81db36c4b114eb311b066

7c759f1ebfa86d5f07dcedb5e1889198
c8245d3f5f85c5ba98b6743e181f1122

6a40b69e48bb9e408392e526ed85d3cc
ca68cae9c52866ee00fa192fdecced1d

81d3c9fa3b5b062a5c6ac6b84de62950
32cd397000640521e4d76249f32a7cf3

d6ecb6a5a28210a689446791d099898f
f32620cf3eb0ef614c0b50c19c072cb8

064e364eff28a530b65c90420a66a7e1
12143f37cfeab922f3e022e9f291fadb

521de67cba5795f6e9b4470ba1911824
1aa12fa0b41b27e82019866138dabd00

0c0e2975240da648f7359cadd162e823
1c26fc92987fbacf13db735c9a1f6657

b682bdec6ff275892eddac3beadd484a
431dba0d82d272badbfeaaa55a16e1a4

483e929cad8a50735cd35ecb14e458c3
9d75f52bea268860e1681d086aa1347b
');
$test->expectStdoutIf(PHP_VERSION_ID < 80200, '
"[ CmpModule ]"

867bed6e3303e24dbccb6ae1b6258af8
867bed6e3303e24dbccb6ae1b6258af8

69119b8480591f23003b7874ef18b27e
d21ffa4bad46198ca8d8b6fb20e53bab

f406f7301eccbe2369c4f92d978f9bc7
adef371ec1265997c1827318a608da70

80bf152dd6110f6db2eddfa9a9820e0a
296dffb822ba2fac9fb187c15dbc58c4

524446451ea078538c22d16ffc7407ca
407bae8306a462f7dd31df7665eb972d

b193d867e2e9b8772a023957abcd5ab3
782616ba9f2625836305d5edb27af988

f00da4909ce845822117c16f3c6c88b0
8098cc141981c63dd8355a293753830f

4a5ef57f9986cbcdec1d494f3050be01
894c42a801d4e56097631551604dc2a8

48466412af0bd08583e780b384d65a66
a35364fe29a89dda89115f9fb3384099

890e8c5e276e9f2eec402b3dfed584b1
542043204ae96d41c33e8c033cae7efa

40c859a0d73f4011c49e1882509756cc
e284771d933a66eade1276eba33e9084

2b7ea99ae7905e70effe8bf1913766a4
51a846b570526767249465433872c2d4

56a4ff1e86d1be6d217714b2dfa7b640
0e5d455db540c2bbb141870838dc5ff9

0f86bcbd6f04d347357baf0ad5da0cc6
9ee81ed5ebe9742c6f547b270a8d57b4

34c94919a67eadd6474e8abd0263615f
79a0cfcdcf951eb8224909acdb023fa5

07d82cb5793b234948704d7c20cb284d
ae8e6667b484151355fa92c069d5793d

28af9f04c7a2fe85694346d7c3fb656c
0be8825df3990cb351c9ee783a973fe7

84fb8d665403f3f9888af1ae21b6f312
9cd36898bc84a243e8e2ce31438cd56e

098809dc22f412bb928ba7a09bc440f3
4a670c00a1630c13602f50cf223ad984

eb95474cce527e8a7277b32231834b87
061f86a33a3b0809ef62560789f80116
');
$test->run();



// >>> TEST
// > тесты CryptModule
$fn = function () use ($theDebug) {
    $theDebug->dump_value('[ CryptModule ]');
    echo "\n";


    $algos = [
        'fnv1a32',
        'crc32',
        'md5',
        'sha1',
        'sha256',
    ];
    $src = 'hello world!';
    foreach ( $algos as $algo ) {
        $isModeBinary = false;
        $enc = \Gzhegow\Lib\Lib::crypt()->hash($algo, $src, $isModeBinary);
        $status = \Gzhegow\Lib\Lib::crypt()->hash_equals($enc, $algo, $src, $isModeBinary);
        $theDebug->dump_all_value([ $src, $enc, $status ]);

        $isModeBinary = true;
        $enc = \Gzhegow\Lib\Lib::crypt()->hash($algo, $src, $isModeBinary);
        $status = \Gzhegow\Lib\Lib::crypt()->hash_equals($enc, $algo, $src, $isModeBinary);
        $theDebug->dump_all_value([ $src, $enc, $status ]);

        echo "\n";
    }


    $src = 0;
    $enc = \Gzhegow\Lib\Lib::crypt()->dec2numbase($src, '01');
    $dec = \Gzhegow\Lib\Lib::crypt()->numbase2dec($enc, '01');
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    $src = 3;
    $enc = \Gzhegow\Lib\Lib::crypt()->dec2numbase($src, '01');
    $dec = \Gzhegow\Lib\Lib::crypt()->numbase2dec($enc, '01');
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    $src = 0;
    $enc = \Gzhegow\Lib\Lib::crypt()->dec2numbase($src, '01234567');
    $dec = \Gzhegow\Lib\Lib::crypt()->numbase2dec($enc, '01234567');
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    $src = 15;
    $enc = \Gzhegow\Lib\Lib::crypt()->dec2numbase($src, '01234567');
    $dec = \Gzhegow\Lib\Lib::crypt()->numbase2dec($enc, '01234567');
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    $src = 0;
    $enc = \Gzhegow\Lib\Lib::crypt()->dec2numbase($src, '0123456789ABCDEF');
    $dec = \Gzhegow\Lib\Lib::crypt()->numbase2dec($enc, '0123456789ABCDEF');
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    $src = 31;
    $enc = \Gzhegow\Lib\Lib::crypt()->dec2numbase($src, '0123456789ABCDEF');
    $dec = \Gzhegow\Lib\Lib::crypt()->numbase2dec($enc, '0123456789ABCDEF');
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    echo "\n";


    $isOneBased = false;
    $src = 0;
    $enc = \Gzhegow\Lib\Lib::crypt()->dec2numbase($src, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', $isOneBased);
    $dec = \Gzhegow\Lib\Lib::crypt()->numbase2dec($enc, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', $isOneBased);
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    $isOneBased = false;
    $src = 10;
    $enc = \Gzhegow\Lib\Lib::crypt()->dec2numbase($src, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', $isOneBased);
    $dec = \Gzhegow\Lib\Lib::crypt()->numbase2dec($enc, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', $isOneBased);
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    $isOneBased = false;
    $src = 25;
    $enc = \Gzhegow\Lib\Lib::crypt()->dec2numbase($src, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', $isOneBased);
    $dec = \Gzhegow\Lib\Lib::crypt()->numbase2dec($enc, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', $isOneBased);
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    $isOneBased = false;
    $src = 26;
    $enc = \Gzhegow\Lib\Lib::crypt()->dec2numbase($src, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', $isOneBased);
    $dec = \Gzhegow\Lib\Lib::crypt()->numbase2dec($enc, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', $isOneBased);
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    echo "\n";


    $isOneBased = true;
    $src = 0;
    try {
        \Gzhegow\Lib\Lib::crypt()->dec2numbase($src, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', $isOneBased);
    }
    catch ( \Throwable $e ) {
        $theDebug->dump_all_value([ $src, '[ CATCH ] ' . $e->getMessage() ]);
    }

    $isOneBased = true;
    $src = 10;
    $enc = \Gzhegow\Lib\Lib::crypt()->dec2numbase($src, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', $isOneBased);
    $dec = \Gzhegow\Lib\Lib::crypt()->numbase2dec($enc, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', $isOneBased);
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    $isOneBased = true;
    $src = 26;
    $enc = \Gzhegow\Lib\Lib::crypt()->dec2numbase($src, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', $isOneBased);
    $dec = \Gzhegow\Lib\Lib::crypt()->numbase2dec($enc, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', $isOneBased);
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    $isOneBased = true;
    $src = 27;
    $enc = \Gzhegow\Lib\Lib::crypt()->dec2numbase($src, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', $isOneBased);
    $dec = \Gzhegow\Lib\Lib::crypt()->numbase2dec($enc, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', $isOneBased);
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    echo "\n";


    $src = '2147483647';
    $enc = \Gzhegow\Lib\Lib::crypt()->numbase2numbase($src, '0123456789', '0123456789');
    $dec = \Gzhegow\Lib\Lib::crypt()->numbase2numbase('9223372036854775807', '0123456789', '0123456789');
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    $src = '2147483647';
    $enc = \Gzhegow\Lib\Lib::crypt()->numbase2numbase($src, '0123456789abcdefghijklmnopqrstuvwxyz', '0123456789');
    $dec = \Gzhegow\Lib\Lib::crypt()->numbase2numbase($enc, '0123456789', '0123456789abcdefghijklmnopqrstuvwxyz');
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    $src = '9223372036854775807';
    $enc = \Gzhegow\Lib\Lib::crypt()->numbase2numbase($src, '0123456789abcdefghijklmnopqrstuvwxyz', '0123456789');
    $dec = \Gzhegow\Lib\Lib::crypt()->numbase2numbase($enc, '0123456789', '0123456789abcdefghijklmnopqrstuvwxyz');
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    echo "\n";


    $encArray = [];
    $encArray[] = \Gzhegow\Lib\Lib::crypt()->bin2binbase('1', '01');
    $encArray[] = \Gzhegow\Lib\Lib::crypt()->bin2binbase('11', '0123');
    $encArray[] = \Gzhegow\Lib\Lib::crypt()->bin2binbase('111', '01234567');
    $encArray[] = \Gzhegow\Lib\Lib::crypt()->bin2binbase('1111', '0123456789ABCDEF');
    $encArray[] = \Gzhegow\Lib\Lib::crypt()->bin2binbase('11111', '0123456789ABCDEFGHIJKLMNOPQRSTUV');
    $encArray[] = \Gzhegow\Lib\Lib::crypt()->bin2binbase('111111', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/');
    $theDebug->dump_value($encArray);
    echo "\n";


    $src = [ '你' ];
    $enc = \Gzhegow\Lib\Lib::crypt()->text2bin($src);
    $dec = \Gzhegow\Lib\Lib::crypt()->bin2text($enc);
    $theDebug->dump_array($src);
    $theDebug->dump_array($enc);
    $theDebug->dump_array($dec);
    echo "\n";

    $src = [ '你好' ];
    $enc = \Gzhegow\Lib\Lib::crypt()->text2bin($src);
    $dec = \Gzhegow\Lib\Lib::crypt()->bin2text($enc);
    $theDebug->dump_array($src);
    $theDebug->dump_array($enc);
    $theDebug->dump_array($dec);
    echo "\n";


    echo "\n";


    $src = 5678;
    $bin = decbin($src);
    $enc = \Gzhegow\Lib\Lib::crypt()->bin2binbase($bin, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/');
    $dec = \Gzhegow\Lib\Lib::crypt()->binbase2bin($enc, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/');
    $res = bindec($dec);
    $theDebug->dump_all_value([ $src, $bin, $enc, $dec, $res ]);
    echo "\n";

    $src = [ 'hello' ];
    $bin = \Gzhegow\Lib\Lib::crypt()->text2bin($src);
    $enc = \Gzhegow\Lib\Lib::crypt()->bin2base($bin, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/');
    $dec = \Gzhegow\Lib\Lib::crypt()->base2bin($enc, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/');
    $res = implode('', array_map('chr', array_map('bindec', $dec)));
    $theDebug->dump_array($src);
    $theDebug->dump_array($bin);
    $theDebug->dump_value($enc);
    $theDebug->dump_array($dec);
    $theDebug->dump_value($res);
    echo "\n";


    echo "\n";


    $src = "hello";
    $enc = \Gzhegow\Lib\Lib::crypt()->base58_encode($src);
    $dec = \Gzhegow\Lib\Lib::crypt()->base58_decode($enc);
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    $src = "\x00\x00\x01\x00\xFF";
    $enc = \Gzhegow\Lib\Lib::crypt()->base58_encode($src);
    $dec = \Gzhegow\Lib\Lib::crypt()->base58_decode($enc);
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    $src = "你好";
    $enc = \Gzhegow\Lib\Lib::crypt()->base58_encode($src);
    $dec = \Gzhegow\Lib\Lib::crypt()->base58_decode($enc);
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    echo "\n";
    echo "\n";


    $src = "hello";
    $enc = \Gzhegow\Lib\Lib::crypt()->base62_encode($src);
    $dec = \Gzhegow\Lib\Lib::crypt()->base62_decode($enc);
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    $src = "\x00\x00\x01\x00\xFF";
    $enc = \Gzhegow\Lib\Lib::crypt()->base62_encode($src);
    $dec = \Gzhegow\Lib\Lib::crypt()->base62_decode($enc);
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    $src = '你好';
    $enc = \Gzhegow\Lib\Lib::crypt()->base62_encode($src);
    $dec = \Gzhegow\Lib\Lib::crypt()->base62_decode($enc);
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    echo "\n";
    echo "\n";


    $src = "hello";
    $enc = \Gzhegow\Lib\Lib::crypt()->base64_encode($src);
    $dec = \Gzhegow\Lib\Lib::crypt()->base64_decode($enc);
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    $src = "\x00\x00\x01\x00\xFF";
    $enc = \Gzhegow\Lib\Lib::crypt()->base64_encode($src);
    $dec = \Gzhegow\Lib\Lib::crypt()->base64_decode($enc);
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    $src = '你好';
    $enc = \Gzhegow\Lib\Lib::crypt()->base64_encode($src);
    $dec = \Gzhegow\Lib\Lib::crypt()->base64_decode($enc);
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    echo "\n";


    $src = "hello";
    $gen = \Gzhegow\Lib\Lib::crypt()->base64_encode_it($src);
    $enc = implode('', iterator_to_array($gen));
    $gen = \Gzhegow\Lib\Lib::crypt()->base64_decode_it($enc);
    $dec = implode('', iterator_to_array($gen));
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    $src = "\x00\x00\x01\x00\xFF";
    $gen = \Gzhegow\Lib\Lib::crypt()->base64_encode_it($src);
    $enc = implode('', iterator_to_array($gen));
    $gen = \Gzhegow\Lib\Lib::crypt()->base64_decode_it($enc);
    $dec = implode('', iterator_to_array($gen));
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    $src = "你好";
    $gen = \Gzhegow\Lib\Lib::crypt()->base64_encode_it($src);
    $enc = implode('', iterator_to_array($gen));
    $gen = \Gzhegow\Lib\Lib::crypt()->base64_decode_it($enc);
    $dec = implode('', iterator_to_array($gen));
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    echo "\n";
    echo "\n";


    $src = "hello";
    $enc = \Gzhegow\Lib\Lib::crypt()->base64_encode_urlsafe($src);
    $dec = \Gzhegow\Lib\Lib::crypt()->base64_decode_urlsafe($enc);
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    $src = "\x00\x00\x01\x00\xFF";
    $enc = \Gzhegow\Lib\Lib::crypt()->base64_encode_urlsafe($src);
    $dec = \Gzhegow\Lib\Lib::crypt()->base64_decode_urlsafe($enc);
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    $src = '你好';
    $enc = \Gzhegow\Lib\Lib::crypt()->base64_encode_urlsafe($src);
    $dec = \Gzhegow\Lib\Lib::crypt()->base64_decode_urlsafe($enc);
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    $src = 'this+is/a?string=with&special=characters==';
    $enc = \Gzhegow\Lib\Lib::crypt()->base64_encode_urlsafe($src);
    $dec = \Gzhegow\Lib\Lib::crypt()->base64_decode_urlsafe($enc);
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    $src = "\xfa\xfb\xfc\xfd\xfe\xff";
    $enc = \Gzhegow\Lib\Lib::crypt()->base64_encode_urlsafe($src);
    $dec = \Gzhegow\Lib\Lib::crypt()->base64_decode_urlsafe($enc);
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    echo "\n";


    $src = "hello";
    $gen = \Gzhegow\Lib\Lib::crypt()->base64_encode_urlsafe_it($src);
    $enc = implode('', iterator_to_array($gen));
    $gen = \Gzhegow\Lib\Lib::crypt()->base64_decode_urlsafe_it($enc);
    $dec = implode('', iterator_to_array($gen));
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    $src = "\x00\x00\x01\x00\xFF";
    $gen = \Gzhegow\Lib\Lib::crypt()->base64_encode_urlsafe_it($src);
    $enc = implode('', iterator_to_array($gen));
    $gen = \Gzhegow\Lib\Lib::crypt()->base64_decode_urlsafe_it($enc);
    $dec = implode('', iterator_to_array($gen));
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    $src = "你好";
    $gen = \Gzhegow\Lib\Lib::crypt()->base64_encode_urlsafe_it($src);
    $enc = implode('', iterator_to_array($gen));
    $gen = \Gzhegow\Lib\Lib::crypt()->base64_decode_urlsafe_it($enc);
    $dec = implode('', iterator_to_array($gen));
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    $src = "this+is/a?string=with&special=characters==";
    $gen = \Gzhegow\Lib\Lib::crypt()->base64_encode_urlsafe_it($src);
    $enc = implode('', iterator_to_array($gen));
    $gen = \Gzhegow\Lib\Lib::crypt()->base64_decode_urlsafe_it($enc);
    $dec = implode('', iterator_to_array($gen));
    $theDebug->dump_all_value([ $src, $enc, $dec ]);

    $src = "\xfa\xfb\xfc\xfd\xfe\xff";
    $gen = \Gzhegow\Lib\Lib::crypt()->base64_encode_urlsafe_it($src);
    $enc = implode('', iterator_to_array($gen));
    $gen = \Gzhegow\Lib\Lib::crypt()->base64_decode_urlsafe_it($enc);
    $dec = implode('', iterator_to_array($gen));
    $theDebug->dump_all_value([ $src, $enc, $dec ]);
};
$test = $theTest->newCase($fn);
$test->expectStdout('
"[ CryptModule ]"

"hello world!" | "b034fff2" | TRUE
"hello world!" | "b`°4ÿò`" | TRUE

"hello world!" | "b79584fd" | TRUE
"hello world!" | "b`·•„ý`" | TRUE

"hello world!" | "fc3ff98e8c6a0d3087d515c0473f8677" | TRUE
"hello world!" | "b`ü?ùŽŒj\r0‡Õ\x15ÀG?†w`" | TRUE

"hello world!" | "430ce34d020724ed75a196dfc2ad67c77772d169" | TRUE
"hello world!" | "b`C\x0CãM\x02\x07$íu¡–ß­gÇwrÑi`" | TRUE

"hello world!" | "7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9" | TRUE
"hello world!" | "b`u\tå½ ÇbÒºÇù\ru‹[\"cú\x01̼T*µãß\x16;àŽl©`" | TRUE

0 | "0" | "0"
3 | "11" | "3"
0 | "0" | "0"
15 | "17" | "15"
0 | "0" | "0"
31 | "1F" | "31"

0 | "A" | "0"
10 | "K" | "10"
25 | "Z" | "25"
26 | "BA" | "26"

0 | "[ CATCH ] The `decInteger` should be GT 0 due to `oneBasedTo` is set to TRUE"
10 | "J" | "10"
26 | "Z" | "26"
27 | "AA" | "27"

"2147483647" | "2147483647" | "9223372036854775807"
"2147483647" | "zik0zj" | "2147483647"
"9223372036854775807" | "1y2p0ij32e8e7" | "9223372036854775807"

[ "1", "3", "7", "F", "V", "/" ]

[ "你" ]
[ "11100100", "10111101", "10100000" ]
[ "你" ]

[ "你好" ]
[ "11100100", "10111101", "10100000", "11100101", "10100101", "10111101" ]
[ "你", "好" ]


5678 | "1011000101110" | "uYB" | "0001011000101110" | 5678

[ "hello" ]
[ "01101000", "01100101", "01101100", "01101100", "01101111" ]
"aGVsbG8"
[ "01101000", "01100101", "01101100", "01101100", "01101111" ]
"hello"


"hello" | "Cn8eVZg" | "hello"
"b`\x00\x00\x01\x00ÿ`" | "11LZL" | "b`\x00\x00\x01\x00ÿ`"
"你好" | "2xuZUfBKa" | "你好"


"hello" | "7tQLFHz" | "hello"
"b`\x00\x00\x01\x00ÿ`" | "00H79" | "b`\x00\x00\x01\x00ÿ`"
"你好" | "19PqtKE1t" | "你好"


"hello" | "aGVsbG8=" | "hello"
"b`\x00\x00\x01\x00ÿ`" | "AAABAP8=" | "b`\x00\x00\x01\x00ÿ`"
"你好" | "5L2g5aW9" | "你好"

"hello" | "aGVsbG8=" | "hello"
"b`\x00\x00\x01\x00ÿ`" | "AAABAP8=" | "b`\x00\x00\x01\x00ÿ`"
"你好" | "5L2g5aW9" | "你好"


"hello" | "aGVsbG8=" | "hello"
"b`\x00\x00\x01\x00ÿ`" | "AAABAP8=" | "b`\x00\x00\x01\x00ÿ`"
"你好" | "5L2g5aW9" | "你好"
"this+is/a?string=with&special=characters==" | "dGhpcytpcy9hP3N0cmluZz13aXRoJnNwZWNpYWw9Y2hhcmFjdGVycz09" | "this+is/a?string=with&special=characters=="
"b`úûüýþÿ`" | "-vv8_f7_" | "b`úûüýþÿ`"

"hello" | "aGVsbG8=" | "hello"
"b`\x00\x00\x01\x00ÿ`" | "AAABAP8=" | "b`\x00\x00\x01\x00ÿ`"
"你好" | "5L2g5aW9" | "你好"
"this+is/a?string=with&special=characters==" | "dGhpcytpcy9hP3N0cmluZz13aXRoJnNwZWNpYWw9Y2hhcmFjdGVycz09" | "this+is/a?string=with&special=characters=="
"b`úûüýþÿ`" | "-vv8_f7_" | "b`úûüýþÿ`"
');
$test->run();



// >>> TEST
// > тесты DateModule
$fn = function () use ($theDebug) {
    $theDebug->dump_value('[ DateModule ]');
    echo "\n";


    $before = date_default_timezone_get();
    date_default_timezone_set('UTC');


    $status = \Gzhegow\Lib\Lib::date()->type_timezone(null, '+0100')->isOk([ &$dateTimezone ]);
    $theDebug->dump_all_value([ $status, $dateTimezone ]);
    $status = \Gzhegow\Lib\Lib::date()->type_timezone(null, 'EET')->isOk([ &$dateTimezone ]);
    $theDebug->dump_all_value([ $status, $dateTimezone ]);
    $status = \Gzhegow\Lib\Lib::date()->type_timezone(null, 'Europe/Minsk')->isOk([ &$dateTimezone ]);
    $theDebug->dump_all_value([ $status, $dateTimezone ]);
    $status = \Gzhegow\Lib\Lib::date()->type_timezone(null, new \DateTimeZone('UTC'))->isOk([ &$dateTimezone ]);
    $theDebug->dump_all_value([ $status, $dateTimezone ]);
    $status = \Gzhegow\Lib\Lib::date()->type_timezone(null, new \DateTime('now', new \DateTimeZone('UTC')))->isOk([ &$dateTimezone ]);
    $theDebug->dump_all_value([ $status, $dateTimezone ]);
    echo "\n";

    $status = \Gzhegow\Lib\Lib::date()->type_timezone_offset(null, '+0100')->isOk([ &$dateTimezone ]);
    $theDebug->dump_all_value([ $status, $dateTimezone ]);
    $status = \Gzhegow\Lib\Lib::date()->type_timezone_offset(null, new \DateTimeZone('+0100'))->isOk([ &$dateTimezone ]);
    $theDebug->dump_all_value([ $status, $dateTimezone ]);
    $status = \Gzhegow\Lib\Lib::date()->type_timezone_offset(null, new \DateTime('now', new \DateTimeZone('+0100')))->isOk([ &$dateTimezone ]);
    $theDebug->dump_all_value([ $status, $dateTimezone ]);
    echo "\n";

    $status = \Gzhegow\Lib\Lib::date()->type_timezone_abbr(null, 'EET')->isOk([ &$dateTimezone ]);
    $theDebug->dump_all_value([ $status, $dateTimezone ]);
    $status = \Gzhegow\Lib\Lib::date()->type_timezone_abbr(null, new \DateTimeZone('EET'))->isOk([ &$dateTimezone ]);
    $theDebug->dump_all_value([ $status, $dateTimezone ]);
    $status = \Gzhegow\Lib\Lib::date()->type_timezone_abbr(null, new \DateTime('now', new \DateTimeZone('EET')))->isOk([ &$dateTimezone ]);
    $theDebug->dump_all_value([ $status, $dateTimezone ]);
    echo "\n";

    $status = \Gzhegow\Lib\Lib::date()->type_timezone_name(null, 'Europe/Minsk')->isOk([ &$dateTimezone ]);
    $theDebug->dump_all_value([ $status, $dateTimezone ]);
    $status = \Gzhegow\Lib\Lib::date()->type_timezone_name(null, new \DateTimeZone('Europe/Minsk'))->isOk([ &$dateTimezone ]);
    $theDebug->dump_all_value([ $status, $dateTimezone ]);
    $status = \Gzhegow\Lib\Lib::date()->type_timezone_name(null, new \DateTime('now', new \DateTimeZone('Europe/Minsk')))->isOk([ &$dateTimezone ]);
    $theDebug->dump_all_value([ $status, $dateTimezone ]);
    echo "\n";

    $status = \Gzhegow\Lib\Lib::date()->type_timezone_nameabbr(null, 'EET')->isOk([ &$dateTimezone ]);
    $theDebug->dump_all_value([ $status, $dateTimezone ]);
    $status = \Gzhegow\Lib\Lib::date()->type_timezone_nameabbr(null, 'Europe/Minsk')->isOk([ &$dateTimezone ]);
    $theDebug->dump_all_value([ $status, $dateTimezone ]);
    $status = \Gzhegow\Lib\Lib::date()->type_timezone_nameabbr(null, new \DateTimeZone('EET'))->isOk([ &$dateTimezone ]);
    $theDebug->dump_all_value([ $status, $dateTimezone ]);
    $status = \Gzhegow\Lib\Lib::date()->type_timezone_nameabbr(null, new \DateTime('now', new \DateTimeZone('Europe/Minsk')))->isOk([ &$dateTimezone ]);
    $theDebug->dump_all_value([ $status, $dateTimezone ]);
    echo "\n";

    echo "\n";


    $status = \Gzhegow\Lib\Lib::date()->type_interval(null, 'P1D')->isOk([ &$dateInterval ]);
    $theDebug->dump_all_value([ $status, $dateInterval ]);
    $status = \Gzhegow\Lib\Lib::date()->type_interval(null, 'P1.5D')->isOk([ &$dateInterval ]);
    $theDebug->dump_all_value([ $status, $dateInterval ]);
    $status = \Gzhegow\Lib\Lib::date()->type_interval(null, '+100 seconds')->isOk([ &$dateInterval ]);
    $theDebug->dump_all_value([ $status, $dateInterval ]);
    $status = \Gzhegow\Lib\Lib::date()->type_interval(null, new \DateInterval('P1D'))->isOk([ &$dateInterval ]);
    $theDebug->dump_all_value([ $status, $dateInterval ]);
    $status = \Gzhegow\Lib\Lib::date()->type_interval(null, \DateInterval::createFromDateString('+100 seconds'))->isOk([ &$dateInterval ]);
    $theDebug->dump_all_value([ $status, $dateInterval ]);
    echo "\n";

    $status = \Gzhegow\Lib\Lib::date()->type_interval_duration(null, 'P1D')->isOk([ &$dateInterval ]);
    $theDebug->dump_all_value([ $status, $dateInterval ]);
    $status = \Gzhegow\Lib\Lib::date()->type_interval_duration(null, 'P1.5D')->isOk([ &$dateInterval ]);
    $theDebug->dump_all_value([ $status, $dateInterval ]);
    $status = \Gzhegow\Lib\Lib::date()->type_interval_duration(null, new \DateInterval('P1D'))->isOk([ &$dateInterval ]);
    $theDebug->dump_all_value([ $status, $dateInterval ]);
    $status = \Gzhegow\Lib\Lib::date()->type_interval_duration(null, \DateInterval::createFromDateString('+100 seconds'))->isOk([ &$dateInterval ]);
    $theDebug->dump_all_value([ $status, $dateInterval ]);
    echo "\n";

    $status = \Gzhegow\Lib\Lib::date()->type_interval_datestring(null, '+100 seconds')->isOk([ &$dateInterval ]);
    $theDebug->dump_all_value([ $status, $dateInterval ]);
    $status = \Gzhegow\Lib\Lib::date()->type_interval_datestring(null, new \DateInterval('P1D'))->isOk([ &$dateInterval ]);
    $theDebug->dump_all_value([ $status, $dateInterval ]);
    $status = \Gzhegow\Lib\Lib::date()->type_interval_datestring(null, \DateInterval::createFromDateString('+100 seconds'))->isOk([ &$dateInterval ]);
    $theDebug->dump_all_value([ $status, $dateInterval ]);
    echo "\n";

    $status = \Gzhegow\Lib\Lib::date()->type_interval_microtime(null, '123.456')->isOk([ &$dateInterval ]);
    $theDebug->dump_all_value([ $status, $dateInterval ]);
    $status = \Gzhegow\Lib\Lib::date()->type_interval_microtime(null, new \DateInterval('P1D'))->isOk([ &$dateInterval ]);
    $theDebug->dump_all_value([ $status, $dateInterval ]);
    $status = \Gzhegow\Lib\Lib::date()->type_interval_microtime(null, \DateInterval::createFromDateString('+100 seconds'))->isOk([ &$dateInterval ]);
    $theDebug->dump_all_value([ $status, $dateInterval ]);
    echo "\n";

    $status = \Gzhegow\Lib\Lib::date()->type_interval_ago(null, new \DateTime('tomorrow midnight'), new \DateTime('now midnight'))->isOk([ &$dateInterval ]);
    $theDebug->dump_all_value([ $status, $dateInterval ]);
    $status = \Gzhegow\Lib\Lib::date()->type_interval_ago(null, new \DateInterval('P1D'))->isOk([ &$dateInterval ]);
    $theDebug->dump_all_value([ $status, $dateInterval ]);
    $status = \Gzhegow\Lib\Lib::date()->type_interval_ago(null, \DateInterval::createFromDateString('+100 seconds'))->isOk([ &$dateInterval ]);
    $theDebug->dump_all_value([ $status, $dateInterval ]);
    echo "\n";

    echo "\n";


    $status = \Gzhegow\Lib\Lib::date()->type_adate(null, '1970-01-01 midnight')->isOk([ &$dateObject ]);
    $dateAtomString1 = $dateObject->format(DATE_ATOM);
    $theDebug->dump_all_value([ $status, $dateObject ]);

    $status = \Gzhegow\Lib\Lib::date()->type_adate(null, $dateObject)->isOk([ &$dateObject2 ]);
    $dateAtomString2 = $dateObject2->format(DATE_ATOM);
    $theDebug->dump_all_value([ $status, $dateObject2, $dateAtomString1 === $dateAtomString2 ]);

    $status = \Gzhegow\Lib\Lib::date()->type_adate(null, $dateAtomString1)->isOk([ &$dateObject3 ]);
    $dateAtomString3 = $dateObject3->format(DATE_ATOM);
    $theDebug->dump_all_value([ $status, $dateObject3, $dateAtomString1 === $dateAtomString3 ]);
    echo "\n";


    $status = \Gzhegow\Lib\Lib::date()->type_idate(null, '1970-01-01 midnight')->isOk([ &$dateImmutableObject ]);
    $dateAtomString1 = $dateImmutableObject->format(DATE_ATOM);
    $theDebug->dump_all_value([ $status, $dateImmutableObject ]);

    $status = \Gzhegow\Lib\Lib::date()->type_idate(null, $dateObject)->isOk([ &$dateImmutableObject2 ]);
    $dateAtomString2 = $dateImmutableObject2->format(DATE_ATOM);
    $theDebug->dump_all_value([ $status, $dateImmutableObject2, $dateAtomString1 === $dateAtomString2 ]);

    $status = \Gzhegow\Lib\Lib::date()->type_idate(null, $dateAtomString1)->isOk([ &$dateImmutableObject3 ]);
    $dateAtomString3 = $dateImmutableObject3->format(DATE_ATOM);
    $theDebug->dump_all_value([ $status, $dateImmutableObject3, $dateAtomString1 === $dateAtomString3 ]);
    echo "\n";


    $status = \Gzhegow\Lib\Lib::date()->type_date(null, '1970-01-01 midnight')->isOk([ &$dateObject ]);
    $dateAtomString1 = $dateObject->format(DATE_ATOM);
    $theDebug->dump_all_value([ $status, $dateObject ]);

    $status = \Gzhegow\Lib\Lib::date()->type_date(null, $dateObject)->isOk([ &$dateObject2 ]);
    $dateAtomString2 = $dateObject2->format(DATE_ATOM);
    $theDebug->dump_all_value([ $status, $dateObject2, $dateAtomString1 === $dateAtomString2 ]);

    $status = \Gzhegow\Lib\Lib::date()->type_idate(null, $from = $dateObject)->isOk([ &$dateImmutableObject ]);
    $dateAtomString3 = $dateImmutableObject->format(DATE_ATOM);
    $theDebug->dump_all_value([ $status, $dateImmutableObject, $dateAtomString1 === $dateAtomString3 ]);

    $status = \Gzhegow\Lib\Lib::date()->type_date(null, $dateImmutableObject)->isOk([ &$dateImmutableObject2 ]);
    $dateAtomString4 = $dateImmutableObject2->format(DATE_ATOM);
    $theDebug->dump_all_value([ $status, $dateImmutableObject2, $dateAtomString1 === $dateAtomString4 ]);
    echo "\n";


    $status = \Gzhegow\Lib\Lib::date()->type_adate(null, '1970-01-01 midnight')->isOk([ &$dateObject1 ]);
    $dateAtomString = $dateObject1->format(DATE_ATOM);
    $theDebug->dump_all_value([ $status, $dateObject1 ]);

    $status = \Gzhegow\Lib\Lib::date()->type_adate(null, '1970-01-01 midnight', 'EET')->isOk([ &$dateObject2 ]);
    $dateAtomString2 = $dateObject2->format(DATE_ATOM);
    $theDebug->dump_all_value([ $status, $dateObject2, $dateAtomString !== $dateAtomString2 ]);
    echo "\n";

    echo "\n";


    $status = \Gzhegow\Lib\Lib::date()->type_adate(null, '1970-01-01 12:34:56.7')->isOk([ &$dateObject ]);
    $theDebug->dump_all_value([ $status, $dateObject ]);
    $status = \Gzhegow\Lib\Lib::date()->type_adate(null, '1970-01-01 12:34:56.78')->isOk([ &$dateObject ]);
    $theDebug->dump_all_value([ $status, $dateObject ]);
    $status = \Gzhegow\Lib\Lib::date()->type_adate(null, '1970-01-01 12:34:56.789')->isOk([ &$dateObject ]);
    $theDebug->dump_all_value([ $status, $dateObject ]);
    $status = \Gzhegow\Lib\Lib::date()->type_adate(null, '1970-01-01 12:34:56.7890', 'EET')->isOk([ &$dateObject ]);
    $theDebug->dump_all_value([ $status, $dateObject ]);
    echo "\n";

    $status = \Gzhegow\Lib\Lib::date()->type_adate_tz(null, '1970-01-01 12:34:56.7')->isOk([ &$dateObject ]);
    $theDebug->dump_all_value([ $status, $dateObject ]);
    $status = \Gzhegow\Lib\Lib::date()->type_adate_tz(null, '1970-01-01 12:34:56.78 +0100')->isOk([ &$dateObject ]);
    $theDebug->dump_all_value([ $status, $dateObject ]);
    $status = \Gzhegow\Lib\Lib::date()->type_adate_tz(null, '1970-01-01 12:34:56.789 EET')->isOk([ &$dateObject ]);
    $theDebug->dump_all_value([ $status, $dateObject ]);
    $status = \Gzhegow\Lib\Lib::date()->type_adate_tz(null, '1970-01-01 12:34:56.7890 Europe/Minsk')->isOk([ &$dateObject ]);
    $theDebug->dump_all_value([ $status, $dateObject ]);
    echo "\n";

    $status = \Gzhegow\Lib\Lib::date()->type_adate_no_tz(null, '1970-01-01 12:34:56.7', 'UTC')->isOk([ &$dateObject ]);
    $theDebug->dump_all_value([ $status, $dateObject ]);
    $status = \Gzhegow\Lib\Lib::date()->type_adate_no_tz(null, '1970-01-01 12:34:56.78 +0100', 'UTC')->isOk([ &$dateObject ]);
    $theDebug->dump_all_value([ $status, $dateObject ]);
    $status = \Gzhegow\Lib\Lib::date()->type_adate_no_tz(null, '1970-01-01 12:34:56.789 EET', 'UTC')->isOk([ &$dateObject ]);
    $theDebug->dump_all_value([ $status, $dateObject ]);
    $status = \Gzhegow\Lib\Lib::date()->type_adate_no_tz(null, '1970-01-01 12:34:56.7890 Europe/Minsk', 'UTC')->isOk([ &$dateObject ]);
    $theDebug->dump_all_value([ $status, $dateObject ]);
    echo "\n";

    $status = \Gzhegow\Lib\Lib::date()->type_adate_formatted(null, '1970-01-01 12:34:56.7', 'Y-m-d H:i:s.u O')->isOk([ &$dateObject ]);
    $theDebug->dump_all_value([ $status, $dateObject ]);
    $status = \Gzhegow\Lib\Lib::date()->type_adate_formatted(null, '1970-01-01 12:34:56.78 +0100', 'Y-m-d H:i:s.u O')->isOk([ &$dateObject ]);
    $theDebug->dump_all_value([ $status, $dateObject ]);
    $status = \Gzhegow\Lib\Lib::date()->type_adate_formatted(null, '1970-01-01 12:34:56.789 EET', 'Y-m-d H:i:s.u T')->isOk([ &$dateObject ]);
    $theDebug->dump_all_value([ $status, $dateObject ]);
    $status = \Gzhegow\Lib\Lib::date()->type_adate_formatted(null, '1970-01-01 12:34:56.7890 Europe/Minsk', 'Y-m-d H:i:s.u e')->isOk([ &$dateObject ]);
    $theDebug->dump_all_value([ $status, $dateObject ]);
    echo "\n";

    $status = \Gzhegow\Lib\Lib::date()->type_adate_tz_formatted(null, '1970-01-01 12:34:56.7', 'Y-m-d H:i:s.u O')->isOk([ &$dateObject ]);
    $theDebug->dump_all_value([ $status, $dateObject ]);
    $status = \Gzhegow\Lib\Lib::date()->type_adate_tz_formatted(null, '1970-01-01 12:34:56.78 +0100', 'Y-m-d H:i:s.u O')->isOk([ &$dateObject ]);
    $theDebug->dump_all_value([ $status, $dateObject ]);
    $status = \Gzhegow\Lib\Lib::date()->type_adate_tz_formatted(null, '1970-01-01 12:34:56.789 EET', 'Y-m-d H:i:s.u T')->isOk([ &$dateObject ]);
    $theDebug->dump_all_value([ $status, $dateObject ]);
    $status = \Gzhegow\Lib\Lib::date()->type_adate_tz_formatted(null, '1970-01-01 12:34:56.7890 Europe/Minsk', 'Y-m-d H:i:s.u e')->isOk([ &$dateObject ]);
    $theDebug->dump_all_value([ $status, $dateObject ]);
    echo "\n";

    $status = \Gzhegow\Lib\Lib::date()->type_adate_no_tz_formatted(null, '1970-01-01 12:34:56.7', 'Y-m-d H:i:s.u', 'UTC')->isOk([ &$dateObject ]);
    $theDebug->dump_all_value([ $status, $dateObject ]);
    $status = \Gzhegow\Lib\Lib::date()->type_adate_no_tz_formatted(null, '1970-01-01 12:34:56.78 +0100', 'Y-m-d H:i:s.u O', 'UTC')->isOk([ &$dateObject ]);
    $theDebug->dump_all_value([ $status, $dateObject ]);
    $status = \Gzhegow\Lib\Lib::date()->type_adate_no_tz_formatted(null, '1970-01-01 12:34:56.789 EET', 'Y-m-d H:i:s.u T', 'UTC')->isOk([ &$dateObject ]);
    $theDebug->dump_all_value([ $status, $dateObject ]);
    $status = \Gzhegow\Lib\Lib::date()->type_adate_no_tz_formatted(null, '1970-01-01 12:34:56.7890 Europe/Minsk', 'Y-m-d H:i:s.u e', 'UTC')->isOk([ &$dateObject ]);
    $theDebug->dump_all_value([ $status, $dateObject ]);
    echo "\n";

    $status = \Gzhegow\Lib\Lib::date()->type_adate_microtime(null, '0')->isOk([ &$dateObject ]);
    $theDebug->dump_all_value([ $status, $dateObject ]);
    $status = \Gzhegow\Lib\Lib::date()->type_adate_microtime(null, '123')->isOk([ &$dateObject ]);
    $theDebug->dump_all_value([ $status, $dateObject ]);
    $status = \Gzhegow\Lib\Lib::date()->type_adate_microtime(null, '123.456')->isOk([ &$dateObject ]);
    $theDebug->dump_all_value([ $status, $dateObject ]);
    $status = \Gzhegow\Lib\Lib::date()->type_adate_microtime(null, '123.456', 'EET')->isOk([ &$dateObject ]);
    $theDebug->dump_all_value([ $status, $dateObject ]);
    echo "\n";


    date_default_timezone_set($before);
};
$test = $theTest->newCase($fn);
$test->expectStdoutIf(PHP_VERSION_ID >= 80200, '
"[ DateModule ]"

TRUE | { object(serializable) # DateTimeZone # "+01:00" }
TRUE | { object(serializable) # DateTimeZone # "EET" }
TRUE | { object(serializable) # DateTimeZone # "Europe/Minsk" }
TRUE | { object(serializable) # DateTimeZone # "UTC" }
TRUE | { object(serializable) # DateTimeZone # "UTC" }

TRUE | { object(serializable) # DateTimeZone # "+01:00" }
TRUE | { object(serializable) # DateTimeZone # "+01:00" }
TRUE | { object(serializable) # DateTimeZone # "+01:00" }

TRUE | { object(serializable) # DateTimeZone # "EET" }
TRUE | { object(serializable) # DateTimeZone # "EET" }
TRUE | { object(serializable) # DateTimeZone # "EET" }

TRUE | { object(serializable) # DateTimeZone # "Europe/Minsk" }
TRUE | { object(serializable) # DateTimeZone # "Europe/Minsk" }
TRUE | { object(serializable) # DateTimeZone # "Europe/Minsk" }

TRUE | { object(serializable) # DateTimeZone # "EET" }
TRUE | { object(serializable) # DateTimeZone # "Europe/Minsk" }
TRUE | { object(serializable) # DateTimeZone # "EET" }
TRUE | { object(serializable) # DateTimeZone # "Europe/Minsk" }


TRUE | { object(serializable) # DateInterval # "P1D" }
TRUE | { object(serializable) # DateInterval # "P1DT12H" }
TRUE | { object(serializable) # DateInterval # "PT100S" }
TRUE | { object(serializable) # DateInterval # "P1D" }
TRUE | { object(serializable) # DateInterval # "PT100S" }

TRUE | { object(serializable) # DateInterval # "P1D" }
TRUE | { object(serializable) # DateInterval # "P1DT12H" }
TRUE | { object(serializable) # DateInterval # "P1D" }
TRUE | { object(serializable) # DateInterval # "PT100S" }

TRUE | { object(serializable) # DateInterval # "PT100S" }
TRUE | { object(serializable) # DateInterval # "P1D" }
TRUE | { object(serializable) # DateInterval # "PT100S" }

TRUE | { object(serializable) # DateInterval # "PT2M3.456S" }
TRUE | { object(serializable) # DateInterval # "P1D" }
TRUE | { object(serializable) # DateInterval # "PT100S" }

TRUE | { object(serializable) # DateInterval # "P1D" }
TRUE | { object(serializable) # DateInterval # "P1D" }
TRUE | { object(serializable) # DateInterval # "PT100S" }


TRUE | { object(serializable) # DateTime # "1970-01-01T00:00:00.000000+00:00" }
TRUE | { object(serializable) # DateTime # "1970-01-01T00:00:00.000000+00:00" } | TRUE
TRUE | { object(serializable) # DateTime # "1970-01-01T00:00:00.000000+00:00" } | TRUE

TRUE | { object(serializable) # DateTimeImmutable # "1970-01-01T00:00:00.000000+00:00" }
TRUE | { object(serializable) # DateTimeImmutable # "1970-01-01T00:00:00.000000+00:00" } | TRUE
TRUE | { object(serializable) # DateTimeImmutable # "1970-01-01T00:00:00.000000+00:00" } | TRUE

TRUE | { object(serializable) # DateTime # "1970-01-01T00:00:00.000000+00:00" }
TRUE | { object(serializable) # DateTime # "1970-01-01T00:00:00.000000+00:00" } | TRUE
TRUE | { object(serializable) # DateTimeImmutable # "1970-01-01T00:00:00.000000+00:00" } | TRUE
TRUE | { object(serializable) # DateTimeImmutable # "1970-01-01T00:00:00.000000+00:00" } | TRUE

TRUE | { object(serializable) # DateTime # "1970-01-01T00:00:00.000000+00:00" }
TRUE | { object(serializable) # DateTime # "1970-01-01T00:00:00.000000+02:00" } | TRUE


TRUE | { object(serializable) # DateTime # "1970-01-01T12:34:56.700000+00:00" }
TRUE | { object(serializable) # DateTime # "1970-01-01T12:34:56.780000+00:00" }
TRUE | { object(serializable) # DateTime # "1970-01-01T12:34:56.789000+00:00" }
TRUE | { object(serializable) # DateTime # "1970-01-01T12:34:56.789000+02:00" }

FALSE | NULL
TRUE | { object(serializable) # DateTime # "1970-01-01T12:34:56.780000+01:00" }
TRUE | { object(serializable) # DateTime # "1970-01-01T12:34:56.789000+02:00" }
TRUE | { object(serializable) # DateTime # "1970-01-01T12:34:56.789000+03:00" }

TRUE | { object(serializable) # DateTime # "1970-01-01T12:34:56.700000+00:00" }
FALSE | NULL
FALSE | NULL
FALSE | NULL

FALSE | NULL
TRUE | { object(serializable) # DateTime # "1970-01-01T12:34:56.780000+01:00" }
TRUE | { object(serializable) # DateTime # "1970-01-01T12:34:56.789000+02:00" }
TRUE | { object(serializable) # DateTime # "1970-01-01T12:34:56.789000+03:00" }

FALSE | NULL
TRUE | { object(serializable) # DateTime # "1970-01-01T12:34:56.780000+01:00" }
TRUE | { object(serializable) # DateTime # "1970-01-01T12:34:56.789000+02:00" }
TRUE | { object(serializable) # DateTime # "1970-01-01T12:34:56.789000+03:00" }

TRUE | { object(serializable) # DateTime # "1970-01-01T12:34:56.700000+00:00" }
FALSE | NULL
FALSE | NULL
FALSE | NULL

TRUE | { object(serializable) # DateTime # "1970-01-01T00:00:00.000000+00:00" }
TRUE | { object(serializable) # DateTime # "1970-01-01T00:02:03.000000+00:00" }
TRUE | { object(serializable) # DateTime # "1970-01-01T00:02:03.456000+00:00" }
TRUE | { object(serializable) # DateTime # "1970-01-01T02:02:03.456000+02:00" }
');
$test->expectStdoutIf(PHP_VERSION_ID < 80200, '
"[ DateModule ]"

TRUE | { object # DateTimeZone # "+01:00" }
TRUE | { object # DateTimeZone # "EET" }
TRUE | { object # DateTimeZone # "Europe/Minsk" }
TRUE | { object # DateTimeZone # "UTC" }
TRUE | { object # DateTimeZone # "UTC" }

TRUE | { object # DateTimeZone # "+01:00" }
TRUE | { object # DateTimeZone # "+01:00" }
TRUE | { object # DateTimeZone # "+01:00" }

TRUE | { object # DateTimeZone # "EET" }
TRUE | { object # DateTimeZone # "EET" }
TRUE | { object # DateTimeZone # "EET" }

TRUE | { object # DateTimeZone # "Europe/Minsk" }
TRUE | { object # DateTimeZone # "Europe/Minsk" }
TRUE | { object # DateTimeZone # "Europe/Minsk" }

TRUE | { object # DateTimeZone # "EET" }
TRUE | { object # DateTimeZone # "Europe/Minsk" }
TRUE | { object # DateTimeZone # "EET" }
TRUE | { object # DateTimeZone # "Europe/Minsk" }


TRUE | { object # DateInterval # "P1D" }
TRUE | { object # DateInterval # "P1DT12H" }
TRUE | { object # DateInterval # "PT100S" }
TRUE | { object # DateInterval # "P1D" }
TRUE | { object # DateInterval # "PT100S" }

TRUE | { object # DateInterval # "P1D" }
TRUE | { object # DateInterval # "P1DT12H" }
TRUE | { object # DateInterval # "P1D" }
TRUE | { object # DateInterval # "PT100S" }

TRUE | { object # DateInterval # "PT100S" }
TRUE | { object # DateInterval # "P1D" }
TRUE | { object # DateInterval # "PT100S" }

TRUE | { object # DateInterval # "PT2M3.456S" }
TRUE | { object # DateInterval # "P1D" }
TRUE | { object # DateInterval # "PT100S" }

TRUE | { object # DateInterval # "P1D" }
TRUE | { object # DateInterval # "P1D" }
TRUE | { object # DateInterval # "PT100S" }


TRUE | { object # DateTime # "1970-01-01T00:00:00.000000+00:00" }
TRUE | { object # DateTime # "1970-01-01T00:00:00.000000+00:00" } | TRUE
TRUE | { object # DateTime # "1970-01-01T00:00:00.000000+00:00" } | TRUE

TRUE | { object # DateTimeImmutable # "1970-01-01T00:00:00.000000+00:00" }
TRUE | { object # DateTimeImmutable # "1970-01-01T00:00:00.000000+00:00" } | TRUE
TRUE | { object # DateTimeImmutable # "1970-01-01T00:00:00.000000+00:00" } | TRUE

TRUE | { object # DateTime # "1970-01-01T00:00:00.000000+00:00" }
TRUE | { object # DateTime # "1970-01-01T00:00:00.000000+00:00" } | TRUE
TRUE | { object # DateTimeImmutable # "1970-01-01T00:00:00.000000+00:00" } | TRUE
TRUE | { object # DateTimeImmutable # "1970-01-01T00:00:00.000000+00:00" } | TRUE

TRUE | { object # DateTime # "1970-01-01T00:00:00.000000+00:00" }
TRUE | { object # DateTime # "1970-01-01T00:00:00.000000+02:00" } | TRUE


TRUE | { object # DateTime # "1970-01-01T12:34:56.700000+00:00" }
TRUE | { object # DateTime # "1970-01-01T12:34:56.780000+00:00" }
TRUE | { object # DateTime # "1970-01-01T12:34:56.789000+00:00" }
TRUE | { object # DateTime # "1970-01-01T12:34:56.789000+02:00" }

FALSE | NULL
TRUE | { object # DateTime # "1970-01-01T12:34:56.780000+01:00" }
TRUE | { object # DateTime # "1970-01-01T12:34:56.789000+02:00" }
TRUE | { object # DateTime # "1970-01-01T12:34:56.789000+03:00" }

TRUE | { object # DateTime # "1970-01-01T12:34:56.700000+00:00" }
FALSE | NULL
FALSE | NULL
FALSE | NULL

FALSE | NULL
TRUE | { object # DateTime # "1970-01-01T12:34:56.780000+01:00" }
TRUE | { object # DateTime # "1970-01-01T12:34:56.789000+02:00" }
TRUE | { object # DateTime # "1970-01-01T12:34:56.789000+03:00" }

FALSE | NULL
TRUE | { object # DateTime # "1970-01-01T12:34:56.780000+01:00" }
TRUE | { object # DateTime # "1970-01-01T12:34:56.789000+02:00" }
TRUE | { object # DateTime # "1970-01-01T12:34:56.789000+03:00" }

TRUE | { object # DateTime # "1970-01-01T12:34:56.700000+00:00" }
FALSE | NULL
FALSE | NULL
FALSE | NULL

TRUE | { object # DateTime # "1970-01-01T00:00:00.000000+00:00" }
TRUE | { object # DateTime # "1970-01-01T00:02:03.000000+00:00" }
TRUE | { object # DateTime # "1970-01-01T00:02:03.456000+00:00" }
TRUE | { object # DateTime # "1970-01-01T02:02:03.456000+02:00" }
');
$test->run();



// >>> TEST
// > тесты DebugModule
$fn = function () use ($theDebug) {
    $theDebug->dump_value('[ DebugModule ]');
    echo "\n";


    $oldText = "apple\nbanana\ncherry\ndamson\nelderberry";
    $newText = "apple\nbanana\ncherry\ndamson\nelderberry";
    $isDiff = $theDebug->diff($newText, $oldText, [ &$diffLines ]);
    $theDebug->dump_value($isDiff);
    $theDebug->dump_array_multiline($diffLines);
    echo "\n";


    echo "\n";


    $oldText = "apple2\nbanana\ncherry\ndamson\nelderberry";
    $newText = "apple\nbanana\ncherry\ndamson\nelderberry";
    $isDiff = $theDebug->diff($newText, $oldText, [ &$diffLines ]);
    $theDebug->dump_value($isDiff);
    $theDebug->dump_array_multiline($diffLines);
    echo "\n";

    $oldText = "apple\nbanana\ncherry2\ndamson\nelderberry";
    $newText = "apple\nbanana\ncherry\ndamson\nelderberry";
    $isDiff = $theDebug->diff($newText, $oldText, [ &$diffLines ]);
    $theDebug->dump_value($isDiff);
    $theDebug->dump_array_multiline($diffLines);
    echo "\n";

    $oldText = "apple\nbanana\ncherry\ndamson\nelderberry2";
    $newText = "apple\nbanana\ncherry\ndamson\nelderberry";
    $isDiff = $theDebug->diff($newText, $oldText, [ &$diffLines ]);
    $theDebug->dump_value($isDiff);
    $theDebug->dump_array_multiline($diffLines);
    echo "\n";


    echo "\n";


    $oldText = "fig\napple\nbanana\ncherry\ndamson\nelderberry";
    $newText = "apple\nbanana\ncherry\ndamson\nelderberry";
    $isDiff = $theDebug->diff($newText, $oldText, [ &$diffLines ]);
    $theDebug->dump_value($isDiff);
    $theDebug->dump_array_multiline($diffLines);
    echo "\n";

    $oldText = "apple\nbanana\ncherry\nfig\ndamson\nelderberry";
    $newText = "apple\nbanana\ncherry\ndamson\nelderberry";
    $isDiff = $theDebug->diff($newText, $oldText, [ &$diffLines ]);
    $theDebug->dump_value($isDiff);
    $theDebug->dump_array_multiline($diffLines);
    echo "\n";

    $oldText = "apple\nbanana\ncherry\ndamson\nelderberry\nfig";
    $newText = "apple\nbanana\ncherry\ndamson\nelderberry";
    $isDiff = $theDebug->diff($newText, $oldText, [ &$diffLines ]);
    $theDebug->dump_value($isDiff);
    $theDebug->dump_array_multiline($diffLines);
    echo "\n";


    echo "\n";


    $oldText = "banana\ncherry\ndamson\nelderberry";
    $newText = "apple\nbanana\ncherry\ndamson\nelderberry";
    $isDiff = $theDebug->diff($newText, $oldText, [ &$diffLines ]);
    $theDebug->dump_value($isDiff);
    $theDebug->dump_array_multiline($diffLines);
    echo "\n";

    $oldText = "apple\nbanana\ndamson\nelderberry";
    $newText = "apple\nbanana\ncherry\ndamson\nelderberry";
    $isDiff = $theDebug->diff($newText, $oldText, [ &$diffLines ]);
    $theDebug->dump_value($isDiff);
    $theDebug->dump_array_multiline($diffLines);
    echo "\n";

    $oldText = "apple\nbanana\ncherry\ndamson";
    $newText = "apple\nbanana\ncherry\ndamson\nelderberry";
    $isDiff = $theDebug->diff($newText, $oldText, [ &$diffLines ]);
    $theDebug->dump_value($isDiff);
    $theDebug->dump_array_multiline($diffLines);
    echo "\n";


    echo "\n";


    $theDebug->dump_value(null) . "\n";
    $theDebug->dump_value(false) . "\n";
    $theDebug->dump_value(1) . "\n";
    $theDebug->dump_value(1.1) . "\n";
    $theDebug->dump_value('string') . "\n";
    $theDebug->dump_value([]) . "\n";
    $theDebug->dump_value((object) []) . "\n";
    $theDebug->dump_value(\Gzhegow\Lib\Lib::php()->phpout()) . "\n";

    echo "\n";


    $stdClass = (object) [];
    $theDebug->dump_array(
        [
            [ 1, 'apple', $stdClass ],
            [ 2, 'apples', $stdClass ],
            [ 1.5, 'apples', $stdClass ],
        ], 1
    );
    $theDebug->dump_array(
        [
            [ 1, 'apple', $stdClass ],
            [ 2, 'apples', $stdClass ],
            [ 1.5, 'apples', $stdClass ],
        ], 2
    );

    echo "\n";


    $theDebug->dump_value_multiline(
        [
            [ 1, 'apple', $stdClass ],
            [ 2, 'apples', $stdClass ],
            [ 1.5, 'apples', $stdClass ],
        ]
    );
    $theDebug->dump_array_multiline(
        [
            [ 1, 'apple', $stdClass ],
            [ 2, 'apples', $stdClass ],
            [ 1.5, 'apples', $stdClass ],
        ], 2
    );

    echo "\n";


    $varToPrint = '<div class="block"></div>';

    $string = $theDebug
        ->cloneDumper()
        ->selectPrinter(\Gzhegow\Lib\Modules\Debug\Dumper\DefaultDebugDumper::PRINTER_VAR_DUMP)
        ->printerPrint($varToPrint)
    ;
    $theDebug->dump_value($string);

    $string = $theDebug
        ->cloneDumper()
        ->selectPrinter(\Gzhegow\Lib\Modules\Debug\Dumper\DefaultDebugDumper::PRINTER_PRINT_R)
        ->printerPrint($varToPrint)
    ;
    $theDebug->dump_value($string);

    $string = $theDebug
        ->cloneDumper()
        ->selectPrinter(\Gzhegow\Lib\Modules\Debug\Dumper\DefaultDebugDumper::PRINTER_JSON_ENCODE)
        ->printerPrint($varToPrint)
    ;
    $theDebug->dump_value($string);

    echo "\n";


    // $varToDump = '<div class="block"></div>';
    //
    // $theDebug
    //     ->cloneDumper()
    //     ->printer(\Gzhegow\Lib\Modules\Debug\Dumper\DefaultDumper::PRINTER_VAR_DUMP)
    //     ->dumper(\Gzhegow\Lib\Modules\Debug\Dumper\DefaultDumper::DUMPER_ECHO)
    //     ->dump($varToDump)
    // ;
    //
    // $theDebug
    //     ->cloneDumper()
    //     ->printer(\Gzhegow\Lib\Modules\Debug\Dumper\DefaultDumper::PRINTER_VAR_DUMP)
    //     ->dumper(\Gzhegow\Lib\Modules\Debug\Dumper\DefaultDumper::DUMPER_ECHO_HTML)
    //     ->dump($varToDump)
    // ;
    //
    // $theDebug
    //     ->cloneDumper()
    //     ->printer(\Gzhegow\Lib\Modules\Debug\Dumper\DefaultDumper::PRINTER_VAR_DUMP)
    //     ->dumper(\Gzhegow\Lib\Modules\Debug\Dumper\DefaultDumper::DUMPER_DEVTOOLS)
    //     ->dump($varToDump)
    // ;
    //
    // $theDebug
    //     ->cloneDumper()
    //     ->printer(\Gzhegow\Lib\Modules\Debug\Dumper\DefaultDumper::PRINTER_VAR_DUMP)
    //     ->dumper(
    //         \Gzhegow\Lib\Modules\Debug\Dumper\DefaultDumper::DUMPER_PDO,
    //         [
    //             'pdo'    => new \PDO('mysql:host=localhost;dbname=test', 'root', ''),
    //             'table'  => 'dump',
    //             'column' => 'var',
    //         ]
    //     )
    //     ->dump($varToDump)
    // ;
};
$test = $theTest->newCase($fn);
$test->expectStdout('
"[ DebugModule ]"

FALSE
###
[
  "apple",
  "banana",
  "cherry",
  "damson",
  "elderberry"
]
###


TRUE
###
[
  "[ 1 ] --- > apple2",
  "[ 1 ] +++ > apple",
  "banana",
  "cherry",
  "damson",
  "elderberry"
]
###

TRUE
###
[
  "apple",
  "banana",
  "[ 3 ] --- > cherry2",
  "[ 3 ] +++ > cherry",
  "damson",
  "elderberry"
]
###

TRUE
###
[
  "apple",
  "banana",
  "cherry",
  "damson",
  "[ 5 ] --- > elderberry2",
  "[ 5 ] +++ > elderberry"
]
###


TRUE
###
[
  "[ 1 ] --- > fig",
  "apple",
  "banana",
  "cherry",
  "damson",
  "elderberry"
]
###

TRUE
###
[
  "apple",
  "banana",
  "cherry",
  "[ 4 ] --- > fig",
  "damson",
  "elderberry"
]
###

TRUE
###
[
  "apple",
  "banana",
  "cherry",
  "damson",
  "elderberry",
  "[ 6 ] --- > fig"
]
###


TRUE
###
[
  "[ 1 ] +++ > apple",
  "banana",
  "cherry",
  "damson",
  "elderberry"
]
###

TRUE
###
[
  "apple",
  "banana",
  "[ 3 ] +++ > cherry",
  "damson",
  "elderberry"
]
###

TRUE
###
[
  "apple",
  "banana",
  "cherry",
  "damson",
  "[ 5 ] +++ > elderberry"
]
###


NULL
FALSE
1
1.1
"string"
[]
{ object # stdClass }
{ resource(opened) # stream }

[ "{ array(3) }", "{ array(3) }", "{ array(3) }" ]
[ [ 1, "apple", "{ object # stdClass }" ], [ 2, "apples", "{ object # stdClass }" ], [ 1.5, "apples", "{ object # stdClass }" ] ]

###
[
  "{ array(3) }",
  "{ array(3) }",
  "{ array(3) }"
]
###
###
[
  [
    1,
    "apple",
    "{ object # stdClass }"
  ],
  [
    2,
    "apples",
    "{ object # stdClass }"
  ],
  [
    1.5,
    "apples",
    "{ object # stdClass }"
  ]
]
###

"{ string(25) # \"<div class=\\\\"block\\\\"></div>\" }"
"<div class=\"block\"></div>"
"\"<div class=\\\\"block\\\\"></div>\""
');
$test->run();



// >>> TEST
// > тесты EscapeModule
$fn = function () use ($theDebug) {
    $theDebug->dump_value('[ EscapeModule ]');
    echo "\n";


    $params = [];
    $sqlIn = \Gzhegow\Lib\Lib::escape()->sql_in($params, 'AND `user_id`', [ 1, 2, 3 ]);
    $theDebug->dump_value($sqlIn);
    $theDebug->dump_array($params);

    echo "\n";


    $params = [];
    $sqlIn = \Gzhegow\Lib\Lib::escape()->sql_in($params, 'AND `user_id`', [ 1, 2, 3 ], 'user_id');
    $theDebug->dump_value($sqlIn);
    $theDebug->dump_array($params);

    echo "\n";


    $sqlLike = \Gzhegow\Lib\Lib::escape()->sql_like_quote('Hello, _user_! How are you today, in percents (%)?', '\\');
    $theDebug->dump_value($sqlLike);

    $sqlLike = \Gzhegow\Lib\Lib::escape()->sql_like_escape(
        'AND `search`', 'ILIKE',
        'Hello, _user_! How are you today, in percents (%)?'
    );
    $theDebug->dump_value($sqlLike);

    $sqlLike = \Gzhegow\Lib\Lib::escape()->sql_like_escape(
        'AND `name`', 'LIKE',
        [ '__' ], 'user%%__', [ '%' ]
    );
    $theDebug->dump_value($sqlLike);

    echo "\n";
};
$test = $theTest->newCase($fn);
$test->expectStdout('
"[ EscapeModule ]"

"AND `user_id` IN (?, ?, ?)"
[ 1, 2, 3 ]

"AND `user_id` IN (:user_id0, :user_id1, :user_id2)"
[ ":user_id0" => 1, ":user_id1" => 2, ":user_id2" => 3 ]

"Hello, \_user\_! How are you today, in percents (\%)?"
"AND `search` ILIKE \"Hello, \_user\_! How are you today, in percents (\%)?\""
"AND `name` LIKE \"__user\%\%\_\_%\""
');
$test->run();



// >>> TEST
// > тесты FormatModule
$fn = function () use ($theDebug) {
    $theDebug->dump_value('[ FormatModule ]');
    echo "\n";

    $enc = \Gzhegow\Lib\Lib::format()->bytes_encode([ NAN ], $src = 1024 * 1024);
    $theDebug->dump_value($enc);

    $dec = \Gzhegow\Lib\Lib::format()->bytes_decode([ NAN ], $enc);
    $theDebug->dump_all_value([ $dec, $src === $dec ]);

    echo "\n";
    echo "\n";


    $csv = \Gzhegow\Lib\Lib::format()->csv()->csv_encode_rows(
        [ false ],
        [
            [ 'col1', 'col2' ],
            [ 'val1', 'val2' ],
        ]
    );
    $theDebug->dump_value($csv);

    echo "\n";

    $csv = \Gzhegow\Lib\Lib::format()->csv()->csv_encode_row([ false ], [ 'col1', 'col2' ]);
    $theDebug->dump_value($csv);

    echo "\n";
    echo "\n";



    $json1 = '{"hello": "world"}';
    $json2 = '
        {
            "hello": "world"
        }
    ';

    $jsonWithComment1 = "[1, /* 2, */ 3]";
    $jsonWithComment2 = '
        {
            "hello": "world",
            # "foo1": "bar1",
            // "foo2": "bar2",
            /* "foo3": "bar3" */
            "foo": "bar"
        }
    ';


    try {
        \Gzhegow\Lib\Lib::format()->json()->json_decode([], $json = null, $isAssociative = true);
    }
    catch ( \Throwable $e ) {
        $theDebug->dump_value('[ CATCH ] ' . $e->getMessage());
    }

    $result = \Gzhegow\Lib\Lib::format()->json()->json_decode([ null ], $json = null, $isAssociative = true);
    $theDebug->dump_value($result);

    echo "\n";


    try {
        \Gzhegow\Lib\Lib::format()->json()->jsonc_decode([], $json = null, $isAssociative = true);
    }
    catch ( \Throwable $e ) {
        $theDebug->dump_value('[ CATCH ] ' . $e->getMessage());
    }

    $result = \Gzhegow\Lib\Lib::format()->json()->jsonc_decode([ null ], $json = null, $isAssociative = true);
    $theDebug->dump_value($result);

    echo "\n";


    $result = \Gzhegow\Lib\Lib::format()->json()->json_decode([], $json1, $isAssociative = true);
    $theDebug->dump_value($result);

    $result = \Gzhegow\Lib\Lib::format()->json()->json_decode([], $json2, $isAssociative = true);
    $theDebug->dump_value($result);

    echo "\n";


    $result = \Gzhegow\Lib\Lib::format()->json()->jsonc_decode([], $json1, $isAssociative = true);
    $theDebug->dump_value($result);

    $result = \Gzhegow\Lib\Lib::format()->json()->jsonc_decode([], $json2, $isAssociative = true);
    $theDebug->dump_value($result);

    echo "\n";


    try {
        \Gzhegow\Lib\Lib::format()->json()->json_decode([], $jsonWithComment1, $isAssociative = true);
    }
    catch ( \Throwable $e ) {
        $theDebug->dump_value('[ CATCH ] ' . $e->getMessage());
    }

    try {
        \Gzhegow\Lib\Lib::format()->json()->json_decode([], $jsonWithComment2, $isAssociative = true);
    }
    catch ( \Throwable $e ) {
        $theDebug->dump_value('[ CATCH ] ' . $e->getMessage());
    }

    $result = \Gzhegow\Lib\Lib::format()->json()->jsonc_decode([], $jsonWithComment1, $isAssociative = true);
    $theDebug->dump_value($result);

    $result = \Gzhegow\Lib\Lib::format()->json()->jsonc_decode([], $jsonWithComment2, $isAssociative = true);
    $theDebug->dump_value($result);

    echo "\n";


    try {
        \Gzhegow\Lib\Lib::format()->json()->json_encode([], $value = null, $isAllowNull = false);
    }
    catch ( \Throwable $e ) {
        $theDebug->dump_value('[ CATCH ] ' . $e->getMessage());
    }

    $result = \Gzhegow\Lib\Lib::format()->json()->json_encode([ null ], $value = null, $isAllowNull = false);
    $theDebug->dump_value($result);

    $result = \Gzhegow\Lib\Lib::format()->json()->json_encode([], $value = null, $isAllowNull = true);
    $theDebug->dump_value($result);

    echo "\n";


    try {
        \Gzhegow\Lib\Lib::format()->json()->json_encode([], $value = NAN);
    }
    catch ( \Throwable $e ) {
        $theDebug->dump_value('[ CATCH ] ' . $e->getMessage());
    }

    $result = \Gzhegow\Lib\Lib::format()->json()->json_encode([ 'NAN' ], $value = NAN);
    $theDebug->dump_value($result);

    echo "\n";


    $result = \Gzhegow\Lib\Lib::format()->json()->json_encode([], "привет");
    $theDebug->dump_value($result);

    $result = \Gzhegow\Lib\Lib::format()->json()->json_print([], "привет");
    $theDebug->dump_value($result);

    echo "\n";
    echo "\n";



    $xml = <<<XML
<example>
  <a>Apple</a>
  <b>Banana</b>
  <c>Cherry</c>
</example>
XML;

    $sxe = \Gzhegow\Lib\Lib::format()->xml()->parse_xml_sxe([], $xml);
    $theDebug->dump_value($sxe);


    $xml = <<<XML
<?xml version="1.0" encoding="UTF-8"

php test.php