packages feed

fluent-1.1.0: test/ExpansionSpec.hs

module ExpansionSpec (spec) where

import Data.Text qualified as Text
import Prelude

spec :: Spec
spec = do
    it "expands a message that refers to another one twice, a few levels deep" $
        translate "a5" doubling `shouldBe` Right (Text.replicate 32 "x")
    it "stops expanding a message that refers to another one twice, many levels deep" $
        translate "a30" doubling `shouldBe` Left "Too many placeables expanded"

doubling :: Resource
doubling =
    either error id . parseResource . Text.unlines $
        "a0 = x" : (message <$> [1 .. 30 :: Int])

message :: Int -> Text
message n = level n <> " = { " <> level (n - 1) <> " }{ " <> level (n - 1) <> " }"

level :: Int -> Text
level n = "a" <> Text.show n