Benjamin Peterson | 90f5ba5 | 2010-03-11 22:53:45 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 2 | # |
| 3 | # test_codecencodings_kr.py |
| 4 | # Codec encoding tests for ROK encodings. |
| 5 | # |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 6 | |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 7 | from test import support |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 8 | from test import test_multibytecodec_support |
| 9 | import unittest |
| 10 | |
| 11 | class Test_CP949(test_multibytecodec_support.TestBase, unittest.TestCase): |
| 12 | encoding = 'cp949' |
| 13 | tstring = test_multibytecodec_support.load_teststring('cp949') |
| 14 | codectests = ( |
| 15 | # invalid bytes |
Guido van Rossum | 024da5c | 2007-05-17 23:59:11 +0000 | [diff] [blame] | 16 | (b"abc\x80\x80\xc1\xc4", "strict", None), |
| 17 | (b"abc\xc8", "strict", None), |
| 18 | (b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\uc894"), |
| 19 | (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\uc894\ufffd"), |
| 20 | (b"abc\x80\x80\xc1\xc4", "ignore", "abc\uc894"), |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 21 | ) |
| 22 | |
| 23 | class Test_EUCKR(test_multibytecodec_support.TestBase, unittest.TestCase): |
| 24 | encoding = 'euc_kr' |
| 25 | tstring = test_multibytecodec_support.load_teststring('euc_kr') |
| 26 | codectests = ( |
| 27 | # invalid bytes |
Guido van Rossum | 024da5c | 2007-05-17 23:59:11 +0000 | [diff] [blame] | 28 | (b"abc\x80\x80\xc1\xc4", "strict", None), |
| 29 | (b"abc\xc8", "strict", None), |
| 30 | (b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\uc894"), |
| 31 | (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\uc894\ufffd"), |
| 32 | (b"abc\x80\x80\xc1\xc4", "ignore", "abc\uc894"), |
Guido van Rossum | 61e21b5 | 2007-08-20 19:06:03 +0000 | [diff] [blame] | 33 | |
| 34 | # composed make-up sequence errors |
| 35 | (b"\xa4\xd4", "strict", None), |
| 36 | (b"\xa4\xd4\xa4", "strict", None), |
| 37 | (b"\xa4\xd4\xa4\xb6", "strict", None), |
| 38 | (b"\xa4\xd4\xa4\xb6\xa4", "strict", None), |
| 39 | (b"\xa4\xd4\xa4\xb6\xa4\xd0", "strict", None), |
| 40 | (b"\xa4\xd4\xa4\xb6\xa4\xd0\xa4", "strict", None), |
| 41 | (b"\xa4\xd4\xa4\xb6\xa4\xd0\xa4\xd4", "strict", "\uc4d4"), |
| 42 | (b"\xa4\xd4\xa4\xb6\xa4\xd0\xa4\xd4x", "strict", "\uc4d4x"), |
| 43 | (b"a\xa4\xd4\xa4\xb6\xa4", "replace", "a\ufffd"), |
| 44 | (b"\xa4\xd4\xa3\xb6\xa4\xd0\xa4\xd4", "strict", None), |
| 45 | (b"\xa4\xd4\xa4\xb6\xa3\xd0\xa4\xd4", "strict", None), |
| 46 | (b"\xa4\xd4\xa4\xb6\xa4\xd0\xa3\xd4", "strict", None), |
| 47 | (b"\xa4\xd4\xa4\xff\xa4\xd0\xa4\xd4", "replace", "\ufffd"), |
| 48 | (b"\xa4\xd4\xa4\xb6\xa4\xff\xa4\xd4", "replace", "\ufffd"), |
| 49 | (b"\xa4\xd4\xa4\xb6\xa4\xd0\xa4\xff", "replace", "\ufffd"), |
| 50 | (b"\xc1\xc4", "strict", "\uc894"), |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 51 | ) |
| 52 | |
| 53 | class Test_JOHAB(test_multibytecodec_support.TestBase, unittest.TestCase): |
| 54 | encoding = 'johab' |
| 55 | tstring = test_multibytecodec_support.load_teststring('johab') |
| 56 | codectests = ( |
| 57 | # invalid bytes |
Guido van Rossum | 024da5c | 2007-05-17 23:59:11 +0000 | [diff] [blame] | 58 | (b"abc\x80\x80\xc1\xc4", "strict", None), |
| 59 | (b"abc\xc8", "strict", None), |
| 60 | (b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\ucd27"), |
| 61 | (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\ucd27\ufffd"), |
| 62 | (b"abc\x80\x80\xc1\xc4", "ignore", "abc\ucd27"), |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 63 | ) |
| 64 | |
| 65 | def test_main(): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 66 | support.run_unittest(__name__) |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 67 | |
| 68 | if __name__ == "__main__": |
| 69 | test_main() |