From ae37e13986b45150f69d7cfa2555cf6b22ccc3c9 Mon Sep 17 00:00:00 2001 From: Olivier Schneider Date: Sat, 3 Mar 2018 15:50:02 +0100 Subject: Add ellipsis option for Monitor's fields and total text --- test/Plugins/Monitors/CommonSpec.hs | 29 +++++++++++++++++++++++++++++ test/Spec.hs | 1 + 2 files changed, 30 insertions(+) create mode 100644 test/Plugins/Monitors/CommonSpec.hs create mode 100644 test/Spec.hs (limited to 'test') diff --git a/test/Plugins/Monitors/CommonSpec.hs b/test/Plugins/Monitors/CommonSpec.hs new file mode 100644 index 0000000..847368c --- /dev/null +++ b/test/Plugins/Monitors/CommonSpec.hs @@ -0,0 +1,29 @@ +module Plugins.Monitors.CommonSpec + ( main + , spec + ) where + +import Test.Hspec +import Plugins.Monitors.Common + +main :: IO () +main = hspec spec + +spec :: Spec +spec = + describe "Common.padString" $ do + it "returns given string when called with default values" $ + do 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 diff --git a/test/Spec.hs b/test/Spec.hs new file mode 100644 index 0000000..52ef578 --- /dev/null +++ b/test/Spec.hs @@ -0,0 +1 @@ +{-# OPTIONS_GHC -F -pgmF hspec-discover #-} \ No newline at end of file -- cgit v1.2.3