J. King
4 years ago
33 changed files with 1681 additions and 890 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,10 +1,14 @@ |
|||
#! /bin/sh |
|||
base=`dirname "$0"` |
|||
roboCommand="$1" |
|||
|
|||
shift |
|||
if [ "$1" == "clean" ]; then |
|||
"$base/vendor/bin/robo" "$roboCommand" $* |
|||
if [ $# -eq 0 ]; then |
|||
"$base/vendor/bin/robo" |
|||
else |
|||
"$base/vendor/bin/robo" "$roboCommand" -- $* |
|||
fi |
|||
shift |
|||
ulimit -n 2048 |
|||
if [ "$1" = "clean" ]; then |
|||
"$base/vendor/bin/robo" "$roboCommand" "$@" |
|||
else |
|||
"$base/vendor/bin/robo" "$roboCommand" -- "$@" |
|||
fi |
|||
fi |
|||
|
@ -0,0 +1,56 @@ |
|||
<?php |
|||
/** @license MIT |
|||
* Copyright 2018 J. King et al. |
|||
* See LICENSE and AUTHORS files for details */ |
|||
|
|||
declare(strict_types=1); |
|||
namespace MensBeam\Intl\TestCase; |
|||
|
|||
use MensBeam\Intl\Encoding; |
|||
|
|||
class TestEncoding extends \PHPUnit\Framework\TestCase { |
|||
/** @dataProvider provideLabelData */ |
|||
public function testMatchALabelToAnEncoding(string $label, array $exp) { |
|||
$this->assertSame($exp, Encoding::matchLabel($label)); |
|||
$this->assertSame($exp, Encoding::matchLabel(strtoupper($label))); |
|||
$this->assertSame($exp, Encoding::matchLabel(" $label\n\n\r\t")); |
|||
} |
|||
|
|||
public function testFailToMatchALabelToAnEncoding() { |
|||
$this->assertNull(Encoding::matchLabel("Not a label")); |
|||
} |
|||
|
|||
/** @dataProvider provideLabelData */ |
|||
public function testCreateADecoderFromALabel(string $label, array $data) { |
|||
$this->assertInstanceOf($data['class'], Encoding::createDecoder($label, "")); |
|||
$this->assertInstanceOf($data['class'], Encoding::createDecoder(strtoupper($label), "")); |
|||
$this->assertInstanceOf($data['class'], Encoding::createDecoder(" $label\n\n\r\t", "")); |
|||
} |
|||
|
|||
public function testFailToCreateADecoderFromALabel() { |
|||
$this->assertNull(Encoding::createDecoder("Not a label", "")); |
|||
} |
|||
|
|||
public function provideLabelData() { |
|||
$ns = "MensBeam\\Intl\\Encoding\\"; |
|||
$labels = []; |
|||
$names = []; |
|||
foreach (new \GlobIterator(\MensBeam\Intl\BASE."/lib/Encoding/*.php", \FilesystemIterator::CURRENT_AS_PATHNAME) as $file) { |
|||
$file = basename($file, ".php"); |
|||
$className = $ns.$file; |
|||
$class = new \ReflectionClass($className); |
|||
if ($class->implementsInterface(\MensBeam\Intl\Encoding\Encoding::class) && $class->isInstantiable()) { |
|||
$name = $class->getConstant("NAME"); |
|||
$names[$name] = $className; |
|||
foreach ($class->getConstant("LABELS") as $label) { |
|||
$labels[$label] = $name; |
|||
} |
|||
} |
|||
} |
|||
$out = []; |
|||
foreach ($labels as $label => $name) { |
|||
$out[] = [(string) $label, ['label' => (string) $label, 'name' => $name, 'class' => $names[$name]]]; |
|||
} |
|||
return $out; |
|||
} |
|||
} |
@ -0,0 +1,40 @@ |
|||
<?php |
|||
// this script read and names and labels from each concrete |
|||
// class in the Encoding set and generates tables mapping labels |
|||
// to names and names to classes |
|||
|
|||
use MensBeam\Intl\Encoding\Encoding; |
|||
|
|||
define("BASE", dirname(__DIR__).DIRECTORY_SEPARATOR); |
|||
require_once BASE."vendor".DIRECTORY_SEPARATOR."autoload.php"; |
|||
|
|||
$ns = "\\MensBeam\\Intl\\Encoding\\"; |
|||
$labels = []; |
|||
$names = []; |
|||
foreach (new \GlobIterator(BASE."/lib/Encoding/*.php", \FilesystemIterator::CURRENT_AS_PATHNAME) as $file) { |
|||
$file = basename($file, ".php"); |
|||
$className = $ns.$file; |
|||
$class = new \ReflectionClass($className); |
|||
if ($class->implementsInterface(Encoding::class) && $class->isInstantiable()) { |
|||
$name = $class->getConstant("NAME"); |
|||
$names[$name] = $className; |
|||
foreach ($class->getConstant("LABELS") as $label) { |
|||
$labels[$label] = $name; |
|||
} |
|||
} |
|||
} |
|||
|
|||
$labelList = []; |
|||
foreach ($labels as $k => $v) { |
|||
$labelList[] = "'$k'=>\"$v\""; |
|||
} |
|||
$labelList = "const LABEL_MAP = [".implode(",", $labelList)."];"; |
|||
|
|||
$nameList = []; |
|||
foreach ($names as $k => $v) { |
|||
$nameList[] = "'$k'=>$v::class"; |
|||
} |
|||
$nameList = "const NAME_MAP = [".implode(",", $nameList)."];"; |
|||
|
|||
echo "$labelList\n"; |
|||
echo "$nameList\n"; |
File diff suppressed because it is too large
@ -1,5 +1,5 @@ |
|||
{ |
|||
"require": { |
|||
"phpunit/phpunit": "^6.5" |
|||
"phpunit/phpunit": "^8.5" |
|||
} |
|||
} |
|||
|
File diff suppressed because it is too large
File diff suppressed because it is too large
Loading…
Reference in new issue