File: TypeSpec.hs

package info (click to toggle)
haskell-microstache 1.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 172 kB
  • sloc: haskell: 971; makefile: 3
file content (47 lines) | stat: -rw-r--r-- 1,421 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{-# LANGUAGE OverloadedStrings #-}

module Text.Microstache.TypeSpec
  ( main
  , spec )
where

import Data.Semigroup ((<>))
import Test.Hspec
import Text.Microstache.Type
import qualified Data.Map as M

main :: IO ()
main = hspec spec

spec :: Spec
spec = do
  describe "Template instances" $
    context "the Semigroup instance" $ do
      it "the resulting template inherits focus of the left one" $
        templateActual (templateA <> templateB)
          `shouldBe` templateActual templateA
      it "the resulting template merges caches with left bias" $
        templateCache (templateA <> templateB)
          `shouldBe` M.fromList
            [ ("c", [TextBlock "foo"])
            , ("d", [TextBlock "bar"])
            , ("e", [TextBlock "baz"]) ]
  describe "showKey" $ do
    context "when the key has no elements in it" $
      it "is rendered correctly" $
        showKey (Key []) `shouldBe` "<implicit>"
    context "when the key has some elements" $
      it "is rendered correctly" $ do
        showKey (Key ["boo"]) `shouldBe` "boo"
        showKey (Key ["foo","bar"]) `shouldBe` "foo.bar"
        showKey (Key ["baz","baz","quux"]) `shouldBe` "baz.baz.quux"

templateA :: Template
templateA = Template "a" $ M.fromList
  [ ("c", [TextBlock "foo"])
  , ("d", [TextBlock "bar"]) ]

templateB :: Template
templateB = Template "b" $ M.fromList
  [ ("c", [TextBlock "bar"])
  , ("e", [TextBlock "baz"]) ]