diff --git a/README.md b/README.md index 1bdbe62..270a891 100644 --- a/README.md +++ b/README.md @@ -23,23 +23,39 @@ composer require cybercog/php-unicode ### Instantiate CodePoint object ```php -$codePoint = CodePoint::ofCharacter('A'); +$codePoint = \Cog\Unicode\CodePoint::ofCharacter('ΓΏ'); -$codePoint = CodePoint::ofDecimal(65); +$codePoint = \Cog\Unicode\CodePoint::ofDecimal(255); -$codePoint = CodePoint::ofHexadecimal('U+0041'); +$codePoint = \Cog\Unicode\CodePoint::ofHexadecimal('U+00FF'); + +$codePoint = \Cog\Unicode\CodePoint::ofHtmlEntity('ÿ'); + +$codePoint = \Cog\Unicode\CodePoint::ofXmlEntity('ÿ'); ``` ### Represent code points in any format ```php -$codePoint = CodePoint::ofCharacter('A'); +$codePoint = \Cog\Unicode\CodePoint::ofCharacter('ΓΏ'); + +echo $codePoint->toCharacter(); // (string) "ΓΏ" + +echo $codePoint->toDecimal(); // (int) 255 + +echo $codePoint->toHexadecimal(); // (string) "U+00FF" -echo $codePoint->toCharacter(); // (string) "A" +echo $codePoint->toHtmlEntity(); // (string) "ÿ" -echo $codePoint->toDecimal(); // (int) 65 +echo $codePoint->toXmlEntity(); // (string) "ÿ" +``` + +### Instantiate CompositeCharacter object + +```php +$compositeCharacter = \Cog\Unicode\CompositeCharacter::ofCharacters('πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦'); -echo $codePoint->toHexadecimal(); // (string) "U+0041" +$compositeCharacter->toCharacters(); // (string) "πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦" ``` ## License diff --git a/test/Unit/CompositeCharacterTest.php b/test/Unit/CompositeCharacterTest.php index 13a78f5..dd33bec 100644 --- a/test/Unit/CompositeCharacterTest.php +++ b/test/Unit/CompositeCharacterTest.php @@ -9,8 +9,20 @@ final class CompositeCharacterTest extends TestCase { - /** @dataProvider provideUnicodeMap */ - public function testItCanInstantiateOfCharacters( + /** @dataProvider provideUnicodeMapSimple */ + public function testItCanInstantiateOfCharactersWithSingleCharacter( + string $characters + ): void { + $compositeCharacter = CompositeCharacter::ofCharacters($characters); + + $this->assertSame( + $characters, + $compositeCharacter->toCharacters(), + ); + } + + /** @dataProvider provideUnicodeMapComposite */ + public function testItCanInstantiateOfCharactersWithManyCharacters( string $characters ): void { $compositeCharacter = CompositeCharacter::ofCharacters($characters); @@ -30,7 +42,7 @@ public function testItCannotInstantiateOfCharactersWithEmptyString(): void CompositeCharacter::ofCharacters($characters); } - public static function provideUnicodeMap(): array + public static function provideUnicodeMapSimple(): array { return [ ["\x00"], @@ -44,4 +56,11 @@ public static function provideUnicodeMap(): array ['οΏ½'], ]; } + + public static function provideUnicodeMapComposite(): array + { + return [ + ['πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦'], + ]; + } }