Пример #1
0
 /**
  * @param Codepoint $codepoint
  * @return bool
  * @throws UnexpectedValueException
  */
 private function isPlusOneOfPrevious(Codepoint $codepoint)
 {
     if ($this->previous === null) {
         throw new UnexpectedValueException('Previous cannot be NULL');
     }
     return $this->previous->getValue() + 1 === $codepoint->getValue();
 }
Пример #2
0
 /**
  * @param mixed $other
  * @return bool
  */
 public function equals($other)
 {
     if ($this === $other) {
         return true;
     }
     return $other instanceof self && $this->codepoint->equals($other->codepoint);
 }
 /**
  * @param Codepoint $codepoint
  * @throws CharacterNotFoundException
  * @return CodepointAssigned
  */
 public function getByCodepoint(Codepoint $codepoint)
 {
     foreach ($this->getAll() as $character) {
         if ($codepoint->equals($character->getCodepoint())) {
             return $character;
         }
     }
     throw CharacterNotFoundException::withCodepoint($codepoint);
 }
Пример #4
0
 /**
  * @return Mirroring
  */
 private function parseMirroring()
 {
     $isMirrored = $this->getBoolAttribute(self::ATTR_MIRRORED);
     $mirroredByValue = $this->getOptionalAttribute(self::ATTR_MIRROR_GLYPH);
     $mirroredBy = $mirroredByValue !== null ? Codepoint::fromHex($mirroredByValue) : null;
     return new Mirroring($isMirrored, $mirroredBy);
 }
Пример #5
0
 protected function setUp()
 {
     $this->repository = new InMemoryRepository();
     $character = $this->buildCharacterWithCodepoint(Codepoint::fromInt(0));
     $characters = Collection::fromArray([$character]);
     $this->repository->addMany($characters);
 }
Пример #6
0
 protected function setUp()
 {
     $dbPath = $this->fs->path('/db');
     $propsPath = $this->fs->path('/props');
     mkdir($dbPath);
     mkdir($propsPath);
     $codepoint = Codepoint::fromInt(0);
     $path = $this->fs->path('/db/00000000-00000000!0001.php');
     $character = $this->buildCharacterWithCodepoint($codepoint);
     $content = sprintf("<?php\nreturn %s;", var_export([0 => serialize($character)], true));
     file_put_contents($path, $content);
     $path = $this->fs->path('/props/block.php');
     $collection = Codepoint\Range\Collection::fromArray([Codepoint\Range::between($codepoint, $codepoint)]);
     $content = sprintf("<?php\nreturn %s;", var_export(['ASCII' => serialize($collection->toArray())], true));
     file_put_contents($path, $content);
     $path = $this->fs->path('/props/gc.php');
     $collection = Codepoint\Range\Collection::fromArray([Codepoint\Range::between($codepoint, $codepoint)]);
     $content = sprintf("<?php\nreturn %s;", var_export(['Cc' => serialize($collection->toArray())], true));
     file_put_contents($path, $content);
     $path = $this->fs->path('/props/script.php');
     $collection = Codepoint\Range\Collection::fromArray([Codepoint\Range::between($codepoint, $codepoint)]);
     $content = sprintf("<?php\nreturn %s;", var_export(['Zyyy' => serialize($collection->toArray())], true));
     file_put_contents($path, $content);
     $this->registerContainerProviders();
     $this->container[ConfigurationProvider::CONFIG_KEY_DB_PATH] = $dbPath;
     $this->container[ConfigurationProvider::CONFIG_KEY_PROPS_PATH] = $propsPath;
     $this->repository = $this->container['repository.php'];
 }
Пример #7
0
 public function it_should_not_equal_an_instance_with_a_different_codepoint($properties)
 {
     $codepointA = Codepoint::fromInt(10);
     $codepointB = Codepoint::fromInt(11);
     $this->beConstructedWith($codepointA, $properties);
     $this->equals(new Character($codepointB, $properties->getWrappedObject()))->shouldReturn(false);
 }
Пример #8
0
 public function it_parses_numericity_for_numeric_characters()
 {
     $type = new NumericType(NumericType::NUMERIC);
     $number = new RationalNumber(1, 2, false);
     $expected = new Numeric($type, $number);
     $element = $this->givenTheCharElementFrom(self::XML_NUMERIC_DATA);
     $this->parseElement($element, Codepoint::fromInt(1))->shouldBeLike($expected);
 }
Пример #9
0
 /**
  * @return \Generator
  */
 private function yieldCodepoints()
 {
     $start = $this->getStart()->getValue();
     $end = $this->getEnd()->getValue();
     for ($i = $start; $i <= $end; $i++) {
         (yield Codepoint::fromInt($i));
     }
 }
Пример #10
0
 public function it_can_be_instantiated_from_encoded_characters()
 {
     $start = 'a';
     $end = 'z';
     $encoding = TransformationFormat::ofType(TransformationFormat::EIGHT);
     $this->beConstructedThrough('betweenEncodedCharacters', [$start, $end, $encoding]);
     $this->shouldBeLike(Range::between(Codepoint::fromInt(97), Codepoint::fromInt(122)));
 }
Пример #11
0
 /**
  * @param \DOMElement $element
  * @return CodepointAssigned[]
  */
 public function parseElement(\DOMElement $element)
 {
     $parser = $this->getParserForElement($element);
     $codepointValues = $this->extractCodepoints($element);
     foreach ($codepointValues as $codepointValue) {
         $codepoint = Codepoint::fromInt($codepointValue);
         (yield $parser->parseElement($element, $codepoint));
     }
 }
 public function it_delegates_for_each_codepoint_in_a_range($characterParser, Character $c1, Character $c2)
 {
     $element = $this->givenAnElementWithTagName(CodepointAssignedParser::TAG_NAME_CHAR);
     $element->setAttribute('first-cp', 1);
     $element->setAttribute('last-cp', 2);
     $characterParser->parseElement($element, Codepoint::fromInt(1))->willReturn($c1);
     $characterParser->parseElement($element, Codepoint::fromInt(2))->willReturn($c2);
     $this->parseElement($element)->shouldIterateLike([$c1, $c2]);
 }
 public function it_parses_bidirectionality_for_bracket_characters()
 {
     $classing = new Classing(Classing::OTHER_NEUTRAL);
     $mirroring = new Mirroring(true, Codepoint::fromInt(41));
     $bracket = Bracket::createOpen(Codepoint::fromInt(41));
     $expected = new BracketBidirectionality($classing, $mirroring, false, $bracket);
     $element = $this->givenTheCharElementFrom(self::XML_BIDI_BRACKET_DATA);
     $this->parseElement($element, Codepoint::fromInt(1))->shouldBeLike($expected);
 }
Пример #14
0
 public function it_exposes_all_ranges_built_by_aggregators(KeyGenerator $keyGenerator, CodepointAssigned $item)
 {
     $key = 'key';
     $cp = Codepoint::fromInt(1);
     $item->getCodepoint()->willReturn($cp);
     $keyGenerator->generateFor($item)->willReturn($key);
     $this->beConstructedWith($keyGenerator);
     $this->add($item);
     $this->getAllRanges()->shouldBeLike([$key => Range\Collection::fromArray([Range::between($cp, $cp)])]);
 }
Пример #15
0
 public function it_can_aggregate_mixtures_of_ranges_and_individual_codepoints()
 {
     $this->addCodepoint(Codepoint::fromInt(1));
     $this->addCodepoint(Codepoint::fromInt(2));
     $this->addCodepoint(Codepoint::fromInt(3));
     $this->addCodepoint(Codepoint::fromInt(10));
     $this->addCodepoint(Codepoint::fromInt(11));
     $this->addCodepoint(Codepoint::fromInt(20));
     $this->getAggregated()->shouldIterateLike([Range::between(Codepoint::fromInt(1), Codepoint::fromInt(3)), Range::between(Codepoint::fromInt(10), Codepoint::fromInt(11)), Range::between(Codepoint::fromInt(20), Codepoint::fromInt(20))]);
 }
Пример #16
0
 public function it_parses_shaping_scope_properties()
 {
     $group = new JoiningGroup(JoiningGroup::AIN);
     $type = new JoiningType(JoiningType::LEFT_JOINING);
     $joining = new Shaping\Joining($group, $type, false);
     $expected = new Shaping($joining);
     $dom = new \DOMDocument('1.0', 'UTF-8');
     $dom->loadXML(self::XML_DATA);
     $element = $dom->getElementsByTagName('char')->item(0);
     $this->parseElement($element, Codepoint::fromInt(0))->shouldBeLike($expected);
 }
Пример #17
0
 public function it_parses_normalization_scope_properties()
 {
     $combining = new Combining(Combining::OVERLAY);
     $decompositionType = new DecompositionType(DecompositionType::SUP);
     $decomposition = new Normalization\Decomposition\Assigned($decompositionType, [Codepoint::fromInt(97)]);
     $expected = new Normalization($combining, $decomposition);
     $dom = new \DOMDocument('1.0', 'UTF-8');
     $dom->loadXML(self::XML_DATA);
     $element = $dom->getElementsByTagName('char')->item(0);
     $this->parseElement($element, Codepoint::fromInt(0))->shouldBeLike($expected);
 }
Пример #18
0
 public function it_parses_case_properties()
 {
     $codepoint = Codepoint::fromInt(0);
     $lower = Codepoint::fromHex('65');
     $mappings = new LetterCase\Mappings(new LetterCase\Mapping($lower, [$lower]), new LetterCase\Mapping($codepoint, [$codepoint]), new LetterCase\Mapping($codepoint, [$codepoint]), new LetterCase\Mapping($codepoint, [$codepoint]));
     $expected = new LetterCase($mappings);
     $dom = new \DOMDocument('1.0', 'UTF-8');
     $dom->loadXML(self::XML_DATA);
     $element = $dom->getElementsByTagName('char')->item(0);
     $this->parseElement($element, $codepoint)->shouldBeLike($expected);
 }
Пример #19
0
 /**
  * @param string $value
  * @param string $encoding
  * @return Codepoint
  * @throws InvalidArgumentException
  */
 private function valueToCodepoint($value, $encoding)
 {
     if ($encoding === self::ENCODING_DECIMAL) {
         return Codepoint::fromInt((int) $value);
     } elseif ($encoding === self::ENCODING_HEXADECIMAL) {
         return Codepoint::fromHex($value);
     } elseif ($encoding === self::ENCODING_UTF8) {
         return Codepoint::fromUTF8($value);
     }
     throw new InvalidArgumentException(sprintf('Unknown encoding: %s', $encoding));
 }
Пример #20
0
 public function it_parses_general_scope_properties()
 {
     $primary = new Unassigned();
     $version1 = new Assigned('NULL');
     $names = new General\Names($primary, [], $version1);
     $block = new Block(Block::BASIC_LATIN);
     $age = new Version(Version::V1_1);
     $generalCategory = new GeneralCategory(GeneralCategory::OTHER_CONTROL);
     $script = new Script(Script::MALAYALAM);
     $expected = new General($names, $block, $age, $generalCategory, $script);
     $dom = new \DOMDocument('1.0', 'UTF-8');
     $dom->loadXML(self::XML_DATA);
     $element = $dom->getElementsByTagName('char')->item(0);
     $this->parseElement($element, Codepoint::fromInt(0))->shouldBeLike($expected);
 }
Пример #21
0
 /**
  * @test
  */
 public function it_displays_characters_residing_in_a_supplied_script()
 {
     $repository = new InMemoryRepository();
     $codepoint = Codepoint::fromInt(97);
     $script = Script::fromValue(Script::LATIN);
     $character = $this->buildCharacterWithCodepoint($codepoint, null, null, $script);
     $characters = Collection::fromArray([$character]);
     $repository->addMany($characters);
     $this->container['repository.test'] = $repository;
     $this->commandTester->execute(['command' => PropertiesCommand::COMMAND_NAME, '--from' => 'test', 'property-type' => PropertiesCommand::PROPERTY_SCRIPT, 'value' => $script->getValue()]);
     $output = $this->commandTester->getDisplay();
     $statusCode = $this->commandTester->getStatusCode();
     ha::assertThat('output', $output, hm::containsString('U+61:'));
     ha::assertThat('status code', $statusCode, hm::is(hm::identicalTo(0)));
 }
Пример #22
0
 public function it_parses_a_noncharacter_element_into_into_a_noncharacter_object()
 {
     $age = new Properties\General\Version(Properties\General\Version::V3_1);
     $primary = new Properties\General\Name\Unassigned();
     $names = new Properties\General\Names($primary, [], $primary);
     $block = new Properties\General\Block(Properties\General\Block::ARABIC_PRESENTATION_FORMS_A);
     $cat = new Properties\General\GeneralCategory(Properties\General\GeneralCategory::OTHER_NOT_ASSIGNED);
     $script = new Properties\General\Script(Properties\General\Script::UNKNOWN);
     $properties = new Properties\General($names, $block, $age, $cat, $script);
     $codepoint = Codepoint::fromInt(64976);
     $character = new NonCharacter($codepoint, $properties);
     $dom = new \DOMDocument('1.0', 'UTF-8');
     $dom->loadXML(self::XML_DATA);
     $element = $dom->getElementsByTagName('noncharacter')->item(0);
     $this->parseElement($element, $codepoint)->shouldBeLike($character);
 }
Пример #23
0
 public function it_parses_a_noncharacter_element_into_into_a_noncharacter_object()
 {
     $age = new Properties\General\Version(Properties\General\Version::V2_0);
     $primary = new Properties\General\Name\Unassigned();
     $names = new Properties\General\Names($primary, [], $primary);
     $block = new Properties\General\Block(Properties\General\Block::HIGH_SURROGATES);
     $cat = new Properties\General\GeneralCategory(Properties\General\GeneralCategory::OTHER_SURROGATE);
     $script = new Properties\General\Script(Properties\General\Script::UNKNOWN);
     $properties = new Properties\General($names, $block, $age, $cat, $script);
     $codepoint = Codepoint::fromInt(55296);
     $character = new Surrogate($codepoint, $properties);
     $dom = new \DOMDocument('1.0', 'UTF-8');
     $dom->loadXML(self::XML_DATA);
     $element = $dom->getElementsByTagName('surrogate')->item(0);
     $this->parseElement($element, $codepoint)->shouldBeLike($character);
 }
Пример #24
0
 /**
  * @test
  */
 public function it_displays_details_for_resolved_characters()
 {
     $repository = new InMemoryRepository();
     $codepoint = Codepoint::fromInt(163);
     $character = $this->buildCharacterWithCodepoint($codepoint);
     $characters = Collection::fromArray([$character]);
     $repository->addMany($characters);
     $this->container['repository.test'] = $repository;
     $this->commandTester->execute(['command' => SearchCommand::COMMAND_NAME, '--from' => 'test', '--enc' => SearchCommand::ENCODING_DECIMAL, 'codepoint' => $codepoint->getValue()]);
     $output = $this->commandTester->getDisplay();
     $statusCode = $this->commandTester->getStatusCode();
     ha::assertThat('output', $output, hm::containsString('Character Found'));
     ha::assertThat('output', $output, hm::containsString('Export: UCD\\Unicode\\Character'));
     ha::assertThat('output', $output, hm::containsString('UTF-8: £'));
     ha::assertThat('status code', $statusCode, hm::is(hm::identicalTo(0)));
 }
 /**
  * @test
  */
 public function it_transfers_characters_from_one_repository_to_another()
 {
     $codepoint = Codepoint::fromInt(1);
     $character = $this->buildCharacterWithCodepoint($codepoint);
     $characters = Collection::fromArray([$character]);
     $source = new InMemoryRepository();
     $source->addMany($characters);
     $destination = new InMemoryRepository();
     $this->container['repository.test-source'] = $source;
     $this->container['repository.test-destination'] = $destination;
     ha::assertThat(count($source), hm::is(hm::identicalTo(1)));
     ha::assertThat(count($destination), hm::is(hm::identicalTo(0)));
     $this->commandTester->execute(['command' => RepositoryTransferCommand::COMMAND_NAME, 'from' => 'test-source', 'to' => 'test-destination']);
     ha::assertThat(count($source), hm::is(hm::identicalTo(1)));
     ha::assertThat(count($destination), hm::is(hm::identicalTo(1)));
     $output = $this->commandTester->getDisplay();
     $statusCode = $this->commandTester->getStatusCode();
     ha::assertThat('output', $output, hm::containsString('Database Generated'));
     ha::assertThat('status code', $statusCode, hm::is(hm::identicalTo(0)));
 }
Пример #26
0
 public function it_can_be_reduced_to_a_regular_expression_character_class()
 {
     $this->givenTheCollectionContains([Range::between(Codepoint::fromInt(1), Codepoint::fromInt(3)), Range::between(Codepoint::fromInt(33), Codepoint::fromInt(33))]);
     $this->toRegexCharacterClass()->shouldEqual('[\\x{1}-\\x{3}\\x{21}]');
 }
Пример #27
0
 public function it_can_build_a_character_class_from_ranges()
 {
     $this->addRange(Range::between(Codepoint::fromInt(1), Codepoint::fromInt(10)));
     $this->addRange(Range::between(Codepoint::fromInt(33), Codepoint::fromInt(33)));
     $this->getCharacterClass()->shouldEqual('[\\x{1}-\\x{A}\\x{21}]');
 }
Пример #28
0
 /**
  * @test
  */
 public function it_can_be_added_to_if_writable()
 {
     if (!$this->repository instanceof WritableRepository) {
         $this->markTestSkipped('Repository is not writable');
     }
     $codepoint = Codepoint::fromInt(1);
     $addCharacter = $this->buildCharacterWithCodepoint($codepoint);
     $addCharacters = Character\Collection::fromArray([$addCharacter]);
     $this->repository->addMany($addCharacters);
     $character = $this->repository->getByCodepoint($codepoint);
     ha::assertThat('character', $character, hm::is(hm::equalTo($addCharacter)));
     ha::assertThat('count', count($this->repository), hm::is(hm::equalTo(2)));
 }
Пример #29
0
 public function it_exposes_codepoints_for_a_requested_script(Character $c1, Character $c2, Character $c3)
 {
     $this->givenCharacterHasCodepointWithValue($c1, 1);
     $this->givenCharacterHasCodepointWithValue($c2, 2);
     $this->givenCharacterHasCodepointWithValue($c3, 3);
     $this->givenCharacterResidesInScript($c1, Script::fromValue(Script::SAMARITAN));
     $this->givenCharacterResidesInScript($c2, Script::fromValue(Script::SAMARITAN));
     $this->givenCharacterResidesInScript($c3, Script::fromValue(Script::COMMON));
     $this->givenTheRepositoryHasCharacters([$c1, $c2, $c3]);
     $this->getCodepointsByScript(Script::fromValue(Script::SAMARITAN))->shouldIterateLike([Range::between(Codepoint::fromInt(1), Codepoint::fromInt(2))]);
 }
Пример #30
0
 /**
  * @param Codepoint $codepoint
  * @return string
  */
 private function flattenCodepoint(Codepoint $codepoint)
 {
     return sprintf('\\x{%X}', $codepoint->getValue());
 }