Commit c5b00887 authored by Bodigrim's avatar Bodigrim Committed by Xia Li-yao
Browse files

Simplify tests for decodeLatin1

parent ba51a486
......@@ -20,27 +20,23 @@ import Text.Show.Functions ()
import qualified Control.Exception as Exception
import qualified Data.Bits as Bits (shiftL, shiftR)
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString.Lazy as BL
import qualified Data.ByteString.Lazy.Char8 as BLC
import qualified Data.Text as T
import qualified Data.Text.Encoding as E
import qualified Data.Text.Encoding.Error as E
import qualified Data.Text.Lazy as TL
import qualified Data.Text.Lazy.Encoding as EL
-- Note: this silently truncates code-points > 255 to 8-bit due to 'B.pack'
encodeL1 :: T.Text -> B.ByteString
encodeL1 = B.pack . map (fromIntegral . fromEnum) . T.unpack
encodeLazyL1 :: TL.Text -> BL.ByteString
encodeLazyL1 = BL.fromChunks . map encodeL1 . TL.toChunks
t_ascii t = E.decodeASCII (E.encodeUtf8 a) === a
where a = T.map (\c -> chr (ord c `mod` 128)) t
tl_ascii t = EL.decodeASCII (EL.encodeUtf8 a) === a
where a = TL.map (\c -> chr (ord c `mod` 128)) t
t_latin1 t = E.decodeLatin1 (encodeL1 a) === a
where a = T.map (\c -> chr (ord c `mod` 256)) t
tl_latin1 t = EL.decodeLatin1 (encodeLazyL1 a) === a
where a = TL.map (\c -> chr (ord c `mod` 256)) t
t_latin1 = E.decodeLatin1 `eq` (T.pack . BC.unpack)
tl_latin1 = EL.decodeLatin1 `eq` (TL.pack . BLC.unpack)
t_utf8 = (E.decodeUtf8 . E.encodeUtf8) `eq` id
t_utf8' = (E.decodeUtf8' . E.encodeUtf8) `eq` (id . Right)
tl_utf8 = (EL.decodeUtf8 . EL.encodeUtf8) `eq` id
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment