From d572163c92cbe7c6cfcb97ad942507ac2478c1d9 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 25 May 2011 00:19:07 +0200 Subject: Issue #12057: Add tests for the HZ encoding --- Lib/test/cjkencodings/hz-utf8.txt | 2 ++ Lib/test/cjkencodings/hz.txt | 2 ++ Lib/test/test_codecencodings_cn.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 Lib/test/cjkencodings/hz-utf8.txt create mode 100644 Lib/test/cjkencodings/hz.txt diff --git a/Lib/test/cjkencodings/hz-utf8.txt b/Lib/test/cjkencodings/hz-utf8.txt new file mode 100644 index 0000000000..7c11735c1f --- /dev/null +++ b/Lib/test/cjkencodings/hz-utf8.txt @@ -0,0 +1,2 @@ +This sentence is in ASCII. +The next sentence is in GB.己所不欲,勿施於人。Bye. diff --git a/Lib/test/cjkencodings/hz.txt b/Lib/test/cjkencodings/hz.txt new file mode 100644 index 0000000000..f882d46344 --- /dev/null +++ b/Lib/test/cjkencodings/hz.txt @@ -0,0 +1,2 @@ +This sentence is in ASCII. +The next sentence is in GB.~{<:Ky2;S{#,NpJ)l6HK!#~}Bye. diff --git a/Lib/test/test_codecencodings_cn.py b/Lib/test/test_codecencodings_cn.py index 96b0d77096..215e8de3b6 100644 --- a/Lib/test/test_codecencodings_cn.py +++ b/Lib/test/test_codecencodings_cn.py @@ -50,6 +50,35 @@ class Test_GB18030(test_multibytecodec_support.TestBase, unittest.TestCase): ) has_iso10646 = True +class Test_HZ(test_multibytecodec_support.TestBase, unittest.TestCase): + encoding = 'hz' + tstring = test_multibytecodec_support.load_teststring('hz') + codectests = ( + # test '~\n' (3 lines) + (b'This sentence is in ASCII.\n' + b'The next sentence is in GB.~{<:Ky2;S{#,~}~\n' + b'~{NpJ)l6HK!#~}Bye.\n', + 'strict', + u'This sentence is in ASCII.\n' + u'The next sentence is in GB.' + u'\u5df1\u6240\u4e0d\u6b32\uff0c\u52ff\u65bd\u65bc\u4eba\u3002' + u'Bye.\n'), + # test '~\n' (4 lines) + (b'This sentence is in ASCII.\n' + b'The next sentence is in GB.~\n' + b'~{<:Ky2;S{#,NpJ)l6HK!#~}~\n' + b'Bye.\n', + 'strict', + u'This sentence is in ASCII.\n' + u'The next sentence is in GB.' + u'\u5df1\u6240\u4e0d\u6b32\uff0c\u52ff\u65bd\u65bc\u4eba\u3002' + u'Bye.\n'), + # invalid bytes + (b'ab~cd', 'replace', u'ab\uFFFDd'), + (b'ab\xffcd', 'replace', u'ab\uFFFDcd'), + (b'ab~{\x81\x81\x41\x44~}cd', 'replace', u'ab\uFFFD\uFFFD\u804Acd'), + ) + def test_main(): test_support.run_unittest(__name__) -- cgit v1.2.1