{- Copyright © 2007 Magnus Therning
-
- This file is part of dataenc.
-
- Dataenc is free software: you can redistribute it and/or modify it under
- the terms of the GNU Lesser General Public License as published by the
- Free Software Foundation, either version 3 of the License, or (at your
- option) any later version.
-
- Dataenc is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with dataenc. If not, see
-}
module Main
where
import Test.HUnit
import Control.Monad
import System.Exit
import Data.Maybe
import Codec.Binary.DataEncoding
-- {{{1 buildTestList
-- builds a list of successful tests based on a tuple (suite, description,
-- encoded data, decoded data, codec)
buildTestList td = TestList $ concat
[[ TestLabel (suite ++ " encode " ++ desc) (enc ~=? (encode codec dec))
, TestLabel (suite ++ " decode " ++ desc) (dec ~=? (fromJust $ decode codec $ enc))]
| (suite, desc, enc, dec, codec) <- td ]
-- {{{1 uuencode tests
uuTestData =
[ ("uu", "empty", "", [], uu)
, ("uu", "\0", "``", [0], uu)
, ("uu", "\255", "_P", [255], uu)
, ("uu", "Example", "17AA;7!L90", [69,120,97,109,112,108,101], uu)
]
uuTests = buildTestList uuTestData
uuTests2 = test
[ "chop . encode Example" ~: ["'17AA;7!L90"] ~=? (chop uu 61 . encode uu) [69,120,97,109,112,108,101]
, "decode . unchop Example" ~: [69,120,97,109,112,108,101] ~=? fromJust ((decode uu . unchop uu) ["'17AA;7!L90"])
]
uuTestsFail = test
[ "uu decode short" ~: Nothing ~=? decode uu "A"
, "uu decode' short" ~: [Nothing] ~=? decode' uu "A"
, "uu decode illegal" ~: Nothing ~=? decode uu "aa"
, "uu decode' illegal" ~: [Nothing] ~=? decode' uu "aa"
]
-- {{{1 base85 tests
base85TestData =
[ ("base85", "empty", "", [], base85)
, ("base85", "f", "Ac", [102], base85)
, ("base85", "fo", "Ao@", [102,111], base85)
, ("base85", "foo", "AoDS", [102,111,111], base85)
, ("base85", "foob", "AoDTs", [102,111,111,98], base85)
, ("base85", "fooba", "AoDTs@/", [102,111,111,98,97], base85)
, ("base85", "foobar", "AoDTs@<)", [102,111,111,98,97,114], base85)
, ("base85", "\0", "!!", [0], base85)
, ("base85", "foob\0\0\0\0ar", "AoDTszEW", [102,111,111,98,0,0,0,0,114], base85)
, ("base85", "Example", "7