{-| Description: Copyright: (c) 2020 Samuel May License: MPL-2.0 Maintainer: ag.eitilt@gmail.com Stability: experimental Portability: portable -} module Test.Willow.Unit.Encoding.SingleByte ( tests ) where import qualified Data.ByteString.Lazy as BS.L import qualified Data.Maybe as Y import qualified Data.Text as T import qualified Data.Text.Encoding as T import qualified Data.Text.IO as T import qualified Data.Text.Lazy as T.L import qualified Data.Text.Read as T.R import qualified Test.HUnit as U import System.FilePath ( (), (<.>) ) import Test.HUnit ( (~:), (~?=), (@?) ) import Web.Willow.Common.Encoding import Web.Willow.Common.Encoding.Labels import Test.Willow.Unit.Common tests :: IO U.Test tests = return $ "single-byte encodings" ~: U.TestList [] {- [ "encoded index is sane" ~: U.TestList $ map expectedCharsetEncode charsets' , "encode-decode index roundtrips" ~: U.TestList $ map roundtrip encodings ] -} {- expectedCharsetEncode :: (Encoding, [Maybe Char]) -> U.Test expectedCharsetEncode (enc, index) = show enc ~: U.TestCase $ do let bs' = encode enc . T.L.pack $ Y.catMaybes index bs = Y.fromMaybe BS.L.empty bs' Y.isJust bs' @? "encoding failed" BS.L.length bs <= 0x100 @? "charset too long" -- This doesn't check the encoded values are correct, but it does at least -- make sure nothing's out of order. snd (BS.L.foldl' (\(c, b) c' -> (c', b && c < c')) (0x00, True) $ BS.L.drop 1 bs) @? "charset out of order" roundtrip :: (Encoding, [Maybe Char]) -> U.Test roundtrip (enc, index) = show enc ~: (encode enc index' >>= decode' enc) ~?= Just index' where index' = T.L.pack $ Y.catMaybes index -}