-- | Miscellaneous functions for manipulating string. module StringUtils ( listify, string_utils_tests ) where import Test.Tasty ( TestTree, testGroup ) import Test.Tasty.HUnit ( (@?=), testCase ) -- | Takes a list of strings and numbers it like an ordered list. -- -- Examples: -- -- >>> listify ["foo", "bar", "baz"] -- ["1. foo","2. bar","3. baz"] -- listify :: [String] -> [String] listify = zipWith (++) list_numbers where list_numbers = map show_with_dot [1::Integer ..] show_with_dot x = (show x) ++ ". " -- -- * Tests -- string_utils_tests :: TestTree string_utils_tests = testGroup "StringUtils Tests" [ test_listify ] test_listify :: TestTree test_listify = testCase description $ actual @?= expected where description = "all items are numbered correctly" actual = listify [ "item1", "item2" ] expected = ["1. item1", "2. item2" ]