fluent-1.1.0: test/ArgumentSpec.hs
module ArgumentSpec (spec) where
import Language.Fluent.Value qualified as Value
import Prelude
spec :: Spec
spec = do
it "is a text" $
translate "foo" ("arg", "Bar" :: Text) [fluent|foo = { $arg }|] `shouldBe` Right "Bar"
it "is a whole number" $
translate "foo" ("arg", 3 :: Int) [fluent|foo = { $arg }|] `shouldBe` Right "3"
it "is a number with a fraction" $
translate "foo" ("arg", 1.5 :: Scientific) [fluent|foo = { $arg }|] `shouldBe` Right "1.5"
it "is a value the caller has already made" $
translate "foo" ("arg", Value.String "Bar") [fluent|foo = { $arg }|] `shouldBe` Right "Bar"
it "is a custom value" $
translate "foo" ("arg", Value.Formatted \_ -> Right "Bar") [fluent|foo = { $arg }|]
`shouldBe` Right "Bar"
it "is a custom value that the locale formats" $
translate
"foo"
("arg", Value.Formatted \locales -> Value.format locales $ Value.Number 1234 numberOptions)
[fluent|foo = { $arg }|]
`shouldBe` Right "1,234"
it "counts the way the locale counts" $
translate
"foo"
("n", 1 :: Int)
[fluent|
foo = { $n ->
[one] one
*[other] other
}
|]
`shouldBe` Right "one"
it "is one of several" $
translate
"foo"
("name", "Ann" :: Text)
("count", 2 :: Int)
[fluent|foo = { $name } has { $count } messages|]
`shouldBe` Right "Ann has 2 messages"