File: Strtest.hs

package info (click to toggle)
missingh 1.6.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 688 kB
  • sloc: haskell: 5,472; makefile: 2
file content (71 lines) | stat: -rw-r--r-- 2,195 bytes parent folder | download
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
                  ]