mirror of
https://github.com/python/cpython.git
synced 2025-09-20 15:40:32 +00:00
merge heads
This commit is contained in:
commit
4dfcb1a00d
3 changed files with 82 additions and 51 deletions
|
@ -58,11 +58,16 @@ class TestBase:
|
||||||
result = func(source, scheme)[0]
|
result = func(source, scheme)[0]
|
||||||
if func is self.decode:
|
if func is self.decode:
|
||||||
self.assertTrue(type(result) is str, type(result))
|
self.assertTrue(type(result) is str, type(result))
|
||||||
|
self.assertEqual(result, expected,
|
||||||
|
'%a.decode(%r, %r)=%a != %a'
|
||||||
|
% (source, self.encoding, scheme, result,
|
||||||
|
expected))
|
||||||
else:
|
else:
|
||||||
self.assertTrue(type(result) is bytes, type(result))
|
self.assertTrue(type(result) is bytes, type(result))
|
||||||
self.assertEqual(result, expected,
|
self.assertEqual(result, expected,
|
||||||
'%a.decode(%r)=%a != %a'
|
'%a.encode(%r, %r)=%a != %a'
|
||||||
% (source, self.encoding, result, expected))
|
% (source, self.encoding, scheme, result,
|
||||||
|
expected))
|
||||||
else:
|
else:
|
||||||
self.assertRaises(UnicodeError, func, source, scheme)
|
self.assertRaises(UnicodeError, func, source, scheme)
|
||||||
|
|
||||||
|
@ -279,6 +284,7 @@ class TestBase_Mapping(unittest.TestCase):
|
||||||
pass_enctest = []
|
pass_enctest = []
|
||||||
pass_dectest = []
|
pass_dectest = []
|
||||||
supmaps = []
|
supmaps = []
|
||||||
|
codectests = []
|
||||||
|
|
||||||
def __init__(self, *args, **kw):
|
def __init__(self, *args, **kw):
|
||||||
unittest.TestCase.__init__(self, *args, **kw)
|
unittest.TestCase.__init__(self, *args, **kw)
|
||||||
|
@ -348,6 +354,30 @@ class TestBase_Mapping(unittest.TestCase):
|
||||||
if (csetch, unich) not in self.pass_dectest:
|
if (csetch, unich) not in self.pass_dectest:
|
||||||
self.assertEqual(str(csetch, self.encoding), unich)
|
self.assertEqual(str(csetch, self.encoding), unich)
|
||||||
|
|
||||||
|
def test_errorhandle(self):
|
||||||
|
for source, scheme, expected in self.codectests:
|
||||||
|
if isinstance(source, bytes):
|
||||||
|
func = source.decode
|
||||||
|
else:
|
||||||
|
func = source.encode
|
||||||
|
if expected:
|
||||||
|
if isinstance(source, bytes):
|
||||||
|
result = func(self.encoding, scheme)
|
||||||
|
self.assertTrue(type(result) is str, type(result))
|
||||||
|
self.assertEqual(result, expected,
|
||||||
|
'%a.decode(%r, %r)=%a != %a'
|
||||||
|
% (source, self.encoding, scheme, result,
|
||||||
|
expected))
|
||||||
|
else:
|
||||||
|
result = func(self.encoding, scheme)
|
||||||
|
self.assertTrue(type(result) is bytes, type(result))
|
||||||
|
self.assertEqual(result, expected,
|
||||||
|
'%a.encode(%r, %r)=%a != %a'
|
||||||
|
% (source, self.encoding, scheme, result,
|
||||||
|
expected))
|
||||||
|
else:
|
||||||
|
self.assertRaises(UnicodeError, func, self.encoding, scheme)
|
||||||
|
|
||||||
def load_teststring(name):
|
def load_teststring(name):
|
||||||
dir = os.path.join(os.path.dirname(__file__), 'cjkencodings')
|
dir = os.path.join(os.path.dirname(__file__), 'cjkencodings')
|
||||||
with open(os.path.join(dir, name + '.txt'), 'rb') as f:
|
with open(os.path.join(dir, name + '.txt'), 'rb') as f:
|
||||||
|
|
|
@ -115,14 +115,15 @@ DECODER(big5hkscs)
|
||||||
|
|
||||||
REQUIRE_INBUF(2)
|
REQUIRE_INBUF(2)
|
||||||
|
|
||||||
if (0xc6 <= c && c <= 0xc8 && (c >= 0xc7 || IN2 >= 0xa1))
|
if (0xc6 > c || c > 0xc8 || (c < 0xc7 && IN2 < 0xa1)) {
|
||||||
goto hkscsdec;
|
|
||||||
|
|
||||||
TRYMAP_DEC(big5, **outbuf, c, IN2) {
|
TRYMAP_DEC(big5, **outbuf, c, IN2) {
|
||||||
NEXT(2, 1)
|
NEXT(2, 1)
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
hkscsdec: TRYMAP_DEC(big5hkscs, decoded, c, IN2) {
|
|
||||||
|
TRYMAP_DEC(big5hkscs, decoded, c, IN2)
|
||||||
|
{
|
||||||
int s = BH2S(c, IN2);
|
int s = BH2S(c, IN2);
|
||||||
const unsigned char *hintbase;
|
const unsigned char *hintbase;
|
||||||
|
|
||||||
|
@ -152,8 +153,9 @@ hkscsdec: TRYMAP_DEC(big5hkscs, decoded, c, IN2) {
|
||||||
OUT1(decoded)
|
OUT1(decoded)
|
||||||
NEXT(2, 1)
|
NEXT(2, 1)
|
||||||
}
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
switch ((c << 8) | IN2) {
|
switch ((c << 8) | IN2) {
|
||||||
case 0x8862: WRITE2(0x00ca, 0x0304); break;
|
case 0x8862: WRITE2(0x00ca, 0x0304); break;
|
||||||
case 0x8864: WRITE2(0x00ca, 0x030c); break;
|
case 0x8864: WRITE2(0x00ca, 0x030c); break;
|
||||||
|
@ -164,7 +166,6 @@ hkscsdec: TRYMAP_DEC(big5hkscs, decoded, c, IN2) {
|
||||||
|
|
||||||
NEXT(2, 2) /* all decoded codepoints are pairs, above. */
|
NEXT(2, 2) /* all decoded codepoints are pairs, above. */
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue