big5_encoding.phpt 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. --TEST--
  2. Exhaustive test of verification and conversion of Big5 text
  3. --EXTENSIONS--
  4. mbstring
  5. --SKIPIF--
  6. <?php
  7. if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
  8. ?>
  9. --FILE--
  10. <?php
  11. include('encoding_tests.inc');
  12. srand(1000); // Make results consistent
  13. mb_substitute_character(0x25); // '%'
  14. readConversionTable(__DIR__ . '/data/BIG5.txt', $toUnicode, $fromUnicode);
  15. // Non-reversible mappings (two different BIG5 codepoints map to same Unicode codepoint)
  16. $fromUnicode["\x25\x50"] = "\xA2\xA4";
  17. $fromUnicode["\x25\x5E"] = "\xA2\xA5";
  18. $fromUnicode["\x25\x61"] = "\xA2\xA7";
  19. $fromUnicode["\x25\x6A"] = "\xA2\xA6";
  20. $fromUnicode["\x25\x6D"] = "\xA2\x7E";
  21. $fromUnicode["\x25\x6E"] = "\xA2\xA1";
  22. $fromUnicode["\x25\x6F"] = "\xA2\xA3";
  23. $fromUnicode["\x25\x70"] = "\xA2\xA2";
  24. findInvalidChars($toUnicode, $invalid, $truncated);
  25. testAllValidChars($toUnicode, 'BIG5', 'UTF-16BE', false);
  26. testAllInvalidChars($invalid, $toUnicode, 'BIG5', 'UTF-16BE', "\x00%");
  27. testTruncatedChars($truncated, 'BIG5', 'UTF-16BE', "\x00%");
  28. echo "Tested BIG5 -> UTF-16BE\n";
  29. testAllValidChars($fromUnicode, 'UTF-16BE', 'BIG5', false);
  30. findInvalidChars($fromUnicode, $invalid, $unused, array_fill_keys(range(0,0xFF), 2));
  31. convertAllInvalidChars($invalid, $fromUnicode, 'UTF-16BE', 'BIG5', '%');
  32. echo "Tested UTF-16BE -> BIG5\n";
  33. // Test "long" illegal character markers
  34. mb_substitute_character("long");
  35. convertInvalidString("\x80", "%", "BIG5", "UTF-8");
  36. convertInvalidString("\xB0\x9F", "%", "BIG5", "UTF-8");
  37. convertInvalidString("\xA3\xED", "%", "BIG5", "UTF-8");
  38. convertInvalidString("\x76\x54", "U+7654", "UTF-16BE", "BIG5");
  39. echo "Done!\n";
  40. ?>
  41. --EXPECT--
  42. Tested BIG5 -> UTF-16BE
  43. Tested UTF-16BE -> BIG5
  44. Done!