implemented right
This commit is contained in:
parent
60c662396f
commit
6145dd5c0c
|
@ -22,6 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
module Mtlstats.Format
|
||||
( padNum
|
||||
, left
|
||||
, right
|
||||
) where
|
||||
|
||||
-- | Pad an 'Int' with leading zeroes to fit a certain character width
|
||||
|
@ -48,3 +49,12 @@ left
|
|||
-- ^ The text to align
|
||||
-> String
|
||||
left n str = take n $ str ++ repeat ' '
|
||||
|
||||
-- | Aligns text to the right within a field (clipping if necessary)
|
||||
right
|
||||
:: Int
|
||||
-- ^ The width of the field
|
||||
-> String
|
||||
-- ^ The text to align
|
||||
-> String
|
||||
right n str = reverse $ left n $ reverse str
|
||||
|
|
|
@ -29,6 +29,7 @@ spec :: Spec
|
|||
spec = describe "Mtlstats.Format" $ do
|
||||
padNumSpec
|
||||
leftSpec
|
||||
rightSpec
|
||||
|
||||
padNumSpec :: Spec
|
||||
padNumSpec = describe "padNum" $ do
|
||||
|
@ -63,3 +64,14 @@ leftSpec = describe "left" $ do
|
|||
context "overflow" $
|
||||
it "should truncate the text" $
|
||||
left 2 "foo" `shouldBe` "fo"
|
||||
|
||||
rightSpec :: Spec
|
||||
rightSpec = describe "right" $ do
|
||||
|
||||
context "fit" $
|
||||
it "should pad the text" $
|
||||
right 5 "foo" `shouldBe` " foo"
|
||||
|
||||
context "overflow" $
|
||||
it "should truncate the text" $
|
||||
right 2 "foo" `shouldBe` "oo"
|
||||
|
|
Loading…
Reference in New Issue
Block a user