mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-10-07 20:37:15 +00:00
:octocat: use Generator to list Kanji/Hanzi characters
This commit is contained in:
+10
-12
@@ -11,10 +11,8 @@
|
||||
namespace chillerlan\QRCodeTest\Data;
|
||||
|
||||
use chillerlan\QRCode\Data\Hanzi;
|
||||
use Throwable;
|
||||
use function bin2hex;
|
||||
use function defined;
|
||||
use function sprintf;
|
||||
use Generator, Throwable;
|
||||
use function bin2hex, chr, defined, sprintf;
|
||||
|
||||
/**
|
||||
* Tests the Hanzi/GB2312 class
|
||||
@@ -25,7 +23,7 @@ class HanziTest extends DataInterfaceTestAbstract{
|
||||
protected string $testdata = '无可奈何燃花作香';
|
||||
|
||||
/**
|
||||
* isGB2312() should pass on Hanzi/Hanzi characters and fail on everything else
|
||||
* isGB2312() should pass on Hanzi/GB2312 characters and fail on everything else
|
||||
*/
|
||||
public function stringValidateProvider():array{
|
||||
return [
|
||||
@@ -41,22 +39,22 @@ class HanziTest extends DataInterfaceTestAbstract{
|
||||
/**
|
||||
* lists all characters in the valid GB2312 range
|
||||
*/
|
||||
public function hanziProvider():array{
|
||||
$list = [];
|
||||
public function hanziProvider():Generator{
|
||||
|
||||
for($byte1 = 0xa1; $byte1 < 0xf8; $byte1 += 0x1){
|
||||
for($byte1 = 0xa1; $byte1 < 0xf8; $byte1++){
|
||||
|
||||
if($byte1 > 0xa9 && $byte1 < 0xb0){
|
||||
continue;
|
||||
}
|
||||
|
||||
for($byte2 = 0xa1; $byte2 < 0xff; $byte2++){
|
||||
$list[] = [chr($byte1).chr($byte2)];
|
||||
yield sprintf('0x%X', ($byte1 << 8 | $byte2)) => [
|
||||
mb_convert_encoding(chr($byte1).chr($byte2), 'UTF-8', Hanzi::ENCODING),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return array_map(fn($chr) => mb_convert_encoding($chr, 'UTF-8', Hanzi::ENCODING), $list);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,8 +73,8 @@ class HanziTest extends DataInterfaceTestAbstract{
|
||||
|
||||
$this::markTestSkipped(sprintf(
|
||||
'invalid glyph: %s => %s',
|
||||
bin2hex($chr),
|
||||
mb_convert_encoding($chr, Hanzi::ENCODING, mb_internal_encoding())
|
||||
bin2hex(mb_convert_encoding($chr, Hanzi::ENCODING, 'UTF-8')),
|
||||
$chr
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user