diff --git a/Utils/MbStringUtils.php b/Utils/MbStringUtils.php index 9673ddf9a..008d3ffe6 100644 --- a/Utils/MbStringUtils.php +++ b/Utils/MbStringUtils.php @@ -283,44 +283,43 @@ final class MbStringUtils /** * Get the utf-8 boundary of a string * - * @param string $text To search for utf-8 boundary - * @param int $offset Search offset + * @param string $text QP text to search for utf-8 boundary + * @param int $length Last character boundary prior to this length * * @return int * * @since 1.0.0 */ - public static function utf8CharBoundary(string $text, int $offset = 0) : int + public static function utf8CharBoundary(string $text, int $length = 0) : int { $reset = 3; - $pos = $offset; do { - $lastChunk = \substr($text, $pos - $reset, $reset); + $lastChunk = \substr($text, $length - $reset, $reset); $encodedPos = \strpos($lastChunk, '='); if ($encodedPos === false) { break; } - $hex = \substr($text, $pos - $reset + $encodedPos + 1, 2); + $hex = \substr($text, $length - $reset + $encodedPos + 1, 2); $dec = \hexdec($hex); if ($dec < 128) { if ($encodedPos > 0) { - $pos -= $reset - $encodedPos; + $length -= $reset - $encodedPos; } break; } elseif ($dec >= 192) { - $pos -= $reset - $encodedPos; + $length -= $reset - $encodedPos; break; - } elseif ($dec < 192) { + } else { /* $dec < 192 */ $reset += 3; } } while (true); - return $pos; + return $length; } /** diff --git a/tests/Algorithm/Maze/MazeGeneratorTest.php b/tests/Algorithm/Maze/MazeGeneratorTest.php index 5bf5e3093..e3724d90d 100644 --- a/tests/Algorithm/Maze/MazeGeneratorTest.php +++ b/tests/Algorithm/Maze/MazeGeneratorTest.php @@ -12,7 +12,7 @@ */ declare(strict_types=1); -namespace phpOMS\tests\Algorithm\PathFinding; +namespace phpOMS\tests\Algorithm\Maze; use phpOMS\Algorithm\Maze\MazeGenerator; diff --git a/tests/Localization/L11nManagerTest.php b/tests/Localization/L11nManagerTest.php index b5665f6e8..7296743b8 100644 --- a/tests/Localization/L11nManagerTest.php +++ b/tests/Localization/L11nManagerTest.php @@ -140,8 +140,12 @@ class L11nManagerTest extends \PHPUnit\Framework\TestCase self::assertEquals('USD 1.235', $this->l11nManager->getCurrency($l11n, 1.2345, 'long')); $this->l11nManager->loadLanguage('en', '0', ['0' => ['CurrencyK' => 'K']]); + $this->l11nManager->loadLanguage('en', '0', ['0' => ['CurrencyM' => 'M']]); + $this->l11nManager->loadLanguage('en', '0', ['0' => ['CurrencyB' => 'B']]); self::assertEquals('K$ 12.345', $this->l11nManager->getCurrency($l11n, 12345.0, 'long', '$', 1000)); self::assertEquals('KUSD 12.345', $this->l11nManager->getCurrency($l11n, 12345.0, 'long', null, 1000)); + self::assertEquals('M$ 123.5', $this->l11nManager->getCurrency($l11n, 123456789.0, 'short', '$', 1000000)); + self::assertEquals('B$ 1.2', $this->l11nManager->getCurrency($l11n, 1234567890.0, 'short', '$', 1000000000)); } /** diff --git a/tests/Math/Topology/Metrics2DTest.php b/tests/Math/Topology/Metrics2DTest.php index a121956f5..589f1e0dc 100644 --- a/tests/Math/Topology/Metrics2DTest.php +++ b/tests/Math/Topology/Metrics2DTest.php @@ -12,7 +12,7 @@ */ declare(strict_types=1); -namespace phpOMS\tests\Math\Number; +namespace phpOMS\tests\Math\Topology; use phpOMS\Math\Topology\Metrics2D; diff --git a/tests/Math/Topology/MetricsNDTest.php b/tests/Math/Topology/MetricsNDTest.php index 91e3a47e6..cafe5ebb1 100644 --- a/tests/Math/Topology/MetricsNDTest.php +++ b/tests/Math/Topology/MetricsNDTest.php @@ -12,7 +12,7 @@ */ declare(strict_types=1); -namespace phpOMS\tests\Math\Number; +namespace phpOMS\tests\Math\Topology; use phpOMS\Math\Topology\Metrics2D; use phpOMS\Math\Topology\MetricsND; diff --git a/tests/Utils/ArrayUtilsTest.php b/tests/Utils/ArrayUtilsTest.php index 281b3e0c5..61e5e54fb 100644 --- a/tests/Utils/ArrayUtilsTest.php +++ b/tests/Utils/ArrayUtilsTest.php @@ -61,6 +61,32 @@ class ArrayUtilsTest extends \PHPUnit\Framework\TestCase self::assertEquals('ab0', ArrayUtils::getArray('a/ab/1', $expected)); } + /** + * @testdox A invalid array path returns null + * @covers phpOMS\Utils\ArrayUtils + * @group framework + */ + public function testArrayInvalidArrayPath() : void + { + $expected = [ + 'a' => [ + 'aa' => 1, + 'ab' => [ + 'aba', + 'ab0', + [ + 3, + 'c', + ], + 4, + ], + ], + 2 => '2a', + ]; + + self::assertEquals(null, ArrayUtils::getArray('a/zzz/1', $expected)); + } + /** * @testdox Test recursively if a value is in an array * @covers phpOMS\Utils\ArrayUtils @@ -106,6 +132,27 @@ class ArrayUtilsTest extends \PHPUnit\Framework\TestCase self::assertFalse(ArrayUtils::inArrayRecursive('aba', ArrayUtils::unsetArray('a/ab', $expected, '/'))); } + /** + * @testdox Deleting an invalid array path returns the original array + * @covers phpOMS\Utils\ArrayUtils + * @group framework + */ + public function testInvalidArrayDelete() : void + { + $expected = [ + 'a' => [ + 'aa' => 1, + 'ab' => [ + 'aba', + 'ab0', + ], + ], + 2 => '2a', + ]; + + self::assertEquals($expected, ArrayUtils::unsetArray('a/zzz', $expected, '/')); + } + /** * @testdox The recursive sum of all values in an array can be calculated * @covers phpOMS\Utils\ArrayUtils diff --git a/tests/Utils/MbStringUtilsTest.php b/tests/Utils/MbStringUtilsTest.php index 71f9e6952..a56cafcde 100644 --- a/tests/Utils/MbStringUtilsTest.php +++ b/tests/Utils/MbStringUtilsTest.php @@ -19,7 +19,7 @@ use phpOMS\Utils\MbStringUtils; require_once __DIR__ . '/../Autoloader.php'; /** - * @testdox phpOMS\tests\Utils\MbStringUtilsTest: String utilities + * @testdox phpOMS\tests\Utils\MbStringUtilsTest: Multi-Byte string utilities * * @internal */ @@ -152,8 +152,13 @@ class MbStringUtilsTest extends \PHPUnit\Framework\TestCase self::assertEquals(5, MbStringUtils::mb_count_chars('αααααΕεΙιΜμΨψ')['α']); } + /** + * @testdox The previous boundary of a utf-8 encoded quoted printable is identified correctly + * @covers phpOMS\Utils\MbStringUtils + * @group framework + */ public function testUtf8CharBoundary() : void { - self::markTestIncomplete(); + self::assertEquals(10, MbStringUtils::utf8CharBoundary('H=E4tten H=FCte ein =DF im Namen, w=E4ren sie m=F6glicherweise k', 12)); } } diff --git a/tests/Utils/StringUtilsTest.php b/tests/Utils/StringUtilsTest.php index e8f0e782a..38ee52f92 100644 --- a/tests/Utils/StringUtilsTest.php +++ b/tests/Utils/StringUtilsTest.php @@ -166,6 +166,16 @@ class StringUtilsTest extends \PHPUnit\Framework\TestCase })); } + /** + * @testdox Stringify/rendering a unknown data type returns null + * @covers phpOMS\Utils\StringUtils + * @group framework + */ + public function testInvalidStringify() : void + { + self::assertEquals(null, StringUtils::stringify(new class() {})); + } + /** * @testdox The difference between two strings can be evaluated * @covers phpOMS\Utils\StringUtils