packages feed

fluent-1.0.0: test/VariableSpec.hs

module VariableSpec (spec) where

import Prelude

spec :: Spec
spec = do
    it "is a string" $
        translate "foo" ("arg", "Bar" :: Text) [fluent|foo = { $arg }|]
            `shouldBe` Right "Bar"
    it "is a number" $
        translate "foo" ("arg", 3 :: Int) [fluent|foo = { $arg }|]
            `shouldBe` Right "3"
    it "stands between texts" $
        translate "foo" ("arg", "Bar" :: Text) [fluent|foo = Foo { $arg } Baz|]
            `shouldBe` Right "Foo Bar Baz"
    it "stands more than once" $
        translate "foo" ("arg", "Ha" :: Text) [fluent|foo = { $arg }{ $arg }|]
            `shouldBe` Right "HaHa"
    it "shows as many fraction digits as the number holds" $
        translate
            "foo"
            ("arg", NumberValue 1 numberOptions{minimumFractionDigits = 2})
            [fluent|foo = { $arg }|]
            `shouldBe` Right "1.00"
    it "is missing" $
        translate "foo" [fluent|foo = { $arg }|]
            `shouldBe` Left "Variable not found: \"arg\""
    it "is missing only where it is used" $
        translate
            "foo"
            [fluent|
              foo = Foo
              bar = { $arg }
            |]
            `shouldBe` Right "Foo"