]> gitweb.michael.orlitzky.com - dead/halcyon.git/blob - src/StringUtils.hs
Clean up a bunch of code and comments.
[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
11 -- | Takes a list of strings and numbers it like an ordered list.
12 --
13 -- Examples:
14 --
15 -- >>> listify ["foo", "bar", "baz"]
16 -- ["1. foo","2. bar","3. baz"]
17 --
18 listify :: [String] -> [String]
19 listify =
20 zipWith (++) list_numbers
21 where
22 list_numbers = map show_with_dot [1::Integer ..]
23 show_with_dot x = (show x) ++ ". "
24
25
26 --
27 -- * Tests
28 --
29
30 string_utils_tests :: TestTree
31 string_utils_tests =
32 testGroup "StringUtils Tests" [ test_listify ]
33
34 test_listify :: TestTree
35 test_listify = testCase description $ actual @?= expected
36 where
37 description = "all items are numbered correctly"
38 actual = listify [ "item1", "item2" ]
39 expected = ["1. item1", "2. item2" ]