free-alacarte 1.0.0.6 → 1.0.0.7
raw patch · 3 files changed
+105/−1 lines, 3 filesdep +QuickCheckdep +containersdep +free-alacartedep ~basePVP ok
version bump matches the API change (PVP)
Dependencies added: QuickCheck, containers, free-alacarte, hspec, relude, tasty, tasty-hspec, text, time
Dependency ranges changed: base
API changes (from Hackage documentation)
Files
- free-alacarte.cabal +44/−1
- test/Free/AlaCarte/Test.hs +54/−0
- test/Spec.hs +7/−0
free-alacarte.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.12 name: free-alacarte-version: 1.0.0.6+version: 1.0.0.7 maintainer: Josep Bigorra <jjbigorra@gmail.com> build-type: Simple license: LGPL-3@@ -55,3 +55,46 @@ base < 5 default-language: GHC2021 +test-suite free-alacarte-spec+ type: exitcode-stdio-1.0+ main-is: Spec.hs+ other-modules:+ Paths_free_alacarte+ Free.AlaCarte.Test+ hs-source-dirs:+ test+ ghc-options: -Wall -threaded -rtsopts "-with-rtsopts=-T -N"+ default-extensions:+ DataKinds+ DefaultSignatures+ DuplicateRecordFields+ EmptyDataDecls+ ExistentialQuantification+ FlexibleContexts+ FlexibleInstances+ FunctionalDependencies+ GADTs+ InstanceSigs+ KindSignatures+ LambdaCase+ MultiWayIf+ NamedFieldPuns+ NoImplicitPrelude+ OverloadedStrings+ PartialTypeSignatures+ RecordWildCards+ TypeFamilies+ ViewPatterns++ build-depends:+ free-alacarte+ , base+ , hspec+ , QuickCheck+ , tasty+ , tasty-hspec+ , relude+ , text+ , containers+ , time+ default-language: GHC2021
+ test/Free/AlaCarte/Test.hs view
@@ -0,0 +1,54 @@+module Free.AlaCarte.Test where++import Data.Text qualified as T+import Free.AlaCarte+import Relude+import Test.Hspec++data FileSystem a+ = MyReadFile FilePath (Either UnicodeException Text -> a)+ | MyWriteFile FilePath Text a+ deriving (Functor)++instance Exec FileSystem where+ execAlgebra (MyReadFile path next) = do+ rawFileContents <- readFileBS path+ next (decodeUtf8' rawFileContents)+ execAlgebra (MyWriteFile path fileContents next) = do+ _ <- writeFileText path fileContents+ next++myReadFile :: (FileSystem :<: f) => FilePath -> Free f (Either UnicodeException Text)+myReadFile path = injectFree (MyReadFile path Pure)++myWriteFile :: (FileSystem :<: f) => FilePath -> Text -> Free f ()+myWriteFile path fileContents = injectFree (MyWriteFile path fileContents (Pure ()))++data Logger a = LogInfo Text a deriving (Functor)++instance Exec Logger where+ execAlgebra (LogInfo message next) = putTextLn message >> next++logInfo :: (Logger :<: f) => Text -> Free f ()+logInfo message = injectFree (LogInfo message (Pure ()))++freealacarteSpec :: SpecWith ()+freealacarteSpec = do+ describe "Free a la Carte" $ do+ describe "using the FileSystem free monad" $ do+ it "can read from file successfully " $ do+ fileContents <- exec @FileSystem $ myReadFile "./resources/test/file-0.txt"+ second T.strip fileContents `shouldBe` Right "Free a la Carte"+ it "can write to file successfully" $ do+ exec @FileSystem $ myWriteFile "./resources/test/some-test-file.txt" "Free a la Carte"+ describe "using the Logger free monad" $ do+ it "can log to stdout" $ do+ exec @Logger $ logInfo "Free a la Carte"+ describe "using FileSystem :+: Logger monads" $ do+ it "can read a file's contents to stdout" $ do+ exec @(FileSystem :+: Logger) $ readFileContentsToStdout "./resources/test/file-0.txt"++readFileContentsToStdout :: (Logger :<: f, FileSystem :<: f) => FilePath -> Free f ()+readFileContentsToStdout path = do+ maybeFileContents <- myReadFile path+ either (logInfo . T.pack . show) logInfo maybeFileContents
+ test/Spec.hs view
@@ -0,0 +1,7 @@+import Relude+import Test.Hspec+import Free.AlaCarte.Test++main :: IO ()+main = hspec $ do+ freealacarteSpec