diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CompressCSS.hs | 35 | ||||
-rw-r--r-- | tests/Context.hs | 37 | ||||
-rw-r--r-- | tests/File.hs | 42 | ||||
-rw-r--r-- | tests/Main.hs | 10 | ||||
-rw-r--r-- | tests/Regex.hs | 24 | ||||
-rw-r--r-- | tests/Util.hs | 18 |
6 files changed, 165 insertions, 1 deletions
diff --git a/tests/CompressCSS.hs b/tests/CompressCSS.hs new file mode 100644 index 0000000..855efcf --- /dev/null +++ b/tests/CompressCSS.hs @@ -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}" diff --git a/tests/Context.hs b/tests/Context.hs new file mode 100644 index 0000000..d8d0504 --- /dev/null +++ b/tests/Context.hs @@ -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") diff --git a/tests/File.hs b/tests/File.hs new file mode 100644 index 0000000..bdc97a1 --- /dev/null +++ b/tests/File.hs @@ -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"] diff --git a/tests/Main.hs b/tests/Main.hs index e3a673d..cdd46dc 100644 --- a/tests/Main.hs +++ b/tests/Main.hs @@ -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 ] diff --git a/tests/Regex.hs b/tests/Regex.hs new file mode 100644 index 0000000..5aac932 --- /dev/null +++ b/tests/Regex.hs @@ -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"] diff --git a/tests/Util.hs b/tests/Util.hs index 087edbd..1369ada 100644 --- a/tests/Util.hs +++ b/tests/Util.hs @@ -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>" |