X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Fhalcyon.git;a=blobdiff_plain;f=src%2FStringUtils.hs;h=55939680467bb314f24aae53e70485e693c6055d;hp=b7d291c229acdc96f777f8b60078fbd991d3c0cd;hb=4cc476a2714260980899ca5358196bbf5226b3c2;hpb=e13f2a1eced5f388b37bc0ed12e9db72eba4b5d4 diff --git a/src/StringUtils.hs b/src/StringUtils.hs index b7d291c..5593968 100644 --- a/src/StringUtils.hs +++ b/src/StringUtils.hs @@ -1,31 +1,41 @@ --- |Miscellaneous functions for manipulating string. +-- | Miscellaneous functions for manipulating string. module StringUtils where -import Test.HUnit +import Test.Framework (Test, testGroup) +import Test.Framework.Providers.HUnit (testCase) +import Test.HUnit (Assertion, assertEqual) --- |Takes a list of strings, call them string1, string2, etc. and --- numbers them like a list. So, --- 1. string1 --- 2. string2 --- 3. etc. +-- | 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 +listify = + zipWith (++) list_numbers where list_numbers = map show_with_dot [1::Integer ..] show_with_dot x = (show x) ++ ". " +-- +-- Tests +-- -string_utils_tests :: [Test] -string_utils_tests = [ test_listify ] - - -test_listify :: Test +test_listify :: Assertion 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" ] + assertEqual description expected_items actual_items + where + description = "All items are numbered correctly." + actual_items = listify [ "item1", "item2" ] + expected_items = ["1. item1", "2. item2" ] + +string_utils_tests :: Test +string_utils_tests = + testGroup "StringUtils Tests" [ tc1 ] + where + tc1 = testCase "All items are numbered correctly." test_listify