gemoire-1.0.0: test/Case/Template.hs
{-# LANGUAGE OverloadedStrings #-}
module Case.Template
( templates
) where
import Data.HashMap.Strict (empty, singleton)
import Test.HUnit (Test, (~=?))
import Gemoire.Template (Component (..), format, template)
templates :: [Test]
templates =
[ [Left "text"] ~=? template "text"
, [Left "also {$", Left "text"] ~=? template "also {$text"
, [Right $ Placeholder "placeholder" Nothing] ~=? template "{$ placeholder $}"
, [Right $ Placeholder "with" $ Just "default value"] ~=? template "{$with:default value$}"
, [Right $ Placeholder "{$weird" Nothing, Left "$}"] ~=? template "{${$weird$}$}"
, [Right $ Placeholder "pholder" $ Just "multiline \CR\LF value"]
~=? template "{$pholder:multiline \CR\LF value$}"
, [Right $ Placeholder "multiline\CR\LFunfortunately" Nothing]
~=? template "{$multiline\CR\LFunfortunately$}"
, [Left "mixed ", Right $ Placeholder "pholder" Nothing, Left " text"]
~=? template "mixed {$pholder$} text"
, [Right $ Fallback "variable" "fallback" Nothing] ~=? template "{&variable:fallback&}"
, [Right $ Fallback "same as a variable" "" Nothing] ~=? template "{& same as a variable&}"
, [Right $ Fallback "var" "fback" (Just "default")] ~=? template "{&var:fback:default&}"
, [Left "commented ", Left " text"] ~=? template "commented {# meow #} text"
, [] ~=? template "{# comment with {$flare$} #}"
, [] ~=? template "{#multiline \CR\LF comment#}"
, [Left "{# not a comment #}"] ~=? template "{\\{# not a comment #}\\}"
, [Left "constant"] ~=? template "{\\constant\\}"
, "formatted text!" ~=? format (template "formatted {$ key $}") (singleton "key" "text!")
, "default value" ~=? format (template "{$key:default$} value") empty
, "falled back!" ~=? format (template "falled {&unexist:fallback&}!") (singleton "fallback" "back")
, "couldn't fall back." ~=? format (template "couldn't {&a:b:fall&} back.") empty
]