diff options
Diffstat (limited to 'test/Xmobar')
| -rw-r--r-- | test/Xmobar/Plugins/Monitors/CpuSpec.hs | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/test/Xmobar/Plugins/Monitors/CpuSpec.hs b/test/Xmobar/Plugins/Monitors/CpuSpec.hs index 3d07dee..b415179 100644 --- a/test/Xmobar/Plugins/Monitors/CpuSpec.hs +++ b/test/Xmobar/Plugins/Monitors/CpuSpec.hs @@ -6,24 +6,38 @@ module Xmobar.Plugins.Monitors.CpuSpec 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>)?)" + +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` (\item -> "Cpu:" `isPrefixOf` item) + 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 cpuValue <- runCpu cpuArgs - cpuValue `shouldSatisfy` (all (`elem` ":#") . 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 @@ -38,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` (\item -> "Cpu:" `isPrefixOf` cpuValue) + cpuValue `shouldSatisfy` (=~ withFcDigits "Cpu:( " ")+") + |
