summaryrefslogtreecommitdiffhomepage
path: root/test/Xmobar/Plugins/Monitors/CommonSpec.hs
blob: 578b1a5c493301b6f755b53a077d430f19f744a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module Xmobar.Plugins.Monitors.CommonSpec
  ( main
  , spec
  ) where

import Test.Hspec
import Xmobar.Plugins.Monitors.Common

main :: IO ()
main = hspec spec

spec :: Spec
spec =
  describe "Common.padString" $ do
    it "returns given string when called with default values" $
      padString 0 0 "" False "" "test" `shouldBe` "test"

    it "truncates to max width" $ do
      let maxw = 3
          givenStr = "mylongstr"
          expectedStr = take maxw givenStr
      padString 0 maxw "" False "" givenStr `shouldBe` expectedStr

    it "truncates to max width and concatenate with ellipsis" $ do
      let maxw = 3
          givenStr = "mylongstr"
          ellipsis = "..."
          expectedStr = (++ ellipsis) . take 3 $ givenStr
      padString 0 maxw "" False ellipsis givenStr `shouldBe` expectedStr

    it "does not pad empty strings" $ do
      let padChars = " "
          givenStr = ""
          expectedStr = ""
      padString 0 0 padChars False "" givenStr `shouldBe` expectedStr