diff --git a/4dev/tests/CoreLibsConvertStringsTest.php b/4dev/tests/CoreLibsConvertStringsTest.php new file mode 100644 index 00000000..7e71355f --- /dev/null +++ b/4dev/tests/CoreLibsConvertStringsTest.php @@ -0,0 +1,142 @@ + [ + '', + '', + null, + '' + ], + 'empty input string' => [ + '', + '2-2', + null, + '' + ], + 'empty format string string' => [ + '1234', + '', + null, + '1234' + ], + 'string format match' => [ + '1234', + '2-2', + null, + '12-34' + ], + 'string format short first' => [ + '1', + '2-2', + null, + '1' + ], + 'string format match first' => [ + '12', + '2-2', + null, + '12' + ], + 'string format short second' => [ + '123', + '2-2', + null, + '12-3' + ], + 'string format too long' => [ + '1234567', + '2-2', + null, + '12-34-567' + ], + 'string format invalid format string' => [ + '1234', + '2_2', + null, + '1234' + ], + 'different split character' => [ + '1234', + '2_2', + '_', + '12_34' + ], + 'mixed split characters' => [ + '123456', + '2-2_2', + '-_', + '12-34_56' + ], + 'length mixed' => [ + 'ABCD12345568ABC13', + '2-4_5-2#4', + '-_#', + 'AB-CD12_34556-8A#BC13' + ], + 'split with split chars in string' => [ + '12-34', + '2-2', + null, + '12--3-4' + ] + ]; + } + + /** + * split format string + * + * @covers ::splitFormatString + * @dataProvider splitFormatStringProvider + * @testdox splitFormatString $input with format $format and splitters $split_characters will be $expected [$_dataName] + * + * @param string $input + * @param string $format + * @param string|null $split_characters + * @param string $expected + * @return void + */ + public function testSplitFormatString( + string $input, + string $format, + ?string $split_characters, + string $expected + ): void { + if ($split_characters === null) { + $output = \CoreLibs\Convert\Strings::splitFormatString( + $input, + $format + ); + } else { + $output = \CoreLibs\Convert\Strings::splitFormatString( + $input, + $format, + $split_characters + ); + } + $this->assertEquals( + $expected, + $output + ); + } +} + +// __END__ diff --git a/www/admin/class_test.php b/www/admin/class_test.php index 4c8c685b..5fbc9129 100644 --- a/www/admin/class_test.php +++ b/www/admin/class_test.php @@ -70,6 +70,7 @@ print '
Class Test: HASH
'; print '
Class Test: ENCODING (CHECK/CONVERT/MIME)
'; print '
Class Test: IMAGE
'; print '
Class Test: BYTE CONVERT
'; +print '
Class Test: STRING CONVERT
'; print '
Class Test: DATE/TIME
'; print '
Class Test: ARRAY HANDLER
'; print '
Class Test: FILE
'; diff --git a/www/admin/class_test.strings.php b/www/admin/class_test.strings.php new file mode 100644 index 00000000..7681110d --- /dev/null +++ b/www/admin/class_test.strings.php @@ -0,0 +1,73 @@ + BASE . LOG, + 'file_id' => $LOG_FILE_ID, + // add file date + 'print_file_date' => true, + // set debug and print flags + 'debug_all' => $DEBUG_ALL ?? false, + 'echo_all' => $ECHO_ALL ?? false, + 'print_all' => $PRINT_ALL ?? false, +]); +$byte_class = 'CoreLibs\Convert\Strings'; + +$PAGE_NAME = 'TEST CLASS: STRINGS CONVERT'; +print ""; +print "" . $PAGE_NAME . ""; +print ""; +print '
Class Test Master
'; +print '

' . $PAGE_NAME . '

'; + +$split = '4-4-4'; +$test_strings = [ + '13', + '1234', + '12341', + '12341234', + '123412341', + '123412341234', + '1234123412341234512345', +]; + +foreach ($test_strings as $string) { + print "Convert: $string with $split to: " + . \CoreLibs\Convert\Strings::splitFormatString($string, $split) + . "
"; +} + +$split = '2_2'; +$string = '1234'; +print "Convert: $string with $split to: " + . \CoreLibs\Convert\Strings::splitFormatString($string, $split) + . "
"; + +// error message +print $log->printErrorMsg(); + +print ""; + +// __END__ diff --git a/www/lib/CoreLibs/Convert/Strings.php b/www/lib/CoreLibs/Convert/Strings.php new file mode 100644 index 00000000..324083af --- /dev/null +++ b/www/lib/CoreLibs/Convert/Strings.php @@ -0,0 +1,81 @@ + $baseDir . '/lib/CoreLibs/Convert/Math.php', 'CoreLibs\\Convert\\MimeAppName' => $baseDir . '/lib/CoreLibs/Convert/MimeAppName.php', 'CoreLibs\\Convert\\MimeEncode' => $baseDir . '/lib/CoreLibs/Convert/MimeEncode.php', + 'CoreLibs\\Convert\\Strings' => $baseDir . '/lib/CoreLibs/Convert/Strings.php', 'CoreLibs\\Create\\Email' => $baseDir . '/lib/CoreLibs/Create/Email.php', 'CoreLibs\\Create\\Hash' => $baseDir . '/lib/CoreLibs/Create/Hash.php', 'CoreLibs\\Create\\RandomKey' => $baseDir . '/lib/CoreLibs/Create/RandomKey.php', diff --git a/www/vendor/composer/autoload_static.php b/www/vendor/composer/autoload_static.php index e150912e..ee64a887 100644 --- a/www/vendor/composer/autoload_static.php +++ b/www/vendor/composer/autoload_static.php @@ -92,6 +92,7 @@ class ComposerStaticInit10fe8fe2ec4017b8644d2b64bcf398b9 'CoreLibs\\Convert\\Math' => __DIR__ . '/../..' . '/lib/CoreLibs/Convert/Math.php', 'CoreLibs\\Convert\\MimeAppName' => __DIR__ . '/../..' . '/lib/CoreLibs/Convert/MimeAppName.php', 'CoreLibs\\Convert\\MimeEncode' => __DIR__ . '/../..' . '/lib/CoreLibs/Convert/MimeEncode.php', + 'CoreLibs\\Convert\\Strings' => __DIR__ . '/../..' . '/lib/CoreLibs/Convert/Strings.php', 'CoreLibs\\Create\\Email' => __DIR__ . '/../..' . '/lib/CoreLibs/Create/Email.php', 'CoreLibs\\Create\\Hash' => __DIR__ . '/../..' . '/lib/CoreLibs/Create/Hash.php', 'CoreLibs\\Create\\RandomKey' => __DIR__ . '/../..' . '/lib/CoreLibs/Create/RandomKey.php',