我有一个程序,它接受用户输入,getLine
然后验证它是所有数字。如果它通过了,它会运行一个函数String -> String
并将结果打印到屏幕上。如果不是,它会重复getLine
.
module Main where
import Control.Monad.Loops (untilJust)
import Data.Char (isDigit)
main = do
let validateInput s = if all isDigit s then Just s else Nothing
putStrLn =<< myFunc <$> untilJust (validateInput <$> (putStr "Number : " >> getLine))
myFunc = id -- to do
我如何测试这个主要功能,比如Hspec
检查它是否使用数字输入与其他输入(字母、空等)做正确的事情
IE
test1 rejects a non-numeric input of "abc"
test2 returns 123 as 123