packages feed

willow-0.1.0.0: test/Test/Willow/Unit/Encoding/Big5.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.Big5
    ( 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 = "Big5" ~: U.TestList
    [ "decode" ~: U.TestList
        [ "ASCII" ~: U.TestList $ map (decodeAscii Big5) ['\NUL'..'\DEL']
        , decodeBig5 "0xFF" [0xFF] $ Nothing
        , decodeBig5 "1133" [0x88, 0x62] $ Just "Ê\x0304"
        , decodeBig5 "1135" [0x88, 0x64] $ Just "Ê\x030C"
        , decodeBig5 "1164" [0x88, 0xA3] $ Just "ê\x0304"
        , decodeBig5 "1166" [0x88, 0xA5] $ Just "ê\x030C"
        ]
    , "encode" ~: U.TestList
        [ "ASCII" ~: U.TestList $ map (encodeAscii Big5) ['\NUL'..'\DEL']
        , encodeBig5 '\x2550' $ Just [0xF9, 0xF9]
        , encodeBig5 '\x255E' $ Just [0xF9, 0xE9]
        , encodeBig5 '\x2561' $ Just [0xF9, 0xEB]
        , encodeBig5 '\x256A' $ Just [0xF9, 0xEA]
        , encodeBig5 '\x5341' $ Just [0xA4, 0x51]
        , encodeBig5 '\x5345' $ Just [0xA4, 0xCA]
        ]
    ]


decodeBig5 :: String -> [W.Word8] -> Maybe String -> U.Test
decodeBig5 = decodeTest Big5

encodeBig5 :: Char -> Maybe [W.Word8] -> U.Test
encodeBig5 c = encodeTest Big5 [c] [c]