1

我有一个程序,它接受用户输入,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
4

1 回答 1

2

由于您想测试逻辑而不是用户交互,我建议您简单地排除输入验证。

于 2017-07-29T03:11:10.800 回答