on hakyll-2.1 help sign in
hakyll/tests/Util.hs
54 lines 1.9 kB history raw
1module Util
2 ( utilGroup
3 ) where
5import Data.Char
7import Test.QuickCheck
8import Test.Framework (testGroup)
9import Test.Framework.Providers.HUnit
10import Test.Framework.Providers.QuickCheck2
11import Test.HUnit
13import Text.Hakyll.Util
15-- Util test group.
16utilGroup = testGroup "Util"
17 [ testProperty "prop_trim_length" prop_trim_length
18 , testProperty "prop_trim_id" prop_trim_id
19 , testProperty "prop_stripHtml_length" prop_stripHtml_length
20 , 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
26 ]
28-- Test that a string always becomes shorter when trimmed.
29prop_trim_length str = length str >= length (trim str)
31-- Check that a string which does not start or end with a space is not trimmed.
32prop_trim_id str = (not $ null str) && isAlreadyTrimmed ==> str == (trim str)
33 where
34 isAlreadyTrimmed :: Bool
35 isAlreadyTrimmed = (not $ isSpace $ head str) && (not $ isSpace $ last str)
37-- Check that a stripped string is shorter.
38prop_stripHtml_length str = length str >= length (stripHtml str)
40-- Check that strings without tags remain untouched.
41prop_stripHtml_id str = (not $ any (`elem` ['>', '<']) str)
42 ==> str == stripHtml str
44-- Strip Html test cases.
45test_stripHtml_1 = stripHtml "<b>text</b>" @?= "text"
46test_stripHtml_2 = stripHtml "text" @?= "text"
47test_stripHtml_3 =
48 stripHtml "<b>Hakyll</b>, a <i>website</i> generator<img src=\"foo.png\" />"
49 @?= "Hakyll, a website generator"
51-- Link test cases.
52test_link_1 = link "foo bar" "/foo/bar.html"
53 @?= "<a href=\"/foo/bar.html\">foo bar</a>"
54test_link_2 = link "back home" "/" @?= "<a href=\"/\">back home</a>"