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