fluent-effectful-1.0.0: test/Effectful/Fluent/MultiSpec.hs
module Effectful.Fluent.MultiSpec (spec) where
import Data.Text (Text)
import Effectful
import Effectful.Fluent.Multi
import Effectful.Hspec
import Language.Fluent.ICU
import Util
import Prelude
spec :: (Hspec :> es) => Eff es ()
spec = do
it "reads a message in the language it is asked for" $ runFluent [english, swiss] do
translate "greeting" enGB `shouldReturn` Right "Hello!"
translate "greeting" deCH `shouldReturn` Right "Grüezi!"
it "reads the arguments a message of that language asks for" $ runFluent [english, swiss] do
translate "welcome" ("name", "Ann" :: Text) enGB `shouldReturn` Right "Welcome, \8296Ann\8297"
translate "welcome" ("name", "Ann" :: Text) deCH `shouldReturn` Right "Willkommen, \8296Ann\8297"
it "reads a message of the one language that holds it" $ runFluent [english, swiss] do
translate "biscuit" enGB `shouldReturn` Right "Biscuit"
translate "biscuit" deCH `shouldReturn` Left "Message not found: \"biscuit\""
it "holds no bundle of a language it was given none of" $ runFluent [english] do
translate "greeting" deCH `shouldReturn` Left "No bundle for locale de-CH"
it "holds no bundle at all where it was given none" $ runFluent @LocaleName [] do
translate "greeting" enGB `shouldReturn` Left "No bundle for locale en-GB"
it "reads the first bundle of a language it was given two of" $
runFluent [english, shouting] do
translate "greeting" enGB `shouldReturn` Right "Hello!"
it "knows a bundle by that name and by no shorter or longer one" $ runFluent [english] do
translate "greeting" en `shouldReturn` Left "No bundle for locale en"
translate "greeting" enGBOxendict `shouldReturn` Left "No bundle for locale en-GB-oxendict"
it "reads what a caller asks of the bundle it reads from" $ runFluent [english] do
translate "shouted" (UseIsolating False) enGB `shouldReturn` Right "a Hello! b"
translate "shouted" enGB `shouldReturn` Right "a \8296Hello!\8297 b"