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