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 = "(()?)" 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: %"] 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: % "] 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: % ", "--", "--load-icon-pattern", ""] cpuArgs <- getArguments args cpuValue <- runCpu cpuArgs cpuValue `shouldSatisfy` (\item -> not $ "% ", "--", "--load-icon-pattern", ""] cpuArgs <- getArguments args cpuValue <- runCpu cpuArgs cpuValue `shouldSatisfy` (\item -> " "] cpuArgs <- getArguments args cpuValue <- runCpu cpuArgs cpuValue `shouldSatisfy` (=~ (fcDigits "Cpu:( " ")+"))