Ejemplo n.º 1
0
 /**
  * @param Range $range
  * @return string
  */
 private function flattenRange(Range $range)
 {
     if ($range->representsSingleCodepoint()) {
         return $this->flattenCodepoint($range->getStart());
     }
     $start = $range->getStart();
     $end = $range->getEnd();
     return sprintf('\\x{%X}-\\x{%X}', $start->getValue(), $end->getValue());
 }
Ejemplo n.º 2
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'];
 }
Ejemplo n.º 3
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)));
 }
Ejemplo n.º 4
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)])]);
 }
Ejemplo n.º 5
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))]);
 }
Ejemplo n.º 6
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))]);
 }
Ejemplo n.º 7
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}]');
 }
Ejemplo n.º 8
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}]');
 }
Ejemplo n.º 9
0
 /**
  * @return Range
  * @throws UnexpectedValueException
  */
 private function getCurrentRange()
 {
     if ($this->rangeStart === null || $this->previous === null) {
         throw new UnexpectedValueException('Range values cannot be NULL');
     }
     return Range::between($this->rangeStart, $this->previous);
 }
Ejemplo n.º 10
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));
 }