UTF16 test cases

darcs-hash:20080119233135-a4fee-e9b4075c867089eb8d8608b7a03fdff75bf73240
This commit is contained in:
Henning Guenther 2008-01-19 15:31:35 -08:00
parent 8b29980edb
commit ce37d090af

View File

@ -3,6 +3,7 @@ module Test.Tests where
import Data.Encoding
import Data.Encoding.ASCII
import Data.Encoding.UTF8
import Data.Encoding.UTF16
import Test.Tester
import Test.HUnit
@ -27,6 +28,8 @@ utf8Tests = TestList $ map test $
[0xE6,0x97,0xA5,0xE6,0x9C,0xAC,0xE8,0xAA,0x9E]
,EncodingTest enc "\x233B4"
[0xF0,0xA3,0x8E,0xB4]
,EncodingTest enc ""
[]
-- First possible sequence of a certain length
,EncodingTest enc "\x0000"
[0x00]
@ -49,7 +52,21 @@ utf8Tests = TestList $ map test $
,EncodingTest enc "\xE000"
[0xEE,0x80,0x80]
,EncodingTest enc "\xFFFD"
[0xEF,0xBF,0xBD]]
[0xEF,0xBF,0xBD]
-- Illegal starting characters
,DecodingError enc
[0x65,0x55,0x85]
(IllegalCharacter 0x85)
-- Unexpected end
,DecodingError enc
[0x41,0xE2,0x89,0xA2,0xCE]
UnexpectedEnd
,DecodingError enc
[0x41,0xE2,0x89]
UnexpectedEnd
,DecodingError enc
[0x41,0xE2]
UnexpectedEnd]
| enc <- [UTF8,UTF8Strict]
]++
[DecodingError UTF8 [0xFE] (IllegalCharacter 0xFE)
@ -75,4 +92,45 @@ utf8Tests = TestList $ map test $
(IllegalRepresentation [0xE0,0x80,0x80])
,DecodingError UTF8Strict [0xF0,0x80,0x80,0x80]
(IllegalRepresentation [0xF0,0x80,0x80,0x80])
-- Invalid extends
-- 2 of 2
,DecodingError UTF8Strict [0xCC,0x1C,0xE0]
(IllegalCharacter 0x1C)
-- 2 of 3
,DecodingError UTF8Strict [0xE3,0x6C,0xB3]
(IllegalCharacter 0x6C)
-- 3 of 3
,DecodingError UTF8Strict [0xE3,0xB4,0x6D]
(IllegalCharacter 0x6D)
-- 2 of 4
,DecodingError UTF8Strict [0xF2,0x6C,0xB3,0xB3]
(IllegalCharacter 0x6C)
-- 3 of 4
,DecodingError UTF8Strict [0xF2,0xB3,0x6C,0xB3]
(IllegalCharacter 0x6C)
-- 4 of 4
,DecodingError UTF8Strict [0xF2,0xB3,0xB3,0x6C]
(IllegalCharacter 0x6C)
]
utf16Tests :: Test
utf16Tests = TestList $ map test $
[EncodingTest UTF16BE "z"
[0x00,0x7A]
,EncodingTest UTF16BE "\x6C34"
[0x6C,0x34]
,EncodingTest UTF16BE "\x1D11E"
[0xD8,0x34,0xDD,0x1E]
,EncodingTest UTF16 "\x6C34z\x1D11E"
[0xFE,0xFF,0x6C,0x34,0x00,0x7A,0xD8,0x34,0xDD,0x1E]
,EncodingTest UTF16BE "˨"
[0x02,0xE8]
,DecodingError UTF16LE [0x65,0xDC]
(IllegalCharacter 0xDC)
,DecodingError UTF16BE [0xDC]
(IllegalCharacter 0xDC)
,DecodingError UTF16BE [0xD9,0x78,0xDA]
(IllegalCharacter 0xDA)
,DecodingError UTF16BE [0xD9,0x78,0xDA,0x66]
(IllegalCharacter 0xDA)
]