Add field step tests

This commit is contained in:
Anton Vakhrushev 2017-11-12 07:35:36 +03:00
parent ac5a5078f3
commit cd33a99b84
2 changed files with 20 additions and 0 deletions

View File

@ -71,3 +71,8 @@ parseSequence text constraint
numbers = map read pieces
allInRange = all (\x -> x `inRange` constraint) numbers
isValid = length pieces >= 2 && isAllNumbers && allInRange
parseFieldStep :: String -> Maybe Step
parseFieldStep "" = Just Every
parseFieldStep text | isNumber text = Just (Step (read text))
parseFieldStep _ = Nothing

View File

@ -19,6 +19,8 @@ spec = do
it "fails constraints" $
parseNumber "10" (Constraint 0 5) `shouldBe` Nothing
-- Field validation
describe "Field can be created from" $ do
it "asterisk" $
parseField "*" (Constraint 0 0) `shouldBe` Just (Field All Every)
@ -31,3 +33,16 @@ spec = do
it "sequence" $
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