|
@ -16,8 +16,8 @@ class TestGB18030 extends \PHPUnit\Framework\TestCase { |
|
|
/** |
|
|
/** |
|
|
* @dataProvider provideCodePoints |
|
|
* @dataProvider provideCodePoints |
|
|
* @covers MensBeam\Intl\Encoding\GB18030::encode |
|
|
* @covers MensBeam\Intl\Encoding\GB18030::encode |
|
|
* @covers MensBeam\Intl\Encoding\GBK::encode |
|
|
|
|
|
* @covers MensBeam\Intl\Encoding\GB18030::err |
|
|
* @covers MensBeam\Intl\Encoding\GB18030::err |
|
|
|
|
|
* @covers MensBeam\Intl\Encoding\GBK::encode |
|
|
* @covers MensBeam\Intl\Encoding\GBK::err |
|
|
* @covers MensBeam\Intl\Encoding\GBK::err |
|
|
*/ |
|
|
*/ |
|
|
public function testEncodeCodePoints(string $class, bool $fatal, int $input, $exp) { |
|
|
public function testEncodeCodePoints(string $class, bool $fatal, int $input, $exp) { |
|
@ -33,11 +33,15 @@ class TestGB18030 extends \PHPUnit\Framework\TestCase { |
|
|
* @dataProvider provideStrings |
|
|
* @dataProvider provideStrings |
|
|
* @covers MensBeam\Intl\Encoding\GB18030::__construct |
|
|
* @covers MensBeam\Intl\Encoding\GB18030::__construct |
|
|
* @covers MensBeam\Intl\Encoding\GB18030::nextCode |
|
|
* @covers MensBeam\Intl\Encoding\GB18030::nextCode |
|
|
|
|
|
* @covers MensBeam\Intl\Encoding\GB18030::posChar |
|
|
*/ |
|
|
*/ |
|
|
public function testDecodeMultipleCharactersAsCodePoints(string $input, array $exp) { |
|
|
public function testDecodeMultipleCharactersAsCodePoints(string $input, array $exp) { |
|
|
$s = new GB18030(hex2bin($input)); |
|
|
$s = new GB18030(hex2bin($input)); |
|
|
$out = []; |
|
|
$out = []; |
|
|
|
|
|
$a = 0; |
|
|
|
|
|
$this->assertSame($a, $s->posChar()); |
|
|
while (($p = $s->nextCode()) !== false) { |
|
|
while (($p = $s->nextCode()) !== false) { |
|
|
|
|
|
$this->assertSame(++$a, $s->posChar()); |
|
|
$out[] = $p; |
|
|
$out[] = $p; |
|
|
} |
|
|
} |
|
|
$this->assertSame($exp, $out); |
|
|
$this->assertSame($exp, $out); |
|
@ -60,6 +64,27 @@ class TestGB18030 extends \PHPUnit\Framework\TestCase { |
|
|
$this->assertSame($exp, $out); |
|
|
$this->assertSame($exp, $out); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @dataProvider provideStrings |
|
|
|
|
|
* @covers MensBeam\Intl\Encoding\GB18030::seekBack |
|
|
|
|
|
*/ |
|
|
|
|
|
public function testSTepBackThroughAString(string $input, array $points) { |
|
|
|
|
|
$s = new GB18030(hex2bin($input)); |
|
|
|
|
|
$a = 0; |
|
|
|
|
|
$test1 = []; |
|
|
|
|
|
$test2 = []; |
|
|
|
|
|
while (($p1 = $s->nextCode()) !== false) { |
|
|
|
|
|
$test1[] = $p1; |
|
|
|
|
|
$this->assertSame(0, $s->seek(-1)); |
|
|
|
|
|
$p2 = $s->nextCode(); |
|
|
|
|
|
$test2[] = $p2; |
|
|
|
|
|
$this->assertSame($p1, $p2, "Mismatch at character position $a"); |
|
|
|
|
|
$this->assertSame(++$a, $s->posChar(), "Character position should be $a"); |
|
|
|
|
|
} |
|
|
|
|
|
$this->assertSame($points, $test1); |
|
|
|
|
|
$this->assertSame($points, $test2); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public function provideCodePoints() { |
|
|
public function provideCodePoints() { |
|
|
// bytes confirmed using Firefox |
|
|
// bytes confirmed using Firefox |
|
|
return [ |
|
|
return [ |
|
@ -104,6 +129,7 @@ class TestGB18030 extends \PHPUnit\Framework\TestCase { |
|
|
|
|
|
|
|
|
public function provideStrings() { |
|
|
public function provideStrings() { |
|
|
return [ |
|
|
return [ |
|
|
|
|
|
'empty string' => ["", []], |
|
|
// valid single characters |
|
|
// valid single characters |
|
|
'sanity check' => ["40", [64]], |
|
|
'sanity check' => ["40", [64]], |
|
|
'special case for 0x80' => ["80", [8364]], |
|
|
'special case for 0x80' => ["80", [8364]], |
|
@ -123,6 +149,15 @@ class TestGB18030 extends \PHPUnit\Framework\TestCase { |
|
|
'control second byte' => ["8100F437", [65533, 0, 65533]], |
|
|
'control second byte' => ["8100F437", [65533, 0, 65533]], |
|
|
'control third byte' => ["81350037", [65533, 53, 0, 55]], |
|
|
'control third byte' => ["81350037", [65533, 53, 0, 55]], |
|
|
'control fourth byte' => ["8135F400", [65533, 53, 65533, 0]], |
|
|
'control fourth byte' => ["8135F400", [65533, 53, 65533, 0]], |
|
|
|
|
|
// invalid sequences with clean EOF |
|
|
|
|
|
'bad first byte (padded)' => ["FF35F43700000000", [65533, 53, 65533, 55, 0, 0, 0, 0]], |
|
|
|
|
|
'bad second byte (padded)' => ["81FFF43700000000", [65533, 65533, 55, 0, 0, 0, 0]], |
|
|
|
|
|
'bad third byte (padded)' => ["8135FF3700000000", [65533, 53, 65533, 55, 0, 0, 0, 0]], |
|
|
|
|
|
'bad fourth byte (padded)' => ["8135F4FF00000000", [65533, 53, 65533, 0, 0, 0, 0]], |
|
|
|
|
|
'control first byte (padded)' => ["0035F43700000000", [0, 53, 65533, 55, 0, 0, 0, 0]], |
|
|
|
|
|
'control second byte (padded)' => ["8100F43700000000", [65533, 0, 65533, 55, 0, 0, 0, 0]], |
|
|
|
|
|
'control third byte (padded)' => ["8135003700000000", [65533, 53, 0, 55, 0, 0, 0, 0]], |
|
|
|
|
|
'control fourth byte (padded)' => ["8135F40000000000", [65533, 53, 65533, 0, 0, 0, 0, 0]], |
|
|
// out-of-range sequences |
|
|
// out-of-range sequences |
|
|
'void sequence' => ["8432A439", [65533]], |
|
|
'void sequence' => ["8432A439", [65533]], |
|
|
'void sequence 2' => ["FE39FE39", [65533]], |
|
|
'void sequence 2' => ["FE39FE39", [65533]], |
|
|