on master help sign in
Backported previous tests.
commitd41500758f884a4e7a54a4696a2a521b4465242f authorJasper Van der Jeugt <jaspervdj@gmail.com> dateSun 24 Jan 2010, 22:27 (17 years ago) parent7a75e1f
6 files changed+165−1
tests/CompressCSS.hs+35 tests/Context.hs+37 tests/File.hs+42 tests/Main.hs+9−1 tests/Regex.hs+24 tests/Util.hs+18
tests/CompressCSS.hsnew file+35
@@ -0,0 +1,35 @@
1+module CompressCSS
2+ ( compressCSSGroup
3+ ) where
4+
5+import qualified Data.Map as M
6+
7+import Data.Binary
8+import Test.Framework (testGroup)
9+import Test.Framework.Providers.HUnit
10+import Test.Framework.Providers.QuickCheck2
11+import Test.HUnit
12+
13+import Text.Hakyll.Internal.CompressCSS
14+
15+-- CompressCSS test group.
16+compressCSSGroup = testGroup "CompressCSS"
17+ [ testProperty "prop_compressCSS_length" prop_compressCSS_length
18+ , testCase "test_compressCSS_1" test_compressCSS_1
19+ , testCase "test_compressCSS_2" test_compressCSS_2
20+ , testCase "test_compressCSS_3" test_compressCSS_3
21+ , testCase "test_compressCSS_4" test_compressCSS_4
22+ ]
23+
24+-- CSS compression should always decrease the text length.
25+prop_compressCSS_length str = length str >= length (compressCSS str)
26+
27+-- Compress CSS test cases.
28+test_compressCSS_1 = compressCSS "a { \n color : red; }" @?= "a{color:red}"
29+test_compressCSS_2 = compressCSS "img {border :none;;;; }"
30+ @?= "img{border:none}"
31+test_compressCSS_3 =
32+ compressCSS "p {font-size : 90%;} h1 {color :white;;; }"
33+ @?= "p{font-size:90%}h1{color:white}"
34+test_compressCSS_4 = compressCSS "a { /* /* red is pretty cool */ color: red; }"
35+ @?= "a{color:red}"
tests/Context.hsnew file+37
@@ -0,0 +1,37 @@
1+module Context
2+ ( contextGroup
3+ ) where
4+
5+import qualified Data.Map as M
6+
7+import Test.QuickCheck
8+import Test.Framework (testGroup)
9+import Test.Framework.Providers.HUnit
10+import Test.Framework.Providers.QuickCheck2
11+import Test.HUnit
12+
13+import Text.Hakyll.Context
14+
15+-- Context test group.
16+contextGroup = testGroup "Context"
17+ [ testCase "test_renderDate_1" test_renderDate_1
18+ , testCase "test_renderDate_2" test_renderDate_2
19+ , testCase "test_changeExtension_1" test_changeExtension_1
20+ ]
21+
22+-- Date rendering test cases.
23+test_renderDate_1 =
24+ M.lookup "date" rendered @?= Just "December 30, 2009"
25+ where
26+ rendered = renderDate "date" "%B %e, %Y" "Unknown date"
27+ (M.singleton "path" "2009-12-30-a-title.markdown")
28+
29+test_renderDate_2 = M.lookup "date" rendered @?= Just "Unknown date"
30+ where
31+ rendered = renderDate "date" "%B %e, %Y" "Unknown date" $
32+ M.singleton "path" "2009-badness-30-a-title.markdown"
33+
34+-- changeExtension test cases.
35+test_changeExtension_1 = M.lookup "url" rendered @?= Just "foo.php"
36+ where
37+ rendered = changeExtension "php" (M.singleton "url" "foo.html")
tests/File.hsnew file+42
@@ -0,0 +1,42 @@
1+module File
2+ ( fileGroup
3+ ) where
4+
5+import qualified Data.Map as M
6+
7+import Data.Binary
8+import Test.Framework (testGroup)
9+import Test.Framework.Providers.HUnit
10+import Test.Framework.Providers.QuickCheck2
11+import Test.HUnit
12+import Test.QuickCheck
13+
14+import Text.Hakyll.File
15+
16+-- File test group.
17+fileGroup = testGroup "File"
18+ [ testCase "test_toRoot_1" test_toRoot_1
19+ , testCase "test_toRoot_2" test_toRoot_2
20+ , testCase "test_toRoot_3" test_toRoot_3
21+ , testCase "test_removeSpaces_1" test_removeSpaces_1
22+ , testCase "test_removeSpaces_2" test_removeSpaces_2
23+ , testCase "test_havingExtension_1" test_havingExtension_1
24+ , testCase "test_havingExtension_2" test_havingExtension_2
25+ ]
26+
27+
28+-- toRoot test cases
29+test_toRoot_1 = toRoot "/posts/foo.html" @?= ".."
30+test_toRoot_2 = toRoot "posts/foo.html" @?= ".."
31+test_toRoot_3 = toRoot "foo.html" @?= "."
32+
33+-- removeSpaces test cases
34+test_removeSpaces_1 = removeSpaces "$root/tags/random crap.html"
35+ @?= "$root/tags/random-crap.html"
36+test_removeSpaces_2 = removeSpaces "another simple example.zip"
37+ @?= "another-simple-example.zip"
38+
39+-- Having extension test cases
40+test_havingExtension_1 = havingExtension ".foo" ["file.bar", "file.txt"] @?= []
41+test_havingExtension_2 = havingExtension ".foo" ["file.foo", "file.txt"]
42+ @?= ["file.foo"]
tests/Main.hs+9−1
@@ -4,9 +4,17 @@ import Test.Framework (defaultMain, testGroup)
44import Test.Framework.Providers.HUnit
55import Test.Framework.Providers.QuickCheck2
66
7+import CompressCSS
8+import Context
9+import File
10+import Regex
711import Template
812import Util
913
10−main = defaultMain [ templateGroup
14+main = defaultMain [ compressCSSGroup
15+ , contextGroup
16+ , fileGroup
17+ , regexGroup
18+ , templateGroup
1119 , utilGroup
1220 ]
tests/Regex.hsnew file+24
@@ -0,0 +1,24 @@
1+module Regex
2+ ( regexGroup
3+ ) where
4+
5+import qualified Data.Map as M
6+
7+import Data.Binary
8+import Test.Framework (testGroup)
9+import Test.Framework.Providers.HUnit
10+import Test.Framework.Providers.QuickCheck2
11+import Test.HUnit
12+import Test.QuickCheck
13+
14+import Text.Hakyll.Regex
15+
16+-- Regex test group.
17+regexGroup = testGroup "Regex"
18+ [ testCase "test_splitRegex_1" test_splitRegex_1
19+ , testCase "test_splitRegex_2" test_splitRegex_2
20+ ]
21+
22+-- Split Regex test cases.
23+test_splitRegex_1 = splitRegex "," "1,2,3" @?= ["1", "2", "3"]
24+test_splitRegex_2 = splitRegex "," ",1,2," @?= ["1", "2"]
tests/Util.hs+18
@@ -8,6 +8,7 @@ import Test.QuickCheck
88import Test.Framework (testGroup)
99import Test.Framework.Providers.HUnit
1010import Test.Framework.Providers.QuickCheck2
11+import Test.HUnit
1112
1213import Text.Hakyll.Util
1314
@@ -17,6 +18,11 @@ utilGroup = testGroup "Util"
1718 , testProperty "prop_trim_id" prop_trim_id
1819 , testProperty "prop_stripHTML_length" prop_stripHTML_length
1920 , testProperty "prop_stripHTML_id" prop_stripHTML_id
21+ , testCase "test_stripHTML_1" test_stripHTML_1
22+ , testCase "test_stripHTML_2" test_stripHTML_2
23+ , testCase "test_stripHTML_3" test_stripHTML_3
24+ , testCase "test_link_1" test_link_1
25+ , testCase "test_link_2" test_link_2
2026 ]
2127
2228-- Test that a string always becomes shorter when trimmed.
@@ -34,3 +40,15 @@ prop_stripHTML_length str = length str >= length (stripHTML str)
3440-- Check that strings without tags remain untouched.
3541prop_stripHTML_id str = (not $ any (`elem` ['>', '<']) str)
3642 ==> str == stripHTML str
43+
44+-- Strip HTML test cases.
45+test_stripHTML_1 = stripHTML "<b>text</b>" @?= "text"
46+test_stripHTML_2 = stripHTML "text" @?= "text"
47+test_stripHTML_3 =
48+ stripHTML "<b>Hakyll</b>, a <i>website</i> generator<img src=\"foo.png\" />"
49+ @?= "Hakyll, a website generator"
50+
51+-- Link test cases.
52+test_link_1 = link "foo bar" "/foo/bar.html"
53+ @?= "<a href=\"/foo/bar.html\">foo bar</a>"
54+test_link_2 = link "back home" "/" @?= "<a href=\"/\">back home</a>"