@@ -1,12 +1,25 @@
1−module Template where
1+module Template
2+ ( templateGroup
3+ ) where
24
35import qualified Data.Map as M
46
5−import Test.QuickCheck
67import Data.Binary
8+import Test.Framework (testGroup)
9+import Test.Framework.Providers.HUnit
10+import Test.Framework.Providers.QuickCheck2
11+import Test.HUnit
712
813import Text.Hakyll.Internal.Template
914
15+-- Template test group.
16+templateGroup = testGroup "Template"
17+ [ testProperty "prop_template_encode_id" prop_template_encode_id
18+ , testProperty "prop_substitute_id" prop_substitute_id
19+ , testCase "test_substitute_1" test_substitute_1
20+ , testCase "test_substitute_2" test_substitute_2
21+ ]
22+
1023-- Test encoding/decoding of templates.
1124prop_template_encode_id :: Template -> Bool
1225prop_template_encode_id template = decode (encode template) == template
@@ -16,10 +29,15 @@ prop_substitute_id string =
1629 regularSubstitute (fromString string) M.empty == string
1730
1831-- substitute test case 1.
19−prop_substitute_case1 string1 string2 =
20− finalSubstitute template context == string1 ++ " costs $" ++ string2 ++ "."
32+test_substitute_1 =
33+ finalSubstitute template context @?= "Banana costs $4."
2134 where
2235 template = fromString "$product costs $$$price."
23− context = M.fromList [ ("product", string1)
24− , ("price", string2)
25− ]
36+ context = M.fromList [("product", "Banana"), ("price", "4")]
37+
38+-- substitute test case 2.
39+test_substitute_2 =
40+ regularSubstitute template context @?= "$$root is a special key."
41+ where
42+ template = fromString "$$root is a special $thing."
43+ context = M.fromList [("root", "foo"), ("thing", "key")]