Intl/tests/cases/Encoding/TestEUCKR.php

190 lines
223 KiB
PHP
Raw Normal View History

2018-09-15 13:30:30 -04:00
<?php
/** @license MIT
* Copyright 2018 J. King et al.
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace MensBeam\Intl\TestCase\Encoding;
use MensBeam\Intl\Encoding\EUCKR;
use MensBeam\Intl\Encoding\Encoding;
use MensBeam\Intl\Encoding\EncoderException;
class TestEUCKR extends \MensBeam\Intl\Test\CoderDecoderTest {
protected $testedClass = EUCKR::class;
2018-09-15 19:46:42 -04:00
/*
Char 0 U+007A (1 byte) Offset 0
Char 1 U+ACF2 (2 bytes) Offset 1
Char 2 U+0020 (1 byte) Offset 3
Char 3 U+6C34 (2 bytes) Offset 4
Char 4 U+0391 (2 bytes) Offset 6
Char 5 U+03C9 (2 bytes) Offset 8
Char 6 U+002A (1 byte) Offset 10
End of string at char 7, offset 11
*/
protected $seekString = "7A 81E9 20 E2A9 A5C1 A5F8 2A";
protected $seekCodes = [0x7A, 0xACF2, 0x20, 0x6C34, 0x391, 0x3C9, 0x2A];
protected $seekOffsets = [0, 1, 3, 4, 6, 8, 10, 11];
2018-09-15 13:30:30 -04:00
/* This string contains an invalid character sequence sandwiched between two null characters */
2018-09-15 19:46:42 -04:00
protected $brokenChar = "00 FF 00";
2018-09-15 13:30:30 -04:00
/**
* @dataProvider provideCodePoints
* @covers MensBeam\Intl\Encoding\EUCKR::encode
* @covers MensBeam\Intl\Encoding\EUCKR::err
*/
2018-09-15 13:30:30 -04:00
public function testEncodeCodePoints(bool $fatal, $input, $exp) {
return parent::testEncodeCodePoints($fatal, $input, $exp);
}
/**
* @dataProvider provideStrings
* @covers MensBeam\Intl\Encoding\EUCKR::__construct
* @covers MensBeam\Intl\Encoding\EUCKR::nextCode
*/
2018-09-15 13:30:30 -04:00
public function testDecodeMultipleCharactersAsCodePoints(string $input, array $exp) {
return parent::testDecodeMultipleCharactersAsCodePoints($input, $exp);
}
/**
* @dataProvider provideStrings
* @covers MensBeam\Intl\Encoding\EUCKR::__construct
* @covers MensBeam\Intl\Encoding\EUCKR::nextChar
*/
2018-09-15 13:30:30 -04:00
public function testDecodeMultipleCharactersAsStrings(string $input, array $exp) {
return parent::testDecodeMultipleCharactersAsStrings($input, $exp);
}
/**
* @dataProvider provideStrings
* @covers MensBeam\Intl\Encoding\EUCKR::seekBack
*/
2018-09-15 13:30:30 -04:00
public function testSTepBackThroughAString(string $input, array $exp) {
return parent::testSTepBackThroughAString($input, $exp);
}
/**
* @covers MensBeam\Intl\Encoding\EUCKR::seek
* @covers MensBeam\Intl\Encoding\EUCKR::posChar
* @covers MensBeam\Intl\Encoding\EUCKR::posByte
* @covers MensBeam\Intl\Encoding\EUCKR::rewind
*/
2018-09-15 13:30:30 -04:00
public function testSeekThroughAString() {
return parent::testSeekThroughAString();
}
/**
* @covers MensBeam\Intl\Encoding\EUCKR::posChar
* @covers MensBeam\Intl\Encoding\EUCKR::posByte
2019-12-13 11:00:25 -05:00
* @covers MensBeam\Intl\Encoding\EUCKR::eof
*/
2018-09-15 13:30:30 -04:00
public function testTraversePastTheEndOfAString() {
return parent::testTraversePastTheEndOfAString();
}
/**
* @covers MensBeam\Intl\Encoding\EUCKR::peekChar
* @covers MensBeam\Intl\Encoding\EUCKR::stateSave
* @covers MensBeam\Intl\Encoding\EUCKR::stateApply
*/
2018-09-15 13:30:30 -04:00
public function testPeekAtCharacters() {
return parent::testPeekAtCharacters();
}
/**
* @covers MensBeam\Intl\Encoding\EUCKR::peekCode
* @covers MensBeam\Intl\Encoding\EUCKR::stateSave
* @covers MensBeam\Intl\Encoding\EUCKR::stateApply
*/
2018-09-15 13:30:30 -04:00
public function testPeekAtCodePoints() {
return parent::testPeekAtCodePoints();
}
/**
* @dataProvider provideStrings
2019-12-13 11:00:25 -05:00
* @covers MensBeam\Intl\Encoding\EUCKR::lenChar
* @covers MensBeam\Intl\Encoding\EUCKR::lenByte
2018-09-15 13:30:30 -04:00
* @covers MensBeam\Intl\Encoding\EUCKR::stateSave
* @covers MensBeam\Intl\Encoding\EUCKR::stateApply
*/
2018-09-15 13:30:30 -04:00
public function testGetStringLength(string $input, array $points) {
return parent::testGetStringLength($input, $points);
}
/**
* @covers MensBeam\Intl\Encoding\EUCKR::err
*/
2018-09-15 13:30:30 -04:00
public function testReplacementModes() {
return parent::testReplacementModes();
}
/**
* @dataProvider provideStrings
* @covers MensBeam\Intl\Encoding\EUCKR::rewind
* @covers MensBeam\Intl\Encoding\EUCKR::chars
* @covers MensBeam\Intl\Encoding\EUCKR::codes
*/
2018-09-15 13:30:30 -04:00
public function testIterateThroughAString(string $input, array $exp) {
return parent::testIterateThroughAString($input, $exp);
}
/**
* @dataProvider provideStrings
* @coversNothing
*/
public function testIterateThroughAStringAllowingSurrogates(string $input, array $strictExp, array $relaxedExp = null) {
return parent::testIterateThroughAStringAllowingSurrogates($input, $strictExp, $relaxedExp);
}
2018-09-15 13:30:30 -04:00
public function provideCodePoints() {
return [
2018-09-15 19:46:42 -04:00
'U+0064 (HTML)' => [false, 0x64, "64"],
'U+0064 (fatal)' => [true, 0x64, "64"],
'U+00CA (HTML)' => [false, 0xCA, bin2hex("&#202;")],
'U+00CA (fatal)' => [true, 0xCA, new EncoderException("", Encoding::E_UNAVAILABLE_CODE_POINT)],
'U+ACF2 (HTML)' => [false, 0xACF2, "81 E9"],
'U+ACF2 (fatal)' => [true, 0xACF2, "81 E9"],
'-1 (HTML)' => [false, -1, new EncoderException("", Encoding::E_INVALID_CODE_POINT)],
'-1 (fatal)' => [true, -1, new EncoderException("", Encoding::E_INVALID_CODE_POINT)],
'0x110000 (HTML)' => [false, 0x110000, new EncoderException("", Encoding::E_INVALID_CODE_POINT)],
'0x110000 (fatal)' => [true, 0x110000, new EncoderException("", Encoding::E_INVALID_CODE_POINT)],
2018-09-15 13:30:30 -04:00
];
}
public function provideStrings() {
return [
2018-09-15 19:46:42 -04:00
'empty string' => ["", []],
'sanity check' => ["40", [64]],
'two-byte character' => ["D7 D7", [21033]],
'EOF after first byte' => ["D7", [65533]],
'low byte after first byte' => ["D7 39", [65533, 57]],
'0x80 as first byte' => ["80 D7 00", [65533, 65533, 0]],
'0xFF as first byte' => ["FF D7 00", [65533, 65533, 0]],
'0x7F after first byte' => ["D7 7F", [65533, 127]],
'0xFF after first byte' => ["D7 FF", [65533]],
'non-character' => ["A5 DC", [65533]],
'mixed string' => ["7A D7 AA A4 F4 88 62 88 A5", [122, 30267, 12676, 45714, 45802]],
'mixed string 2' => ["62 D7 D7 D7 D7 62", [98, 21033, 21033, 98]],
2018-09-15 13:30:30 -04:00
];
}
/**
* @group optional
*/
2018-09-15 13:30:30 -04:00
public function testPedanticallyDecodeSingleCharactersAsCodePoint() {
$series = [
'characters' => [["A2AE","A2B4","A1D7","A1A7","A8A3","A1A9","A2E7","A1C6","A1BE","A9F7","A9F8","A2A5","A2D2","A1A4","A2AC","A9F6","A8AC","A8F9","A8F6","A8FA","A2AF","A8A1","A8A2","A1BF","A8AA","A8AD","A9AC","A9A1","A9A3","A1C0","A9AA","A9AD","A9A2","A8A4","A9A4","A9A5","A8A6","A9A6","A9A7","A8A8","A9A8","A8A9","A9A9","A9B0","A8AF","A9AF","A8AB","A9AB","A8AE","A9AE","A2A7","A2B0","A2A8","A2AB","A2AA","A2AD","A2A9","A5C1","A5C2","A5C3","A5C4","A5C5","A5C6","A5C7","A5C8","A5C9","A5CA","A5CB","A5CC","A5CD","A5CE","A5CF","A5D0","A5D1","A5D2","A5D3","A5D4","A5D5","A5D6","A5D7","A5D8","A5E1","A5E2","A5E3","A5E4","A5E5","A5E6","A5E7","A5E8","A5E9","A5EA","A5EB","A5EC","A5ED","A5EE","A5EF","A5F0","A5F1","A5F2","A5F3","A5F4","A5F5","A5F6","A5F7","A5F8","ACA7","ACA1","ACA2","ACA3","ACA4","ACA5","ACA6","ACA8","ACA9","ACAA","ACAB","ACAC","ACAD","ACAE","ACAF","ACB0","ACB1","ACB2","ACB3","ACB4","ACB5","ACB6","ACB7","ACB8","ACB9","ACBA","ACBB","ACBC","ACBD","ACBE","ACBF","ACC0","ACC1","ACD1","ACD2","ACD3","ACD4","ACD5","ACD6","ACD8","ACD9","ACDA","ACDB","ACDC","ACDD","ACDE","ACDF","ACE0","ACE1","ACE2","ACE3","ACE4","ACE5","ACE6","ACE7","ACE8","ACE9","ACEA","ACEB","ACEC","ACED","ACEE","ACEF","ACF0","ACF1","ACD7","A1AA","A1AE","A1AF","A1B0","A1B1","A2D3","A2D4","A1A5","A1A6","A2B6","A1C7","A1C8","A1D8","A9F9","A9FA","A9FB","A9FC","A9FD","A9FE","A2E6","A1C9","A2B5","A7A4","A2E0","A2E5","A2E2","A7D9","A1CA","A8F7","A8F8","A8FB","A8FC","A8FD","A8FE","A5B0","A5B1","A5B2","A5B3","A5B4","A5B5","A5B6","A5B7","A5B8","A5B9","A5A1","A5A2","A5A3","A5A4","A5A5","A5A6","A5A7","A5A8","A5A9","A5AA","A1E7","A1E8","A1E6","A1E9","A1EA","A2D5","A2D8","A2D6","A2D9","A2D7","A2A1","A2A2","A2A3","A1D3","A2A4","A1D4","A1F4","A1F5","A2B3","A2B2","A1EE","A1F0","A1C4","A1D0","A1AB","A1FC","A1FD","A1FB","A1FA","A1F2","A1F3","A2B1","A1C5","A1F1","A1AD","A1EF","A1D6","A1C1","A1D5","A1C2","A1C3","A1EC","A1ED","A1F8","A1F9","A1F6","A1F7","A2C1","A1D1","A1D2","A8E7","A8E8","A8E9","A8EA","A8EB","A8EC","A8ED","A8EE","A8EF","A8F0","A8F1","A8F2","A8F3","A8F4","A8F5","A9E7","A9E8","A9E9","A9EA","A9EB","A9EC","A9ED","A9EE","A9EF","A9F0","A9F1","A9F2","A9F3","A9F4","A9F5","A9CD","A9CE","A9CF","A9D0","A9D1","A9D2","A9D3","A9D4","A9D5","A9D6","A9D7","A9D8","A9D9","A9DA","A9DB","A9DC","A9DD","A9DE","A9DF","A9E0","A9E1","A9E2","A9E3","A9E4","A9E5","A9E6","A8CD","A8CE","A8CF","A8D0","A8D1","A8D2","A8D3","A8D4","A8D5","A8D6","A8D7","A8D8","A8D9","A8DA","A8DB","A8DC","A8DD","A8DE","A8DF","A8E0","A8E1","A8E2","A8E3","A8E4","A8E5","A8E6","A6A1","A6AC","A6A2","A6AD","A6A3","A6C8","A6C7","A6AE","A6A4","A6C2","A6C1","A6AF","A6A6","A6C6","A6C5","A6B1","A6A5","A6C4","A6C3","A6B0","A6A7","A6BC","A6C9","A6CA","A6B7","A6CB","A6CC","A6B2","A6A9","A6BE","A6CD","A6CE","A6B9","A6CF","A6D0","A6B4","A6A8","A6D1","A6D2","A6B8","A6BD","A6D3","A6D4","A6B3","A6AA","A6D5","A6D6","A6BA","A6BF","A6D7","A6D8","A6B5","A6AB","A6D9","A6DA","A6BB","A6DB","A6DC","A6C0","A6DD","A6DE","A6DF","A6E0","A6E1","A6E2","A6E3","A6E4","A6B6","A2C6","A1E1","A1E0","A2C3","A2C7","A2C8","A2CB","A2CA","A2C9","A2CC","A1E3","A1E2","A2BA","A2B9","A1E5","A1E4","A2B8","A2B7","A1DF","A1DE","A2C2","A1DB","A1DD","A1DC","A2C4","A2C5","A1DA","A1D9","A2CF","A2CE","A2D0","A2D1","A1CF","A1CE","A2BC","A2BD","A2C0","A2BB","A2BE","A2BF","A2CD","A2DB","A2DC","A2DD","A2DA","A1A1","A1A2","A1A3","A1A8","A1B4","A1B5","A1B6","A1B7","A1B8","A1B9","A1BA","A1BB","A1BC","A1BD","A1EB","A1B2","A1B3","AAA1","AAA2","AAA3","AAA4","AAA5","AAA6","AAA7","AAA8","AAA9","AAAA","AAAB","AAAC","AAAD","AAAE","AAAF","AAB0","AAB1","AAB2","AAB3","AAB4","AAB5","AAB6","AAB7","AAB8","AAB9","AABA","AABB","AABC","AABD","AABE","AABF","AAC0","AAC1","AAC2","AAC3","AAC4","AAC5","AAC6","AAC7","AAC8","AAC9","AACA","AACB","AACC","AACD","AACE","AACF","AAD0","AAD1","AAD2","AAD3","AAD4","AAD5","AAD6","AAD7","AAD8","AAD9","AADA","AADB","AADC","AADD","AADE","AADF","AAE0","AAE1","AAE2","AAE3","AAE4","AAE5","AAE6","AAE7","AAE8","AAE9","AAEA","AAEB","AAEC","AAED","AAEE","AAEF","AAF0","AAF1","AAF2","AAF3","ABA1","ABA2","ABA3","ABA4","ABA5","ABA6","ABA7","ABA8","ABA9","ABAA","ABAB
];
foreach ($series as $test) {
foreach ($test[0] as $a => $input) {
$class = $this->testedClass;
$char = hex2bin($input);
$exp = $test[1][$a];
$s = new $class($char);
$this->assertSame($exp, $s->nextCode(), "Sequence $input did not decode to $exp.");
$this->assertFalse($s->nextCode(), "Sequence $input did not end after one character");
}
}
}
}