Backported previous tests.

This commit is contained in:
Jasper Van der Jeugt 2010-01-24 22:27:11 +01:00
parent 7a75e1f481
commit d41500758f
6 changed files with 165 additions and 1 deletions

35
tests/CompressCSS.hs Normal file
View file

@ -0,0 +1,35 @@
module CompressCSS
( compressCSSGroup
) where
import qualified Data.Map as M
import Data.Binary
import Test.Framework (testGroup)
import Test.Framework.Providers.HUnit
import Test.Framework.Providers.QuickCheck2
import Test.HUnit
import Text.Hakyll.Internal.CompressCSS
-- CompressCSS test group.
compressCSSGroup = testGroup "CompressCSS"
[ testProperty "prop_compressCSS_length" prop_compressCSS_length
, testCase "test_compressCSS_1" test_compressCSS_1
, testCase "test_compressCSS_2" test_compressCSS_2
, testCase "test_compressCSS_3" test_compressCSS_3
, testCase "test_compressCSS_4" test_compressCSS_4
]
-- CSS compression should always decrease the text length.
prop_compressCSS_length str = length str >= length (compressCSS str)
-- Compress CSS test cases.
test_compressCSS_1 = compressCSS "a { \n color : red; }" @?= "a{color:red}"
test_compressCSS_2 = compressCSS "img {border :none;;;; }"
@?= "img{border:none}"
test_compressCSS_3 =
compressCSS "p {font-size : 90%;} h1 {color :white;;; }"
@?= "p{font-size:90%}h1{color:white}"
test_compressCSS_4 = compressCSS "a { /* /* red is pretty cool */ color: red; }"
@?= "a{color:red}"

37
tests/Context.hs Normal file
View file

@ -0,0 +1,37 @@
module Context
( contextGroup
) where
import qualified Data.Map as M
import Test.QuickCheck
import Test.Framework (testGroup)
import Test.Framework.Providers.HUnit
import Test.Framework.Providers.QuickCheck2
import Test.HUnit
import Text.Hakyll.Context
-- Context test group.
contextGroup = testGroup "Context"
[ testCase "test_renderDate_1" test_renderDate_1
, testCase "test_renderDate_2" test_renderDate_2
, testCase "test_changeExtension_1" test_changeExtension_1
]
-- Date rendering test cases.
test_renderDate_1 =
M.lookup "date" rendered @?= Just "December 30, 2009"
where
rendered = renderDate "date" "%B %e, %Y" "Unknown date"
(M.singleton "path" "2009-12-30-a-title.markdown")
test_renderDate_2 = M.lookup "date" rendered @?= Just "Unknown date"
where
rendered = renderDate "date" "%B %e, %Y" "Unknown date" $
M.singleton "path" "2009-badness-30-a-title.markdown"
-- changeExtension test cases.
test_changeExtension_1 = M.lookup "url" rendered @?= Just "foo.php"
where
rendered = changeExtension "php" (M.singleton "url" "foo.html")

42
tests/File.hs Normal file
View file

@ -0,0 +1,42 @@
module File
( fileGroup
) where
import qualified Data.Map as M
import Data.Binary
import Test.Framework (testGroup)
import Test.Framework.Providers.HUnit
import Test.Framework.Providers.QuickCheck2
import Test.HUnit
import Test.QuickCheck
import Text.Hakyll.File
-- File test group.
fileGroup = testGroup "File"
[ testCase "test_toRoot_1" test_toRoot_1
, testCase "test_toRoot_2" test_toRoot_2
, testCase "test_toRoot_3" test_toRoot_3
, testCase "test_removeSpaces_1" test_removeSpaces_1
, testCase "test_removeSpaces_2" test_removeSpaces_2
, testCase "test_havingExtension_1" test_havingExtension_1
, testCase "test_havingExtension_2" test_havingExtension_2
]
-- toRoot test cases
test_toRoot_1 = toRoot "/posts/foo.html" @?= ".."
test_toRoot_2 = toRoot "posts/foo.html" @?= ".."
test_toRoot_3 = toRoot "foo.html" @?= "."
-- removeSpaces test cases
test_removeSpaces_1 = removeSpaces "$root/tags/random crap.html"
@?= "$root/tags/random-crap.html"
test_removeSpaces_2 = removeSpaces "another simple example.zip"
@?= "another-simple-example.zip"
-- Having extension test cases
test_havingExtension_1 = havingExtension ".foo" ["file.bar", "file.txt"] @?= []
test_havingExtension_2 = havingExtension ".foo" ["file.foo", "file.txt"]
@?= ["file.foo"]

View file

@ -4,9 +4,17 @@ import Test.Framework (defaultMain, testGroup)
import Test.Framework.Providers.HUnit
import Test.Framework.Providers.QuickCheck2
import CompressCSS
import Context
import File
import Regex
import Template
import Util
main = defaultMain [ templateGroup
main = defaultMain [ compressCSSGroup
, contextGroup
, fileGroup
, regexGroup
, templateGroup
, utilGroup
]

24
tests/Regex.hs Normal file
View file

@ -0,0 +1,24 @@
module Regex
( regexGroup
) where
import qualified Data.Map as M
import Data.Binary
import Test.Framework (testGroup)
import Test.Framework.Providers.HUnit
import Test.Framework.Providers.QuickCheck2
import Test.HUnit
import Test.QuickCheck
import Text.Hakyll.Regex
-- Regex test group.
regexGroup = testGroup "Regex"
[ testCase "test_splitRegex_1" test_splitRegex_1
, testCase "test_splitRegex_2" test_splitRegex_2
]
-- Split Regex test cases.
test_splitRegex_1 = splitRegex "," "1,2,3" @?= ["1", "2", "3"]
test_splitRegex_2 = splitRegex "," ",1,2," @?= ["1", "2"]

View file

@ -8,6 +8,7 @@ import Test.QuickCheck
import Test.Framework (testGroup)
import Test.Framework.Providers.HUnit
import Test.Framework.Providers.QuickCheck2
import Test.HUnit
import Text.Hakyll.Util
@ -17,6 +18,11 @@ utilGroup = testGroup "Util"
, testProperty "prop_trim_id" prop_trim_id
, testProperty "prop_stripHTML_length" prop_stripHTML_length
, testProperty "prop_stripHTML_id" prop_stripHTML_id
, testCase "test_stripHTML_1" test_stripHTML_1
, testCase "test_stripHTML_2" test_stripHTML_2
, testCase "test_stripHTML_3" test_stripHTML_3
, testCase "test_link_1" test_link_1
, testCase "test_link_2" test_link_2
]
-- Test that a string always becomes shorter when trimmed.
@ -34,3 +40,15 @@ prop_stripHTML_length str = length str >= length (stripHTML str)
-- Check that strings without tags remain untouched.
prop_stripHTML_id str = (not $ any (`elem` ['>', '<']) str)
==> str == stripHTML str
-- Strip HTML test cases.
test_stripHTML_1 = stripHTML "<b>text</b>" @?= "text"
test_stripHTML_2 = stripHTML "text" @?= "text"
test_stripHTML_3 =
stripHTML "<b>Hakyll</b>, a <i>website</i> generator<img src=\"foo.png\" />"
@?= "Hakyll, a website generator"
-- Link test cases.
test_link_1 = link "foo bar" "/foo/bar.html"
@?= "<a href=\"/foo/bar.html\">foo bar</a>"
test_link_2 = link "back home" "/" @?= "<a href=\"/\">back home</a>"