Fix formatting and errors
This commit is contained in:
@ -12,7 +12,5 @@ main = hspec spec
|
||||
spec :: Spec
|
||||
spec =
|
||||
describe "Constraint" $ do
|
||||
it "can be created from number" $
|
||||
makeRangeFromNumber 10 `shouldBe` Constraint 10 10
|
||||
it "validate number" $ 10 `inRange` Constraint 0 10 `shouldBe` True
|
||||
it "validate number" $ 10 `inRange` Constraint 15 20 `shouldBe` False
|
||||
|
@ -34,23 +34,23 @@ spec = do
|
||||
describe "Step can be created from" $ do
|
||||
it "empty string" $ parseFieldStep "" `shouldBe` Just Every
|
||||
it "number" $ parseFieldStep "5" `shouldBe` Just (Step 5)
|
||||
describe "Step cant'b created from" $ do
|
||||
describe "Step cant'b created from" $
|
||||
it "word" $ parseFieldStep "hello" `shouldBe` Nothing
|
||||
-- Field validation
|
||||
describe "Field can be created from" $ do
|
||||
it "asterisk" $
|
||||
parseField "*" (Constraint 0 59) `shouldBe` Just (Field All Every)
|
||||
it "asterisk with step" $ do
|
||||
it "asterisk with step" $
|
||||
parseField "*/5" (Constraint 0 59) `shouldBe` Just (Field All (Step 5))
|
||||
it "number with step" $ do
|
||||
it "number with step" $
|
||||
parseField "10/5" (Constraint 0 59) `shouldBe`
|
||||
Just (Field (Range 10 10) (Step 5))
|
||||
it "range with step" $ do
|
||||
Just (Field (Range 10 10) (Step 5))
|
||||
it "range with step" $
|
||||
parseField "0-59/5" (Constraint 0 59) `shouldBe`
|
||||
Just (Field (Range 0 59) (Step 5))
|
||||
it "sequence with step" $ do
|
||||
Just (Field (Range 0 59) (Step 5))
|
||||
it "sequence with step" $
|
||||
parseField "1,3,4/5" (Constraint 0 59) `shouldBe`
|
||||
Just (Field (Sequence [1, 3, 4]) (Step 5))
|
||||
Just (Field (Sequence [1, 3, 4]) (Step 5))
|
||||
-- Field match
|
||||
describe "Field can match" $ do
|
||||
it "number" $ count (Field All Every) [0 .. 59] `shouldBe` 60
|
||||
|
@ -4,6 +4,7 @@ module PatternSpec
|
||||
) where
|
||||
|
||||
import Data.Dates
|
||||
import Data.Maybe
|
||||
import Pattern
|
||||
import Test.Hspec
|
||||
|
||||
@ -11,13 +12,13 @@ main :: IO ()
|
||||
main = hspec spec
|
||||
|
||||
spec :: Spec
|
||||
spec = do
|
||||
spec =
|
||||
describe "Cron pattern" $ do
|
||||
it "createParts" $ length (createParts "* * * * * *") `shouldBe` 6
|
||||
it "createFields" $ length (createFields "* * * * * *") `shouldBe` 6
|
||||
it "matches fixed time" $
|
||||
let ptn = "* * * * * *"
|
||||
date = DateTime 2017 10 11 0 0 0
|
||||
in match ptn date `shouldBe` True
|
||||
in match ptn date `shouldBe` Just True
|
||||
it "matches all minutes" $
|
||||
let ptn = "* * * * * *"
|
||||
dates = [DateTime 2017 10 11 0 i 0 | i <- [0 .. 59]]
|
||||
@ -25,12 +26,16 @@ spec = do
|
||||
it "matches exactly moment" $
|
||||
let date = DateTime 2017 10 11 0 0 0
|
||||
ptn = "0 0 11 10 * 2017"
|
||||
in match ptn date `shouldBe` True
|
||||
in match ptn date `shouldBe` Just True
|
||||
it "matches moment" $
|
||||
let date = DateTime 2017 10 10 12 10 0
|
||||
ptn = "* 12 * * * *"
|
||||
in match ptn date `shouldBe` Just True
|
||||
|
||||
countMatches :: String -> [DateTime] -> Int
|
||||
countMatches p xs = sum $ map (f p) xs
|
||||
where
|
||||
f x d =
|
||||
if match x d
|
||||
if isJust $ match x d
|
||||
then 1
|
||||
else 0
|
||||
|
Reference in New Issue
Block a user