diff options
| -rw-r--r-- | test/Xmobar/Plugins/Monitors/CpuSpec.hs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/test/Xmobar/Plugins/Monitors/CpuSpec.hs b/test/Xmobar/Plugins/Monitors/CpuSpec.hs index f7e7f97..614ca62 100644 --- a/test/Xmobar/Plugins/Monitors/CpuSpec.hs +++ b/test/Xmobar/Plugins/Monitors/CpuSpec.hs @@ -13,6 +13,12 @@ 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 @@ -20,12 +26,12 @@ spec = do let args = ["-L","3","-H","50","--normal","green","--high","red", "-t", "Cpu: <total>%"] cpuArgs <- getArguments args cpuValue <- runCpu cpuArgs - cpuValue `shouldSatisfy` (=~ "Cpu: [0-9]+%") + 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` ((=~ "((<fc=(green|red)>)?#+(</fc>)?)?:*") . last . words) + 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 @@ -40,4 +46,4 @@ spec = do let args = ["-L","3","-H","50","--normal","green","--high","red", "-t", "Cpu: <user> <nice> <iowait>"] cpuArgs <- getArguments args cpuValue <- runCpu cpuArgs - cpuValue `shouldSatisfy` (=~ "Cpu: [0-9][0-9]? [0-9][0-9]? [0-9][0-9]?") + cpuValue `shouldSatisfy` (=~ (fcDigits "Cpu:( " ")+")) |
