lz4-hs-0.1.4.0: test/Spec.hs
module Main (main) where
import Codec.Lz4
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as BSL
import Test.Tasty
import Test.Tasty.HUnit
testCompression :: FilePath -> TestTree
testCompression fp = testCase ("Highly compressed frames " ++ fp) $ do
contents <- BSL.readFile "cbits/lz4.c"
let sz0 = BSL.length (compressSz 0 contents)
sz1 = BSL.length (compressSz 6 contents)
assertBool "higher compression means smaller frames" $ sz1 < sz0
testRoundtripBlocks :: FilePath -> TestTree
testRoundtripBlocks fp = testCase ("Roundtrip " ++ fp) $ do
contents <- BS.readFile fp
let sz = BS.length contents
actual = decompressBlockSz (compressBlock contents) sz
actual @?= contents
testRoundtripFrames :: FilePath -> TestTree
testRoundtripFrames fp = testCase ("Roundtrip " ++ fp) $ do
contents <- BSL.readFile fp
let actual = decompressBufSz (32 * 1024) (compress contents)
actual @?= contents
main :: IO ()
main =
defaultMain $
testGroup "lz4" [testBlocks, testFrames, testHC]
where
testBlocks = testGroup "Block compression"
[ testRoundtripBlocks "lz4-hs.cabal"
, testRoundtripBlocks "LICENSE"
]
testFrames = testGroup "Frame compression"
[ testRoundtripFrames "cbits/lz4.c"
]
testHC = testGroup "Compression levels"
[ testCompression "cbits/lz4frame.c"
]