diff --git a/4dev/tests/CoreLibsDebugLoggingTest.php b/4dev/tests/CoreLibsDebugLoggingTest.php new file mode 100644 index 00000000..6bb5d1c5 --- /dev/null +++ b/4dev/tests/CoreLibsDebugLoggingTest.php @@ -0,0 +1,36 @@ + [ 0 => null, - 1 => '/^\d{4}\.\d{5,}$/' + 1 => '/^\d{4}\.\d{1,}$/' ], 'nanoseconds' => [ 0 => 'ns', @@ -28,19 +26,19 @@ final class CoreLibsDebugRunningTimeTest extends TestCase ], 'microseconds' => [ 0 => 'ys', - 1 => '/^\d{7}\.\d{3}$/' + 1 => '/^\d{7}\.\d{1,}$/' ], 'milliseconds' => [ 0 => 'ms', - 1 => '/^\d{4}\.\d{6}$/' + 1 => '/^\d{4}\.\d{1,}$/' ], 'seconds' => [ 0 => 's', - 1 => '/^\d{1}\.\d{9}$/' + 1 => '/^\d{1}\.\d{4,}$/' ], 'invalid fallback to ms' => [ 0 => 'invalid', - 1 => '/^\d{4}\.\d{6}$/' + 1 => '/^\d{4}\.\d{1,}$/' ] ]; } @@ -49,9 +47,11 @@ final class CoreLibsDebugRunningTimeTest extends TestCase { return [ 'run time test' => [ - 0 => '/^\d{1}$/', - 1 => '/^Start: \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} 0\.\d{7,}$/', - 2 => '/^Start:$/' + 0 => '/^\d{1,}\.\d{1,}$/', + 1 => '/^Start: \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} 0\.\d{8}, $/', + 2 => '/^Start: \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} 0\.\d{8}, ' + . 'End: \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} 0\.\d{8}, ' + . 'Run: \d{1,}\.\d{1,} s$/' ] ]; } @@ -80,6 +80,7 @@ final class CoreLibsDebugRunningTimeTest extends TestCase } else { $end = \CoreLibs\Debug\RunningTime::hrRunningTime($out_time); } + // print "E: " . $end . "\n"; $this->assertMatchesRegularExpression( $expected, (string)$end @@ -100,20 +101,24 @@ final class CoreLibsDebugRunningTimeTest extends TestCase public function testRunningTime(string $expected_number, string $expected_start, string $expected_end): void { $start = \CoreLibs\Debug\RunningTime::runningTime(true); + // print "Start: " . $start . "\n"; $this->assertEquals( 0, $start ); + // print "STRING: " . \CoreLibs\Debug\RunningTime::runningTimeString() . "\n"; $this->assertMatchesRegularExpression( $expected_start, \CoreLibs\Debug\RunningTime::runningTimeString() ); time_nanosleep(1, 500); $end = \CoreLibs\Debug\RunningTime::runningTime(true); + // print "Start: " . $end . "\n"; $this->assertMatchesRegularExpression( $expected_number, (string)$end ); + // print "STRING: " . \CoreLibs\Debug\RunningTime::runningTimeString() . "\n"; $this->assertMatchesRegularExpression( $expected_end, \CoreLibs\Debug\RunningTime::runningTimeString() diff --git a/www/admin/class_test.array.php b/www/admin/class_test.array.php index df7c4c97..98524a19 100644 --- a/www/admin/class_test.array.php +++ b/www/admin/class_test.array.php @@ -65,6 +65,8 @@ echo "ARRAYSEARCHRECURSIVE(email, [array]['input'], type): " // all return echo "ARRAYSEARCHRECURSIVEALL(email, [array], type): " . Dgs::printAr((array)ArrayHandler::arraySearchRecursiveAll('email', $test_array, 'type')) . "
"; + echo "ARRAYSEARCHRECURSIVEALL(email, [array], type, false): " + . Dgs::printAr((array)ArrayHandler::arraySearchRecursiveAll('email', $test_array, 'type', false)) . "
"; // simple search echo "ARRAYSEARCHSIMPLE([array], type, email): " @@ -139,24 +141,6 @@ function rec(string $pre, string $cur, array $node = []) return $node; } -/** - * flatten array down to own level - * - * @param array $array - * @param array $return - * @return array - */ -function flattenArrayKey(array $array, array $return = []) -{ - foreach ($array as $key => $sub) { - $return[] = $key; - if (count($sub) > 0) { - $return = flattenArrayKey($sub, $return); - } - } - return $return; -} - // $test = [ // 'A' => [ // 'B' => [], @@ -193,7 +177,34 @@ $test = rec('F', 'U', $test); $test = rec('', 'Al', $test); $test = rec('B', 'B1', $test); print "ORIGINAL: " . \CoreLibs\Debug\Support::printAr($test) . "
"; -print "FLATTEN: " . \CoreLibs\Debug\Support::printAr(flattenArrayKey($test)) . "
"; +print "FLATTEN-c: " . \CoreLibs\Debug\Support::printAr(ArrayHandler::flattenArrayKey($test)) . "
"; + +$test = [ + 'a' => ['a1' => 'a1foo', 'a2' => 'a1bar'], + 1 => 'bar', + 'c' => [2, 3, 4], + 'd' => [ + 'e' => [ + 'de1' => 'subfoo', 'de2' => 'subbar', 'a2' => 'a1bar' + ] + ] +]; +print "ORIGINAL: " . \CoreLibs\Debug\Support::printAr($test) . "
"; +print "FLATTEN: " . \CoreLibs\Debug\Support::printAr(ArrayHandler::flattenArrayKey($test)) . "
"; + +// genAssocArray +$db_array = [ + 0 => ['a' => 'a1', 'b' => 2], + 1 => ['a' => 'a2', 'b' => 3], + 2 => ['a' => '', 'b' => ''], +]; +// $key = false; +$key = 'a'; +// $value = false; +$value = 'b'; +$flag = false; +$output = \CoreLibs\Combined\ArrayHandler::genAssocArray($db_array, $key, $value, $flag); +print "OUTPUT: " . \CoreLibs\Debug\Support::printAr($output) . "
"; // error message print $basic->log->printErrorMsg(); diff --git a/www/admin/class_test.byte.php b/www/admin/class_test.byte.php index 7cbacf84..b255ebc3 100644 --- a/www/admin/class_test.byte.php +++ b/www/admin/class_test.byte.php @@ -43,10 +43,23 @@ $byte = 254779258; $string = '242.98 MB'; // static print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte) . "
"; +print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_SI) . "
"; +print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_ADJUST) . "
"; +print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_NOSPACE) . "
"; +print "S::BYTE FROM: $string: " . $byte_class::stringByteFormat($string) . "
"; +// +$byte = 314572800; +$string = '300 MB'; +print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte) . "
"; +print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_SI) . "
"; +print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_ADJUST) . "
"; +print "S::BYTE TO: $byte: " + . $byte_class::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_ADJUST | Byte::BYTE_FORMAT_NOSPACE) . "
"; +print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_NOSPACE) . "
"; print "S::BYTE FROM: $string: " . $byte_class::stringByteFormat($string) . "
"; // *** BYTES TEST *** -$bytes = array( +$bytes = [ -123123123, 999999, // KB-1 999999999, // MB-1 @@ -56,7 +69,7 @@ $bytes = array( 999999999999999999, // PB-1 9223372036854775807, // MAX INT 999999999999999999999, // EB-1 -); +]; print "BYTE FORMAT TESTS
"; foreach ($bytes as $byte) { print '
'; diff --git a/www/admin/class_test.colors.php b/www/admin/class_test.colors.php index 54d35d19..d49f4071 100644 --- a/www/admin/class_test.colors.php +++ b/www/admin/class_test.colors.php @@ -43,7 +43,7 @@ print '
Class Test Master
'; // A(out of bounds) print "C::S/COLOR invalid rgb->hex (gray 125): -1, -1, -1: " . CoreLibs\Convert\Colors::rgb2hex(-1, -1, -1) . "
"; -print "\$C::S/COLOR invalid rgb->hex (gary 125): -1, -1, -1: " . $color_class::rgb2hex(-1, -1, -1) . "
"; +print "\$C::S/COLOR invalid rgb->hex (gray 125): -1, -1, -1: " . $color_class::rgb2hex(-1, -1, -1) . "
"; // B(valid) $rgb = [10, 20, 30]; $hex = '#0a141e'; @@ -63,6 +63,10 @@ print "S::COLOR hsb->rgb: $hsb[0], $hsb[1], $hsb[2]: " print "S::COLOR hsl->rgb: $hsl[0], $hsl[1], $hsl[2]: " . DgS::printAr(Colors::hsl2rgb($hsl[0], $hsl[1], $hsl[2])) . "
"; +$hsb = [0, 0, 5]; +print "S::COLOR hsb->rgb: $hsb[0], $hsb[1], $hsb[2]: " + . DgS::printAr(Colors::hsb2rgb($hsb[0], $hsb[1], $hsb[2])) . "
"; + // TODO: run compare check input must match output // error message diff --git a/www/admin/class_test.html.php b/www/admin/class_test.html.php index 93be8ac5..10c6f663 100644 --- a/www/admin/class_test.html.php +++ b/www/admin/class_test.html.php @@ -72,7 +72,7 @@ $checked_list = [ ]; foreach ($checked_list as $check) { print "CHECKED(0): $check[0]: " . Html::checked($check[1], $check[0]) . "
"; - print "CHECKED(1): $check[0]: " . Html::checked($check[1], $check[0], 1) . "
"; + print "CHECKED(1): $check[0]: " . Html::checked($check[1], $check[0], Html::CHECKED) . "
"; } // magic link creation test diff --git a/www/admin/class_test.json.php b/www/admin/class_test.json.php index 628211b0..09cc1e78 100644 --- a/www/admin/class_test.json.php +++ b/www/admin/class_test.json.php @@ -29,11 +29,12 @@ if (!defined('SET_SESSION_NAME')) { $LOG_FILE_ID = 'classTest-json'; ob_end_flush(); -use CoreLibs\Check\Jason; +use CoreLibs\Check\Json; +// use CoreLibs\Check\Jason; use CoreLibs\Debug\Support as DgS; $basic = new CoreLibs\Basic(); -$json_class = 'CoreLibs\Check\Jason'; +$json_class = 'CoreLibs\Check\Json'; // define a list of from to color sets for conversion test @@ -42,14 +43,14 @@ print ""; print '
Class Test Master
'; $json = '{"foo": "bar"}'; -$output = Jason::jsonConvertToArray($json); +$output = Json::jsonConvertToArray($json); print "S::JSON: $json: " . DgS::printAr($output) . "
"; -print "S::JSON ERROR: " . Jason::jsonGetLastError() . ": " . Jason::jsonGetLastError(true) . "
"; +print "S::JSON ERROR: " . Json::jsonGetLastError() . ": " . Json::jsonGetLastError(true) . "
"; $json = '["f: {b"""ar}]'; -$output = Jason::jsonConvertToArray($json); +$output = Json::jsonConvertToArray($json); print "S::E-JSON: $json: " . DgS::printAr($output) . "
"; -print "S::E-JSON ERROR: " . Jason::jsonGetLastError() . ": " . Jason::jsonGetLastError(true) . "
"; +print "S::E-JSON ERROR: " . Json::jsonGetLastError() . ": " . Json::jsonGetLastError(true) . "
"; // direct $json = '{"direct": "static function call"}'; @@ -68,6 +69,11 @@ $output = $basic->jsonConvertToArray($json); print "E-JSON: $json: ".DgS::printAr($output)."
"; print "E-JSON ERROR: ".$basic->jsonGetLastError().": ".$basic->jsonGetLastError(true)."
"; */ +// $json = '{"foo": "bar"}'; +// $output = Jason::jsonConvertToArray($json); +// print "S::JSON: $json: " . DgS::printAr($output) . "
"; +// print "S::JSON ERROR: " . Jason::jsonGetLastError() . ": " . Jason::jsonGetLastError(true) . "
"; + // error message print $basic->log->printErrorMsg();