diff --git a/src/Lib.hs b/src/Lib.hs index a638186..074199f 100644 --- a/src/Lib.hs +++ b/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 \ No newline at end of file +matchItemPattern :: CronItemPattern -> Int -> Bool +matchItemPattern (CronItemPattern Any All) _ = True \ No newline at end of file diff --git a/test/Spec.hs b/test/Spec.hs index 8980b9e..6acac8f 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -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)