diff --git a/src/Mtlstats/Format.hs b/src/Mtlstats/Format.hs index 72c5565..8ccd4cc 100644 --- a/src/Mtlstats/Format.hs +++ b/src/Mtlstats/Format.hs @@ -24,6 +24,7 @@ module Mtlstats.Format , left , right , centre + , overlay , month ) where @@ -74,6 +75,17 @@ centre n str = let pad = replicate pLen ' ' in take n $ pad ++ str ++ repeat ' ' +-- | Overlays one string on top of another +overlay + :: String + -- ^ The string on the top + -> String + -- ^ The string on the bottom + -> String +overlay (x:xs) (_:ys) = x : overlay xs ys +overlay xs [] = xs +overlay [] ys = ys + -- | Converts a number to a three character month (e.g. @"JAN"@) month :: Int -> String month 1 = "JAN" diff --git a/test/FormatSpec.hs b/test/FormatSpec.hs index 1177376..bcfa781 100644 --- a/test/FormatSpec.hs +++ b/test/FormatSpec.hs @@ -31,6 +31,7 @@ spec = describe "Mtlstats.Format" $ do leftSpec rightSpec centreSpec + overlaySpec monthSpec padNumSpec :: Spec @@ -89,6 +90,17 @@ centreSpec = describe "centre" $ do it "should truncate the text" $ centre 2 "foo" `shouldBe` "fo" +overlaySpec :: Spec +overlaySpec = describe "overlay" $ do + + context "first string shorter" $ + it "should overlay" $ + overlay "foo" "abc123" `shouldBe` "foo123" + + context "first string longer" $ + it "should overlay" $ + overlay "abc123" "foo" `shouldBe` "abc123" + monthSpec :: Spec monthSpec = describe "month" $ do