Add field step tests
This commit is contained in:
parent
ac5a5078f3
commit
cd33a99b84
@ -71,3 +71,8 @@ parseSequence text constraint
|
|||||||
numbers = map read pieces
|
numbers = map read pieces
|
||||||
allInRange = all (\x -> x `inRange` constraint) numbers
|
allInRange = all (\x -> x `inRange` constraint) numbers
|
||||||
isValid = length pieces >= 2 && isAllNumbers && allInRange
|
isValid = length pieces >= 2 && isAllNumbers && allInRange
|
||||||
|
|
||||||
|
parseFieldStep :: String -> Maybe Step
|
||||||
|
parseFieldStep "" = Just Every
|
||||||
|
parseFieldStep text | isNumber text = Just (Step (read text))
|
||||||
|
parseFieldStep _ = Nothing
|
||||||
|
@ -19,6 +19,8 @@ spec = do
|
|||||||
it "fails constraints" $
|
it "fails constraints" $
|
||||||
parseNumber "10" (Constraint 0 5) `shouldBe` Nothing
|
parseNumber "10" (Constraint 0 5) `shouldBe` Nothing
|
||||||
|
|
||||||
|
-- Field validation
|
||||||
|
|
||||||
describe "Field can be created from" $ do
|
describe "Field can be created from" $ do
|
||||||
it "asterisk" $
|
it "asterisk" $
|
||||||
parseField "*" (Constraint 0 0) `shouldBe` Just (Field All Every)
|
parseField "*" (Constraint 0 0) `shouldBe` Just (Field All Every)
|
||||||
@ -31,3 +33,16 @@ spec = do
|
|||||||
|
|
||||||
it "sequence" $
|
it "sequence" $
|
||||||
parseField "1,2,3" (Constraint 0 59) `shouldBe` Just (Field (Sequence [1, 2, 3]) Every)
|
parseField "1,2,3" (Constraint 0 59) `shouldBe` Just (Field (Sequence [1, 2, 3]) Every)
|
||||||
|
|
||||||
|
-- Field Step validation
|
||||||
|
|
||||||
|
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
|
||||||
|
it "word" $
|
||||||
|
parseFieldStep "hello" `shouldBe` Nothing
|
||||||
|
Loading…
Reference in New Issue
Block a user