willow-0.1.0.0: test/Test/Willow/Unit/Encoding/EucJp.hs
{-|
Description:
Copyright: (c) 2020 Samuel May
License: MPL-2.0
Maintainer: ag.eitilt@gmail.com
Stability: experimental
Portability: portable
-}
module Test.Willow.Unit.Encoding.EucJp
( tests
) where
import qualified Data.Word as W
import qualified Test.HUnit as U
import Test.HUnit ( (~:) )
import Web.Willow.Common.Encoding
import Test.Willow.Unit.Encoding.Common
tests :: U.Test
tests = "EucJp" ~: U.TestList
[ "decode" ~: U.TestList $
[ "ASCII" ~: U.TestList $ map (decodeAscii EucJp) ['\NUL'..'\DEL']
, "failures" ~: U.TestList $ map (\(c, b) -> decodeEucJp c b Nothing)
[ ([toEnum i], [fromIntegral i])
| i <- [0x80..0x8D] ++ [0x90..0xA0] ++ [0xFF]
]
] ++
[ decodeEucJp ['\x8E', toEnum i] [0x8E, fromIntegral i] $ Just [toEnum $ 0xFF61 - 0xA1 + i]
| i <- [0xA1..0xDF]
]
, "encode" ~: U.TestList $
[ "ASCII" ~: U.TestList $ map (encodeAscii EucJp) ['\NUL'..'\DEL']
, encodeEucJp '\x00A5' $ Just [0x5C]
, encodeEucJp '\x203E' $ Just [0x7E]
, encodeEucJp '\x2212' $ Just [0xA1, 0xDD]
] ++
[ encodeEucJp (toEnum i) $ Just [0x8E, fromIntegral $ i - 0xFF61 + 0xA1]
| i <- [0xFF61..0xFF9F]
]
]
decodeEucJp :: String -> [W.Word8] -> Maybe String -> U.Test
decodeEucJp = decodeTest EucJp
encodeEucJp :: Char -> Maybe [W.Word8] -> U.Test
encodeEucJp c = encodeTest EucJp [c] [c]