]> gitweb.michael.orlitzky.com - dead/halcyon.git/blobdiff - src/StringUtils.hs
Add referenced users' timeline URLs to the bottom of each message.
[dead/halcyon.git] / src / StringUtils.hs
diff --git a/src/StringUtils.hs b/src/StringUtils.hs
new file mode 100644 (file)
index 0000000..b7d291c
--- /dev/null
@@ -0,0 +1,31 @@
+-- |Miscellaneous functions for manipulating string.
+module StringUtils
+where
+
+import Test.HUnit
+
+
+-- |Takes a list of strings, call them string1, string2, etc. and
+-- numbers them like a list. So,
+-- 1. string1
+-- 2. string2
+-- 3. etc.
+listify :: [String] -> [String]
+listify items =
+    zipWith (++) list_numbers items
+    where
+      list_numbers = map show_with_dot [1::Integer ..]
+      show_with_dot x = (show x) ++ ". "
+
+
+
+string_utils_tests :: [Test]
+string_utils_tests = [ test_listify ]
+
+
+test_listify :: Test
+test_listify =
+    TestCase $ assertEqual "All items are numbered correctly." expected_items actual_items
+    where
+      actual_items = listify [ "item1", "item2" ]
+      expected_items = ["1. item1", "2. item2" ]