diff options
author | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2009-12-25 11:55:03 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2009-12-25 11:55:03 +0100 |
commit | 4fa472250e9041f95dc21adefcfd70cfefd09bc2 (patch) | |
tree | e43be11018af8895df3b80047ddc44eb7b937ec1 | |
parent | ce2cef43509f7912089443c0a651cb334fd9bcc5 (diff) | |
download | hakyll-4fa472250e9041f95dc21adefcfd70cfefd09bc2.tar.gz |
Added some tests.
-rw-r--r-- | src/Text/Hakyll/CompressCSS.hs | 1 | ||||
-rw-r--r-- | tests/Tests.hs | 53 |
2 files changed, 54 insertions, 0 deletions
diff --git a/src/Text/Hakyll/CompressCSS.hs b/src/Text/Hakyll/CompressCSS.hs index 7f3ddc3..c8c4bcb 100644 --- a/src/Text/Hakyll/CompressCSS.hs +++ b/src/Text/Hakyll/CompressCSS.hs @@ -19,6 +19,7 @@ compressCSS = compressSeparators compressSeparators :: String -> String compressSeparators = subRegex' ";\\s*}" "}" . subRegex' "\\s*([{};:])\\s*" "\\1" + . subRegex' ";;*" ";" -- | Compresses all whitespace. compressWhitespace :: String -> String diff --git a/tests/Tests.hs b/tests/Tests.hs new file mode 100644 index 0000000..eb1f275 --- /dev/null +++ b/tests/Tests.hs @@ -0,0 +1,53 @@ +import Test.Framework (defaultMain, testGroup) +import Test.Framework.Providers.QuickCheck2 +import Test.Framework.Providers.HUnit +import Test.QuickCheck +import Test.HUnit + +import Data.Char + +import Text.Hakyll.CompressCSS +import Text.Hakyll.Util + +main = defaultMain tests + +tests = [ testGroup "Util group" [ testProperty "trim length" prop_trim_length + , testProperty "trim id" prop_trim_id + , testProperty "trim empty" prop_trim_empty + , testCase "stripHTML 1" test_strip_html1 + , testCase "stripHTML 2" test_strip_html2 + , testCase "stripHTML 3" test_strip_html3 + ] + + , testGroup "CompressCSS group" [ testProperty "compressCSS length" prop_compress_css_length + , testCase "compressCSS 1" test_compress_css1 + , testCase "compressCSS 2" test_compress_css2 + , testCase "compressCSS 3" test_compress_css3 + ] + ] + +-- 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) + && (not $ isSpace $ head str) + && (not $ isSpace $ last str) + ==> str == (trim str) + +-- An string of only spaces should be reduced to an empty string. +prop_trim_empty str = (all isSpace str) ==> null (trim str) + +-- Strip HTML test cases. +test_strip_html1 = stripHTML "<b>text</b>" @?= "text" +test_strip_html2 = stripHTML "text" @?= "text" +test_strip_html3 = stripHTML "<b>Hakyll</b> is an <i>awesome</i> web framework <img src=\"foo.png\" />" @?= + "Hakyll is an awesome web framework " + +-- CSS compression should always decrease the text length. +prop_compress_css_length str = length str >= length (compressCSS str) + +-- Compress CSS test cases. +test_compress_css1 = compressCSS "a { \n color : red; }" @?= "a{color:red}" +test_compress_css2 = compressCSS "img {border :none;;;; }" @?= "img{border:none}" +test_compress_css3 = compressCSS "p {font-size : 90%;} h1 {color :white;;; }" @?= "p{font-size:90%}h1{color:white}" |