summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc-André Lemburg <mal@egenix.com>2001-06-19 20:09:28 (GMT)
committerMarc-André Lemburg <mal@egenix.com>2001-06-19 20:09:28 (GMT)
commita37171dd8632b80af5500939791e39a482efe4a3 (patch)
tree1fef10eeb8f5fd4b515b2081a1f7cce6c6cab215
parent92b550cdd854f27ba49fbdab4fc001e9ab7717c2 (diff)
downloadcpython-a37171dd8632b80af5500939791e39a482efe4a3.zip
cpython-a37171dd8632b80af5500939791e39a482efe4a3.tar.gz
cpython-a37171dd8632b80af5500939791e39a482efe4a3.tar.bz2
Test by Martin v. Loewis for the new UTF-16 codec handling of BOM
marks.
-rw-r--r--Lib/test/test_codecs.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
new file mode 100644
index 0000000..6d9e31d
--- /dev/null
+++ b/Lib/test/test_codecs.py
@@ -0,0 +1,25 @@
+import test_support,unittest
+import codecs
+import StringIO
+
+class UTF16Test(unittest.TestCase):
+
+ spamle = '\xff\xfes\x00p\x00a\x00m\x00s\x00p\x00a\x00m\x00'
+ spambe = '\xfe\xff\x00s\x00p\x00a\x00m\x00s\x00p\x00a\x00m'
+
+ def test_only_one_bom(self):
+ _,_,reader,writer = codecs.lookup("utf-16")
+ # encode some stream
+ s = StringIO.StringIO()
+ f = writer(s)
+ f.write(u"spam")
+ f.write(u"spam")
+ d = s.getvalue()
+ # check whether there is exactly one BOM in it
+ self.assert_(d == self.spamle or d == self.spambe)
+ # try to read it back
+ s = StringIO.StringIO(d)
+ f = reader(s)
+ self.assertEquals(f.read(), u"spamspam")
+
+test_support.run_unittest(UTF16Test)