From 8aec308ae2030f8bff7bc58ec435b8a610951d0a Mon Sep 17 00:00:00 2001
From: Sibi Prabakaran <sibi@psibi.in>
Date: Sun, 14 Jun 2020 15:40:18 +0530
Subject: Cleanup and add some tests

---
 test/Xmobar/Plugins/Monitors/CpuSpec.hs | 41 +++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100644 test/Xmobar/Plugins/Monitors/CpuSpec.hs

(limited to 'test')

diff --git a/test/Xmobar/Plugins/Monitors/CpuSpec.hs b/test/Xmobar/Plugins/Monitors/CpuSpec.hs
new file mode 100644
index 0000000..449acd5
--- /dev/null
+++ b/test/Xmobar/Plugins/Monitors/CpuSpec.hs
@@ -0,0 +1,41 @@
+module Xmobar.Plugins.Monitors.CpuSpec
+  ( 
+   spec, main
+  ) where
+
+import Test.Hspec
+import Xmobar.Plugins.Monitors.Common
+import Xmobar.Plugins.Monitors.Cpu
+import Data.List
+
+main :: IO ()
+main = hspec spec
+
+spec :: Spec
+spec =
+  describe "CPU Spec" $ do
+    it "works with total template" $
+      do let args = ["-L","3","-H","50","--normal","green","--high","red", "-t", "Cpu: <total>%"]
+         cpuArgs <- getArguments args
+         cpuValue <- runCpu cpuArgs
+         cpuValue `shouldSatisfy` (\item -> "Cpu:" `isPrefixOf` item)
+    it "works with bar template" $
+      do let args = ["-L","3","-H","50","--normal","green","--high","red", "-t", "Cpu: <total>% <bar>"]
+         cpuArgs <- getArguments args
+         cpuValue <- runCpu cpuArgs
+         cpuValue `shouldSatisfy` (\item -> "::" `isSuffixOf` item)
+    it "works with no icon pattern template" $
+      do let args = ["-L","3","-H","50","--normal","green","--high","red", "-t", "Cpu: <total>% <bar>", "--", "--load-icon-pattern", "<icon=bright_%%.xpm/>"]
+         cpuArgs <- getArguments args
+         cpuValue <- runCpu cpuArgs
+         cpuValue `shouldSatisfy` (\item -> not $ "<icon=bright_" `isInfixOf` cpuValue)
+    it "works with icon pattern template" $
+      do let args = ["-L","3","-H","50","--normal","green","--high","red", "-t", "Cpu: <total>% <bar> <ipat>", "--", "--load-icon-pattern", "<icon=bright_%%.xpm/>"]
+         cpuArgs <- getArguments args
+         cpuValue <- runCpu cpuArgs
+         cpuValue `shouldSatisfy` (\item -> "<icon=bright_" `isInfixOf` cpuValue)
+    it "works with other parameters in template" $
+      do let args = ["-L","3","-H","50","--normal","green","--high","red", "-t", "Cpu: <user> <nice> <iowait>"]
+         cpuArgs <- getArguments args
+         cpuValue <- runCpu cpuArgs
+         cpuValue `shouldSatisfy` (\item -> "Cpu:" `isPrefixOf` cpuValue)
-- 
cgit v1.2.3