1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
{- arch-tag: Str tests main file
Copyright (C) 2004-2011 John Goerzen <jgoerzen@complete.org>
All rights reserved.
For license and copyright information, see the file LICENSE
-}
module Strtest(tests) where
import Test.HUnit
import Data.String.Utils
import TestUtils
import Text.Regex
import Data.Char
test_lstrip =
mapassertEqual "lstrip" lstrip
[("", ""),
("a", "a"),
(" a ", "a "),
(" abas", "abas"),
("\n\t fdsa", "fdsa"),
("abc def", "abc def")]
test_rstrip =
mapassertEqual "rstrip" rstrip
[("", ""),
("a", "a"),
(" a ", " a"),
("abas ", "abas"),
("fdsa \n\t", "fdsa"),
("abc def", "abc def")]
test_strip =
mapassertEqual "strip" strip
[("", ""),
("a", "a"),
(" a ", "a"),
("abas ", "abas"),
(" abas", "abas"),
("asdf\n\t ", "asdf"),
("\nbas", "bas"),
("abc def", "abc def")]
test_splitWs =
let f exp inp = TestCase $ exp @=? splitWs inp
in [
f [] " ",
f [] "",
f ["asdf"] " asdf\n",
f ["one", "two", "three"] " one\ntwo \tthree \n"
]
test_escapeRe =
map (\i -> TestLabel (show $ chr i) $ TestCase $ assertEqual [chr i] (Just [])
(matchRegex (mkRegex $ escapeRe $ [chr i]) [chr i]))
[1..127]
++
[TestCase $ assertEqual "big string"
(Just ([], teststr, [], []))
(matchRegexAll (mkRegex $ escapeRe teststr) teststr)
]
where teststr = map chr [1..127]
tests = TestList [TestLabel "lstrip" (TestList test_lstrip),
TestLabel "rstrip" $ TestList test_rstrip,
TestLabel "strip" $ TestList test_strip,
TestLabel "splitWs" $ TestList test_splitWs,
TestLabel "escapeRe" $ TestList test_escapeRe
]
|