From 15bcbca2279046110b78abb96be7bc9ed567906c Mon Sep 17 00:00:00 2001 From: jao Date: Sat, 27 Jun 2026 19:56:27 +0100 Subject: more unit test improvements --- test/Xmobar/Plugins/Monitors/CpuSpec.hs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'test') 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 = "(()?)" + +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: %"] 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: % "] cpuArgs <- getArguments args cpuValue <- runCpu cpuArgs - cpuValue `shouldSatisfy` ((=~ "(()?#+()?)?:*") . 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: % ", "--", "--load-icon-pattern", ""] cpuArgs <- getArguments args @@ -40,4 +46,4 @@ spec = do let args = ["-L","3","-H","50","--normal","green","--high","red", "-t", "Cpu: "] 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:( " ")+")) -- cgit v1.2.3