Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8fdfc20

Browse files
author
Victor Stinner
committed
Issue #12057: Add tests for the HZ encoding
1 parent 6bcbef7 commit 8fdfc20

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

Lib/test/cjkencodings/hz-utf8.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This sentence is in ASCII.
2+
The next sentence is in GB.己所不欲,勿施於人。Bye.

Lib/test/cjkencodings/hz.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This sentence is in ASCII.
2+
The next sentence is in GB.~{<:Ky2;S{#,NpJ)l6HK!#~}Bye.

Lib/test/test_codecencodings_cn.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,35 @@ class Test_GB18030(test_multibytecodec_support.TestBase, unittest.TestCase):
5050
)
5151
has_iso10646 = True
5252

53+
class Test_HZ(test_multibytecodec_support.TestBase, unittest.TestCase):
54+
encoding = 'hz'
55+
tstring = test_multibytecodec_support.load_teststring('hz')
56+
codectests = (
57+
# test '~\n' (3 lines)
58+
(b'This sentence is in ASCII.\n'
59+
b'The next sentence is in GB.~{<:Ky2;S{#,~}~\n'
60+
b'~{NpJ)l6HK!#~}Bye.\n',
61+
'strict',
62+
'This sentence is in ASCII.\n'
63+
'The next sentence is in GB.'
64+
'\u5df1\u6240\u4e0d\u6b32\uff0c\u52ff\u65bd\u65bc\u4eba\u3002'
65+
'Bye.\n'),
66+
# test '~\n' (4 lines)
67+
(b'This sentence is in ASCII.\n'
68+
b'The next sentence is in GB.~\n'
69+
b'~{<:Ky2;S{#,NpJ)l6HK!#~}~\n'
70+
b'Bye.\n',
71+
'strict',
72+
'This sentence is in ASCII.\n'
73+
'The next sentence is in GB.'
74+
'\u5df1\u6240\u4e0d\u6b32\uff0c\u52ff\u65bd\u65bc\u4eba\u3002'
75+
'Bye.\n'),
76+
# invalid bytes
77+
(b'ab~cd', 'replace', 'ab\uFFFDd'),
78+
(b'ab\xffcd', 'replace', 'ab\uFFFDcd'),
79+
(b'ab~{\x81\x81\x41\x44~}cd', 'replace', 'ab\uFFFD\uFFFD\u804Acd'),
80+
)
81+
5382
def test_main():
5483
support.run_unittest(__name__)
5584

0 commit comments

Comments
 (0)