1.1 --- a/tests/iconv.py Mon Dec 12 18:00:17 2016 +0100
1.2 +++ b/tests/iconv.py Mon Dec 12 18:30:40 2016 +0100
1.3 @@ -8,22 +8,44 @@
1.4 from_utf16 = Converter("UTF-16", "ISO-8859-1")
1.5
1.6 try:
1.7 - try:
1.8 - iso = "æøå"
1.9 - print iso # æøå
1.10 - utf = to_utf8.convert(iso)
1.11 - print utf # æøå
1.12 - print from_utf8.convert(utf) # æøå
1.13 - utf = to_utf16.convert(iso)
1.14 - print utf # ...
1.15 - print from_utf16.convert(utf) # æøå
1.16 - except OSError, exc:
1.17 - if exc.value == EINVAL:
1.18 - print "Incomplete input", exc.arg
1.19 - elif exc.value == EILSEQ:
1.20 - print "Invalid input", exc.arg
1.21 - else:
1.22 - print exc.value, exc.arg
1.23 + iso = "æøå"
1.24 + print iso # æøå
1.25 + to_utf8.feed(iso)
1.26 + utf8 = str(to_utf8)
1.27 + print utf8 # æøå
1.28 + from_utf8.feed(utf8)
1.29 + print str(from_utf8) # æøå
1.30 + to_utf16.feed(iso)
1.31 + utf16 = str(to_utf16)
1.32 + print utf16 # ...
1.33 + from_utf16.feed(utf16)
1.34 + print str(from_utf16) # æøå
1.35 +
1.36 + # Convert part of a UTF-16 sequence, then convert the remainder, then obtain
1.37 + # the result.
1.38 +
1.39 + first = utf16[:3]
1.40 + second = utf16[3:]
1.41 +
1.42 + from_utf16.reset()
1.43 + print "first:", first # ...
1.44 + from_utf16.feed(first) # should have handled an incomplete input
1.45 + print "second:", second # ...
1.46 + from_utf16.feed(second) # should have handled the complete input
1.47 + print str(from_utf16) # æøå
1.48 +
1.49 + # Convert part of a UTF-8 sequence, then the remainder, then get the result.
1.50 +
1.51 + first = utf8[:3]
1.52 + second = utf8[3:]
1.53 +
1.54 + from_utf8.reset()
1.55 + print "first:", first # æÃ
1.56 + from_utf8.feed(first) # should have handled an incomplete input
1.57 + print "second:", second # ¸Ã¥
1.58 + from_utf8.feed(second) # should have handled the complete input
1.59 + print str(from_utf8) # æøå
1.60 +
1.61 finally:
1.62 to_utf8.close()
1.63 to_utf16.close()