based/test/Main.hs

180 lines
9.5 KiB
Haskell

module Main where
import Test.HUnit
import Encoding.Base91 (enc91, dec91)
import Encoding.Base85 (enc85, dec85)
import Encoding.Base64 (enc64, dec64)
import Encoding.Base45 (enc45, dec45)
import Encoding.Base32 (enc32, dec32)
import Encoding.Base16 (enc16, dec16)
import Encoding.Base8 (enc8, dec8)
import Encoding.Base2 (enc2, dec2)
import Encoding.QuotedPrintable (encqp, decqp)
import Encoding.UnixToUnix (encuu, decuu)
import System.Exit (exitFailure, exitSuccess)
testEnc91 :: Test
testEnc91 = TestCase $ do
assertEqual "for (enc91 \"Hello, World!\")," ">OwJh>}AQ;r@@Y?F" (enc91 "Hello, World!")
assertEqual "for (enc91 \"Haskell\")," "3D8=d,[*G" (enc91 "Haskell")
assertEqual "for (enc91 \"😂\")," "=~m6g" (enc91 "😂")
testDec91 :: Test
testDec91 = TestCase $ do
assertEqual "for (dec91 \">OwJh>}AQ;r@@Y?F\")," "Hello, World!" (dec91 ">OwJh>}AQ;r@@Y?F")
assertEqual "for (dec91 \"3D8=d,[*G\")," "Haskell" (dec91 "3D8=d,[*G")
assertEqual "for (dec91 \"=~m6g\")," "😂" (dec91 "=~m6g")
testEnc85 :: Test
testEnc85 = TestCase $ do
assertEqual "for (enc85 \"Hello, World!\")," "87cURD_*#4DfTZ)+T" (enc85 "Hello, World!")
assertEqual "for (enc85 \"Haskell\")," "87?RTASc/" (enc85 "Haskell")
assertEqual "for (enc85 \"😂\")," "n=Q)\"" (enc85 "😂")
testDec85 :: Test
testDec85 = TestCase $ do
assertEqual "for (dec85 \"87cURD_*#4DfTZ)+T\")," "Hello, World!" (dec85 "87cURD_*#4DfTZ)+T")
assertEqual "for (dec85 \"87?RTASc/\")," "Haskell" (dec85 "87?RTASc/")
assertEqual "for (dec85 \"n=Q)\"\")," "😂" (dec85 "n=Q)\"")
testEnc64 :: Test
testEnc64 = TestCase $ do
assertEqual "for (enc64 \"hello\")," "aGVsbG8=" (enc64 "hello")
assertEqual "for (enc64 \"Haskell\")," "SGFza2VsbA==" (enc64 "Haskell")
assertEqual "for (enc64 \"\x00\x01\x02\")," "AAEC" (enc64 "\x00\x01\x02")
assertEqual "for (enc64 \"😂\")," "8J+Ygg==" (enc64 "😂")
testDec64 :: Test
testDec64 = TestCase $ do
assertEqual "for (dec64 \"aGVsbG8=\")," "hello" (dec64 "aGVsbG8=")
assertEqual "for (dec64 \"SGFza2VsbA==\")," "Haskell" (dec64 "SGFza2VsbA==")
assertEqual "for (dec64 \"AAEC\")," "\x00\x01\x02" (dec64 "AAEC")
assertEqual "for (dec64 \"8J+Ygg==\")," "😂" (dec64 "8J+Ygg==")
testEnc45 :: Test
testEnc45 = TestCase $ do
assertEqual "for (enc45 \"Hello, World!\")," "%69 VDK2E:3404ESVDX0" (enc45 "Hello, World!")
assertEqual "for (enc45 \"Haskell\")," "Y69RQE: CI2" (enc45 "Haskell")
assertEqual "for (enc45 \"😂\")," "*IURCJ" (enc45 "😂")
testDec45 :: Test
testDec45 = TestCase $ do
assertEqual "for (dec45 \"%69 VDK2E:3404ESVDX0\")," "Hello, World!" (dec45 "%69 VDK2E:3404ESVDX0")
assertEqual "for (dec45 \"Y69RQE: CI2\")," "Haskell" (dec45 "Y69RQE: CI2")
assertEqual "for (dec45 \"*IURCJ\")," "😂" (dec45 "*IURCJ")
testEnc32 :: Test
testEnc32 = TestCase $ do
assertEqual "for (enc32 \"Hello, World!\")," "JBSWY3DPFQQFO33SNRSCC===" (enc32 "Hello, World!")
assertEqual "for (enc32 \"Haskell\")," "JBQXG23FNRWA====" (enc32 "Haskell")
assertEqual "for (enc32 \"😂\")," "6CPZRAQ=" (enc32 "😂")
testDec32 :: Test
testDec32 = TestCase $ do
assertEqual "for (dec32 \"JBSWY3DPFQQFO33SNRSCC===\")," "Hello, World!" (dec32 "JBSWY3DPFQQFO33SNRSCC===")
assertEqual "for (dec32 \"JBQXG23FNRWA====\")," "Haskell" (dec32 "JBQXG23FNRWA====")
-- assertEqual "for (dec32 \"AAEC\")," "\x00\x01\x02" (dec32 "AAEC")
assertEqual "for (dec32 \"6CPZRAQ=\")," "😂" (dec32 "6CPZRAQ=")
testEnc16 :: Test
testEnc16 = TestCase $ do
assertEqual "for (enc16 \"Hello, World!\")," "48656C6C6F2C20576F726C6421" (enc16 "Hello, World!")
assertEqual "for (enc16 \"Haskell\")," "4861736B656C6C" (enc16 "Haskell")
assertEqual "for (enc16 \"😂\")," "F09F9882" (enc16 "😂")
testDec16 :: Test
testDec16 = TestCase $ do
assertEqual "for (dec16 \"48656C6C6F2C20576F726C6421\")," "Hello, World!" (dec16 "48656C6C6F2C20576F726C6421")
assertEqual "for (dec16 \"4861736B656C6C\")," "Haskell" (dec16 "4861736B656C6C")
assertEqual "for (dec16 \"F09F9882\")," "😂" (dec16 "F09F9882")
testEnc8 :: Test
testEnc8 = TestCase $ do
assertEqual "for (enc8 \"Hello, World!\")," "110 145 154 154 157 54 40 127 157 162 154 144 41" (enc8 "Hello, World!")
assertEqual "for (enc8 \"Haskell\")," "110 141 163 153 145 154 154" (enc8 "Haskell")
assertEqual "for (enc8 \"😂\")," "360 237 230 202" (enc8 "😂")
testDec8 :: Test
testDec8 = TestCase $ do
assertEqual "for (dec8 \"110 145 154 154 157 54 40 127 157 162 154 144 41\")," "Hello, World!" (dec8 "110 145 154 154 157 54 40 127 157 162 154 144 41")
assertEqual "for (dec8 \"110 141 163 153 145 154 154\")," "Haskell" (dec8 "110 141 163 153 145 154 154")
assertEqual "for (dec8 \"360 237 230 202\")," "😂" (dec8 "360 237 230 202")
testEnc2 :: Test
testEnc2 = TestCase $ do
assertEqual "for (enc2 \"Hello, World!\")," "01001000 01100101 01101100 01101100 01101111 00101100 00100000 01010111 01101111 01110010 01101100 01100100 00100001" (enc2 "Hello, World!")
assertEqual "for (enc2 \"Haskell\")," "01001000 01100001 01110011 01101011 01100101 01101100 01101100" (enc2 "Haskell")
assertEqual "for (enc2 \"😂\")," "11110000 10011111 10011000 10000010" (enc2 "😂")
testDec2 :: Test
testDec2 = TestCase $ do
assertEqual "for (dec2 \"01001000 01100101 01101100 01101100 01101111 00101100 00100000 01010111 01101111 01110010 01101100 01100100 00100001\")," "Hello, World!" (dec2 "01001000 01100101 01101100 01101100 01101111 00101100 00100000 01010111 01101111 01110010 01101100 01100100 00100001")
assertEqual "for (dec2 \"01001000 01100001 01110011 01101011 01100101 01101100 01101100\")," "Haskell" (dec2 "01001000 01100001 01110011 01101011 01100101 01101100 01101100")
assertEqual "for (dec2 \"11110000 10011111 10011000 10000010\")," "😂" (dec2 "11110000 10011111 10011000 10000010")
testEncQp :: Test
testEncQp = TestCase $ do
assertEqual "for (encqp \"Hello, World!\")," "Hello,=20World!" (encqp "Hello, World!")
assertEqual "for (encqp \"QP works by using the equals sign = as an escape character. It also limits line length to 76, as some software has limits on line length.\")," "QP=20works=20by=20using=20the=20equals=20sign=20=3D=20as=20an=20escape=20=\r\ncharacter.=20It=20also=20limits=20line=20length=20to=2076,=20as=20some=20=\r\nsoftware=20has=20limits=20on=20line=20length." (encqp "QP works by using the equals sign = as an escape character. It also limits line length to 76, as some software has limits on line length.")
assertEqual "for (encqp \"😂\")," "=F0=9F=98=82" (encqp "😂")
testDecQp :: Test
testDecQp = TestCase $ do
assertEqual "for (decqp \"Hello,=20World!\")," "Hello, World!" (decqp "Hello,=20World!")
assertEqual "for (decqp \"QP=20works=20by=20using=20the=20equals=20sign=20=3D=20as=20an=20escape=20=\r\ncharacter.=20It=20also=20limits=20line=20length=20to=2076,=20as=20some=20=\r\nsoftware=20has=20limits=20on=20line=20length.\")," "QP works by using the equals sign = as an escape character. It also limits line length to 76, as some software has limits on line length." (decqp "QP=20works=20by=20using=20the=20equals=20sign=20=3D=20as=20an=20escape=20=\ncharacter.=20It=20also=20limits=20line=20length=20to=2076,=20as=20some=20=\nsoftware=20has=20limits=20on=20line=20length.")
assertEqual "for (decqp \"=F0=9F=98=82\")," "😂" (decqp "=F0=9F=98=82")
testEnUu :: Test
testEnUu = TestCase $ do
assertEqual "for (encuu \"Hello, World!\")," "110 145 154 154 157 54 40 127 157 162 154 144 41" (encuu "Hello, World!")
assertEqual "for (encuu \"Haskell\")," "110 141 163 153 145 154 154" (encuu "Haskell")
assertEqual "for (encuu \"😂\")," "360 237 230 202" (encuu "😂")
testDecUu :: Test
testDecUu = TestCase $ do
assertEqual "for (decuu \"110 145 154 154 157 54 40 127 157 162 154 144 41\")," "Hello, World!" (decuu "110 145 154 154 157 54 40 127 157 162 154 144 41")
assertEqual "for (decuu \"110 141 163 153 145 154 154\")," "Haskell" (decuu "110 141 163 153 145 154 154")
assertEqual "for (decuu \"360 237 230 202\")," "😂" (decuu "360 237 230 202")
tests :: Test
tests = TestList [TestLabel "Test enc91" testEnc91,
TestLabel "Test dec91" testDec91,
TestLabel "Test enc85" testEnc85,
TestLabel "Test dec85" testDec85,
TestLabel "Test enc64" testEnc64,
TestLabel "Test dec64" testDec64,
TestLabel "Test enc45" testEnc45,
TestLabel "Test dec45" testDec45,
TestLabel "Test enc32" testEnc32,
TestLabel "Test dec32" testDec32,
TestLabel "Test enc16" testEnc16,
TestLabel "Test dec16" testDec16,
TestLabel "Test enc8 " testEnc8 ,
TestLabel "Test dec8 " testDec8 ,
TestLabel "Test dec2 " testDec2 ,
TestLabel "Test enc2 " testEnc2 ,
TestLabel "Test decqp" testDecQp,
TestLabel "Test encqp" testEncQp]
-- main :: IO Counts
-- main = runTestTT tests >>= \counts -> print counts >> runTestTTAndExit tests
-- runAndPrint :: Test -> IO Counts
-- runAndPrint t = do
-- counts <- runTestTT t
-- let label = case t of
-- TestLabel l _ -> l
-- _ -> "Unnamed test."
-- putStrLn $ label ++ ": " ++ if errors counts + failures counts == 0 then "[OK]" else "[FAIL]"
-- return counts
main :: IO ()
main = do
counts <- runTestTT tests
print counts
if errors counts + failures counts == 0
then exitSuccess
else exitFailure