diff options
| author | jao <jao@gnu.org> | 2026-06-27 20:09:59 +0100 |
|---|---|---|
| committer | jao <jao@gnu.org> | 2026-06-27 20:30:31 +0100 |
| commit | 358d485779b322339002a744c9ff5f914b534579 (patch) | |
| tree | 771100512a5d07e5ba4d93594cf3c67de5b73b52 /test/Xmobar | |
| parent | 15bcbca2279046110b78abb96be7bc9ed567906c (diff) | |
| download | xmobar-358d485779b322339002a744c9ff5f914b534579.tar.gz xmobar-358d485779b322339002a744c9ff5f914b534579.tar.bz2 | |
wee refactorings
Diffstat (limited to 'test/Xmobar')
| -rw-r--r-- | test/Xmobar/Plugins/Monitors/CpuSpec.hs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/test/Xmobar/Plugins/Monitors/CpuSpec.hs b/test/Xmobar/Plugins/Monitors/CpuSpec.hs index 614ca62..b415179 100644 --- a/test/Xmobar/Plugins/Monitors/CpuSpec.hs +++ b/test/Xmobar/Plugins/Monitors/CpuSpec.hs @@ -14,19 +14,25 @@ main :: IO () main = hspec spec withFc :: String -> String -withFc s = "((<fc=(green|red))?" ++ s ++ "(<fc/>)?)" +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 +withFcDigits :: String -> String -> String +withFcDigits prefix suffix = prefix ++ digits ++ suffix + where digits = withFc "([0-9][0-9]?|-0)" -- in CI computers, -0 is a value spec :: Spec spec = describe "CPU Spec" $ do + it "uses the correct regexps" $ + do "Cpu: -0%" `shouldSatisfy` (=~ withFcDigits "Cpu: " "%") + "Cpu: 12" `shouldSatisfy` (=~ withFcDigits "Cpu: " "") + "Cpu: <fc=red>12</fc>" `shouldSatisfy` (=~ withFcDigits "Cpu: " "") + "Cpu: <fc=green>12</fc> -0" `shouldSatisfy` (=~ withFcDigits "Cpu: (" ")+") 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: " "%")) + cpuValue `shouldSatisfy` (=~ withFcDigits "Cpu: " "%") it "works with bar template" $ do let args = ["-L","3","-H","50","--normal","green","--high","red", "-t", "Cpu: <total>% <bar>"] cpuArgs <- getArguments args @@ -46,4 +52,5 @@ 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` (=~ (fcDigits "Cpu:( " ")+")) + cpuValue `shouldSatisfy` (=~ withFcDigits "Cpu:( " ")+") + |
