@@ -1,12 +1,25 @@
1−module Template where
1+module Template
3import qualified Data.Map as M
5import qualified Data.Map as M
6import Data.Binary
7import Data.Binary
8+import Test.Framework (testGroup)
9+import Test.Framework.Providers.HUnit
10+import Test.Framework.Providers.QuickCheck2
8import Text.Hakyll.Internal.Template
13import Text.Hakyll.Internal.Template
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
10-- Test encoding/decoding of templates.
23-- Test encoding/decoding of templates.
11prop_template_encode_id :: Template -> Bool
24prop_template_encode_id :: Template -> Bool
12prop_template_encode_id template = decode (encode template) == template
25prop_template_encode_id template = decode (encode template) == template
@@ -16,10 +29,15 @@ prop_substitute_id string =
16 regularSubstitute (fromString string) M.empty == string
29 regularSubstitute (fromString string) M.empty == string
18-- substitute test case 1.
31-- substitute test case 1.
19−prop_substitute_case1 string1 string2 =
32+test_substitute_1 =
20− finalSubstitute template context == string1 ++ " costs $" ++ string2 ++ "."
33+ finalSubstitute template context @?= "Banana costs $4."
22 template = fromString "$product costs $$$price."
35 template = fromString "$product costs $$$price."
23− context = M.fromList [ ("product", string1)
36+ context = M.fromList [("product", "Banana"), ("price", "4")]
24− , ("price", string2)
37+
25− ]
38+-- substitute test case 2.
40+ regularSubstitute template context @?= "$$root is a special key."
42+ template = fromString "$$root is a special $thing."
43+ context = M.fromList [("root", "foo"), ("thing", "key")]