EmbedTestGenerator.hs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. {-# LANGUAGE TemplateHaskell, QuasiQuotes, OverloadedStrings #-}
  2. module EmbedTestGenerator (testGen) where
  3. import Data.Default
  4. import Network.Mime (MimeType)
  5. import Yesod.EmbeddedStatic.Types
  6. import Yesod.EmbeddedStatic.Generators (pathToName)
  7. import qualified Data.Text as T
  8. import qualified Data.Text.Lazy as TL
  9. import qualified Data.Text.Lazy.Encoding as TL
  10. import qualified Data.ByteString.Lazy as BL
  11. e1, e2, e3, e4 :: Entry
  12. -- Basic entry
  13. e1 = def
  14. { ebHaskellName = Just $ pathToName "e1"
  15. , ebLocation = "e1"
  16. , ebMimeType = "text/plain"
  17. , ebProductionContent = return $ TL.encodeUtf8 "e1 production"
  18. , ebDevelReload = [| return $ TL.encodeUtf8 $ TL.pack "e1 devel" |]
  19. , ebDevelExtraFiles = Nothing
  20. }
  21. -- Test simulated directory in location
  22. e2 = def
  23. { ebHaskellName = Just $ pathToName "e2"
  24. , ebLocation = "dir/e2"
  25. , ebMimeType = "abcdef"
  26. , ebProductionContent = return $ TL.encodeUtf8 "e2 production"
  27. , ebDevelReload = [| return $ TL.encodeUtf8 $ TL.pack "e2 devel" |]
  28. , ebDevelExtraFiles = Nothing
  29. }
  30. -- Test empty haskell name
  31. e3 = def
  32. { ebHaskellName = Nothing
  33. , ebLocation = "xxxx/e3"
  34. , ebMimeType = "yyy"
  35. , ebProductionContent = return $ TL.encodeUtf8 "e3 production"
  36. , ebDevelReload = [| return $ TL.encodeUtf8 $ TL.pack "e3 devel" |]
  37. , ebDevelExtraFiles = Nothing
  38. }
  39. devExtra :: [T.Text] -> IO (Maybe (MimeType, BL.ByteString))
  40. devExtra ["dev1"] = return $ Just ("mime", "dev1 content")
  41. devExtra ["dir", "dev2"] = return $ Just ("mime2", "dev2 content")
  42. devExtra _ = return Nothing
  43. -- Entry with devel extra files
  44. e4 = def
  45. { ebHaskellName = Just $ pathToName "e4"
  46. , ebLocation = "e4"
  47. , ebMimeType = "text/plain"
  48. , ebProductionContent = return $ TL.encodeUtf8 "e4 production"
  49. , ebDevelReload = [| return $ TL.encodeUtf8 $ TL.pack "e4 devel" |]
  50. , ebDevelExtraFiles = Just [| devExtra |]
  51. }
  52. testGen :: Generator
  53. testGen = return [e1, e2, e3, e4]