a9e2625289c65be857d068f35a850e32009369ae
[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.Tasty ( TestTree, testGroup )
8 import Test.Tasty.HUnit ( (@?=), testCase )
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 string_utils_tests :: TestTree
30 string_utils_tests =
31 testGroup "StringUtils Tests" [ test_listify ]
32
33 test_listify :: TestTree
34 test_listify = testCase description $ actual @?= expected
35 where
36 description = "all items are numbered correctly"
37 actual = listify [ "item1", "item2" ]
38 expected = ["1. item1", "2. item2" ]