File: main.hs

package info (click to toggle)
haskell-file-embed 0.0.16.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 96 kB
  • sloc: haskell: 301; makefile: 3
file content (28 lines) | stat: -rw-r--r-- 882 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE OverloadedStrings #-}

import Control.Monad (unless)
import qualified Data.ByteString as B (ByteString, filter)
import Data.FileEmbed
import System.FilePath ((</>))

infix 1 @?=

(@?=) :: (Eq a, Show a) => a -> a -> IO ()
actual @?= expected = unless (actual == expected) (error $ "expected: " ++ show expected ++ "\n but got: " ++ show actual)

main :: IO ()
main = do
    let received = $(embedDir "test/sample")
    received @?=
        [ ("bar" </> "baz", "baz\r\n")
        , ("foo", "foo\r\n")
        ]
    let str = $(embedStringFile "test/sample/foo") :: String
    filter (/= '\r') str @?= "foo\n"

    let mbs = $(embedFileIfExists "test/sample/foo")
    fmap (B.filter (/= fromIntegral (fromEnum '\r'))) mbs @?= Just "foo\n"

    let mbs2 = $(embedFileIfExists "test/sample/foo2") :: Maybe B.ByteString
    mbs2 @?= Nothing