]> gitweb.michael.orlitzky.com - dead/halcyon.git/blob - src/StringUtils.hs
Clean up imports.
[dead/halcyon.git] / src / StringUtils.hs
1 -- | Miscellaneous functions for manipulating string.
2 module StringUtils (
3 listify,
4 string_utils_tests )
5 where
6
7 import Test.Framework ( Test, testGroup )
8 import Test.Framework.Providers.HUnit ( testCase )
9 import Test.HUnit ( Assertion, assertEqual )
10
11
12 -- | Takes a list of strings, call them string1, string2, etc. and
13 -- numbers them like a list. So,
14 --
15 -- 1. string1
16 -- 2. string2
17 -- 3. etc.
18 --
19 listify :: [String] -> [String]
20 listify =
21 zipWith (++) list_numbers
22 where
23 list_numbers = map show_with_dot [1::Integer ..]
24 show_with_dot x = (show x) ++ ". "
25
26
27 --
28 -- Tests
29 --
30
31 test_listify :: Assertion
32 test_listify =
33 assertEqual description expected_items actual_items
34 where
35 description = "All items are numbered correctly."
36 actual_items = listify [ "item1", "item2" ]
37 expected_items = ["1. item1", "2. item2" ]
38
39 string_utils_tests :: Test
40 string_utils_tests =
41 testGroup "StringUtils Tests" [ tc1 ]
42 where
43 tc1 = testCase "All items are numbered correctly." test_listify