예제 #1
0
 protected function setUp()
 {
     $this->repository = new InMemoryRepository();
     $character = $this->buildCharacterWithCodepoint(Codepoint::fromInt(0));
     $characters = Collection::fromArray([$character]);
     $this->repository->addMany($characters);
 }
예제 #2
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);
 }
예제 #3
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'];
 }
예제 #4
0
 /**
  * @return \Generator
  */
 private function yieldCodepoints()
 {
     $start = $this->getStart()->getValue();
     $end = $this->getEnd()->getValue();
     for ($i = $start; $i <= $end; $i++) {
         (yield Codepoint::fromInt($i));
     }
 }
예제 #5
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)));
 }
예제 #6
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);
 }
 /**
  * @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);
 }
예제 #10
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))]);
 }
예제 #11
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)])]);
 }
예제 #12
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));
 }
예제 #13
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);
 }
예제 #14
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);
 }
예제 #15
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);
 }
예제 #16
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)));
 }
예제 #17
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);
 }
예제 #18
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);
 }
예제 #19
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);
 }
예제 #20
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)));
 }
예제 #22
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)));
 }
예제 #23
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))]);
 }
예제 #24
0
 private function givenEntityHasCodepointWithValue(CodepointAssigned $entity, $value)
 {
     $entity->getCodepoint()->willReturn(Codepoint::fromInt($value));
 }
예제 #25
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}]');
 }
예제 #26
0
 public function it_exposes_codepoints_for_a_requested_script($propertiesDirectory, PropertyFile $file)
 {
     $propertiesDirectory->getFileForProperty(Property::ofType(Property::SCRIPT))->willReturn($file);
     $file->read()->willReturn([Script::SAMARITAN => 's:{}']);
     $this->serializer->unserialize('s:{}')->willReturn($r = [Codepoint\Range::between(Codepoint::fromInt(0), Codepoint::fromInt(1))]);
     $this->getCodepointsByScript(Script::fromValue(Script::SAMARITAN))->shouldBeLike(Collection::fromArray($r));
 }
예제 #27
0
 public function it_should_expose_its_general_properties(General $properties)
 {
     $properties->getBlock()->willReturn(new Block(Block::HIGH_PRIVATE_USE_SURROGATES));
     $this->beConstructedWith(Codepoint::fromInt(0), $properties);
     $this->getGeneralProperties()->shouldReturn($properties);
 }
예제 #28
0
 /**
  * @param Character $character
  * @param int $value
  */
 protected function givenCharacterHasCodepointWithValue($character, $value)
 {
     $character->getCodepoint()->willReturn(Codepoint::fromInt($value));
     $character->getCodepointValue()->willReturn($value);
 }
예제 #29
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}]');
 }
예제 #30
0
 public function it_delegates_getByCodepoints_calls($repository, Character $character)
 {
     $codepoints = Codepoint\Collection::fromArray([Codepoint::fromInt(1)]);
     $repository->getByCodepoints($codepoints)->willReturn($character);
     $this->getByCodepoints($codepoints)->shouldReturn($character);
 }