summaryrefslogtreecommitdiffhomepage
path: root/test/Xmobar/Plugins/Monitors/CpuSpec.hs
blob: 614ca62c7b411f9ab7b9555ce700b28d35544544 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
module Xmobar.Plugins.Monitors.CpuSpec
  ( 
   spec, main
  ) where

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

import Data.List
import Text.Regex.TDFA((=~))

main :: IO ()
main = hspec spec

withFc :: String -> String
withFc s = "((<fc=(green|red))?" ++ s ++ "(<fc/>)?)"

fcDigits :: String -> String -> String
fcDigits prefix suffix = prefix ++ withFc "([0-9][0-9]?|-0)" ++ suffix -- in CI computers, -0 is a value

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` (=~ (fcDigits "Cpu: " "%"))
    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` ((=~ (withFc "#+" ++ "?:*")) . last . words)
    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` (=~ (fcDigits "Cpu:( " ")+"))