summaryrefslogtreecommitdiff
path: root/tests/Util.hs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Util.hs')
-rw-r--r--tests/Util.hs23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/Util.hs b/tests/Util.hs
new file mode 100644
index 0000000..9e2a0dd
--- /dev/null
+++ b/tests/Util.hs
@@ -0,0 +1,23 @@
+module Util where
+
+import Data.Char
+
+import Test.QuickCheck
+
+import Text.Hakyll.Util
+
+-- Test that a string always becomes shorter when trimmed.
+prop_trim_length str = length str >= length (trim str)
+
+-- Check that a string which does not start or end with a space is not trimmed.
+prop_trim_id str = (not $ null str) && isAlreadyTrimmed ==> str == (trim str)
+ where
+ isAlreadyTrimmed :: Bool
+ isAlreadyTrimmed = (not $ isSpace $ head str) && (not $ isSpace $ last str)
+
+-- Check that a stripped string is shorter.
+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