diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index b2357fa..bee0ebe 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -4,7 +4,7 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
-namespace MensBeam\UTF8;
+namespace MensBeam\Intl;
const NS_BASE = __NAMESPACE__."\\";
define(NS_BASE."BASE", dirname(__DIR__).DIRECTORY_SEPARATOR);
diff --git a/tests/cases/TestEncoding.php b/tests/cases/TestEncoding.php
new file mode 100644
index 0000000..a65313c
--- /dev/null
+++ b/tests/cases/TestEncoding.php
@@ -0,0 +1,56 @@
+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;
+ }
+}
diff --git a/tests/phpunit.xml b/tests/phpunit.xml
index 4874644..2037e9a 100644
--- a/tests/phpunit.xml
+++ b/tests/phpunit.xml
@@ -25,6 +25,8 @@
cases/Encoding/TestGB18030.php
cases/Encoding/TestBig5.php
cases/Encoding/TestEUCKR.php
+
+ cases/TestEncoding.php