on master help sign in
Added some tests.
commit4fa472250e9041f95dc21adefcfd70cfefd09bc2 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateFri 25 Dec 2009, 11:55 (17 years ago) parentce2cef4
2 files changed+54
src/Text/Hakyll/CompressCSS.hs+1 tests/Tests.hs+53
src/Text/Hakyll/CompressCSS.hs+1
@@ -19,6 +19,7 @@ compressCSS = compressSeparators
1919compressSeparators :: String -> String
2020compressSeparators = subRegex' ";\\s*}" "}"
2121 . subRegex' "\\s*([{};:])\\s*" "\\1"
22+ . subRegex' ";;*" ";"
2223
2324-- | Compresses all whitespace.
2425compressWhitespace :: String -> String
tests/Tests.hsnew file+53
@@ -0,0 +1,53 @@
1+import Test.Framework (defaultMain, testGroup)
2+import Test.Framework.Providers.QuickCheck2
3+import Test.Framework.Providers.HUnit
4+import Test.QuickCheck
5+import Test.HUnit
6+
7+import Data.Char
8+
9+import Text.Hakyll.CompressCSS
10+import Text.Hakyll.Util
11+
12+main = defaultMain tests
13+
14+tests = [ testGroup "Util group" [ testProperty "trim length" prop_trim_length
15+ , testProperty "trim id" prop_trim_id
16+ , testProperty "trim empty" prop_trim_empty
17+ , testCase "stripHTML 1" test_strip_html1
18+ , testCase "stripHTML 2" test_strip_html2
19+ , testCase "stripHTML 3" test_strip_html3
20+ ]
21+
22+ , testGroup "CompressCSS group" [ testProperty "compressCSS length" prop_compress_css_length
23+ , testCase "compressCSS 1" test_compress_css1
24+ , testCase "compressCSS 2" test_compress_css2
25+ , testCase "compressCSS 3" test_compress_css3
26+ ]
27+ ]
28+
29+-- Test that a string always becomes shorter when trimmed.
30+prop_trim_length str = length str >= length (trim str)
31+
32+-- Check that a string which does not start or end with a space is not trimmed.
33+prop_trim_id str = (not $ null str)
34+ && (not $ isSpace $ head str)
35+ && (not $ isSpace $ last str)
36+ ==> str == (trim str)
37+
38+-- An string of only spaces should be reduced to an empty string.
39+prop_trim_empty str = (all isSpace str) ==> null (trim str)
40+
41+-- Strip HTML test cases.
42+test_strip_html1 = stripHTML "<b>text</b>" @?= "text"
43+test_strip_html2 = stripHTML "text" @?= "text"
44+test_strip_html3 = stripHTML "<b>Hakyll</b> is an <i>awesome</i> web framework <img src=\"foo.png\" />" @?=
45+ "Hakyll is an awesome web framework "
46+
47+-- CSS compression should always decrease the text length.
48+prop_compress_css_length str = length str >= length (compressCSS str)
49+
50+-- Compress CSS test cases.
51+test_compress_css1 = compressCSS "a { \n color : red; }" @?= "a{color:red}"
52+test_compress_css2 = compressCSS "img {border :none;;;; }" @?= "img{border:none}"
53+test_compress_css3 = compressCSS "p {font-size : 90%;} h1 {color :white;;; }" @?= "p{font-size:90%}h1{color:white}"