Swap arguments
This commit is contained in:
parent
44dd3aad0a
commit
8199c1bd57
14
src/Lib.hs
14
src/Lib.hs
@ -1,5 +1,5 @@
|
||||
module Lib
|
||||
( check
|
||||
( match
|
||||
) where
|
||||
|
||||
import Data.Bool
|
||||
@ -13,8 +13,8 @@ data CronItemPattern = CronItemPattern Range Step
|
||||
|
||||
data CronPattern = CronPattern [CronItemPattern]
|
||||
|
||||
check :: DateTime -> String -> Bool
|
||||
check d s = checkPattern d (parseCronPattern s)
|
||||
match :: String -> DateTime -> Bool
|
||||
match s d = matchPattern (parseCronPattern s) d
|
||||
|
||||
parseCronPattern :: String -> CronPattern
|
||||
parseCronPattern s = CronPattern $ map parseCronItemPattern $ words s
|
||||
@ -22,8 +22,8 @@ parseCronPattern s = CronPattern $ map parseCronItemPattern $ words s
|
||||
parseCronItemPattern :: String -> CronItemPattern
|
||||
parseCronItemPattern "*" = CronItemPattern Any All
|
||||
|
||||
checkPattern :: DateTime -> CronPattern -> Bool
|
||||
checkPattern d (CronPattern (x:xs)) = checkItemPattern (year d) x
|
||||
matchPattern :: CronPattern -> DateTime -> Bool
|
||||
matchPattern (CronPattern (x:xs)) d = matchItemPattern x (year d)
|
||||
|
||||
checkItemPattern :: Int -> CronItemPattern -> Bool
|
||||
checkItemPattern n (CronItemPattern Any All) = True
|
||||
matchItemPattern :: CronItemPattern -> Int -> Bool
|
||||
matchItemPattern (CronItemPattern Any All) _ = True
|
@ -3,11 +3,11 @@ import Test.QuickCheck
|
||||
import Control.Exception (evaluate)
|
||||
import Data.Dates
|
||||
|
||||
import Lib (check)
|
||||
import Lib (match)
|
||||
|
||||
main :: IO ()
|
||||
main = hspec $ do
|
||||
describe "Cron ckecker" $ do
|
||||
it "matches asterisks" $ do
|
||||
check (DateTime 2017 10 11 0 0 0) "* * * * *" `shouldBe` (True :: Bool)
|
||||
match "* * * * *" (DateTime 2017 10 11 0 0 0) `shouldBe` (True :: Bool)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user