简体   繁体   English

如何在doctest中使用QuickCheck的多行输入?

[英]How can I use multi-line input with QuickCheck in doctest?

From Doctest's readme , one can use doctest with QuickCheck, like this: Doctest的自述文件中 ,可以使用带有QuickCheck的 doctest,如下所示:

-- |
-- prop> sort xs == (sort . sort) (xs :: [Int])

I would like to describe this property using multiple lines, probably like 我想用多行描述这个属性,可能就像

-- |
-- prop> sort xs ==
--            (sort . sort) (xs :: [Int])

Doctest itself supports multi-line input (again from readme) Doctest本身支持多行输入(同样来自自述文件)

-- |
-- >>> :{
--  let
--    x = 1
--    y = 2
--  in x + y + multiline
-- :}
-- 6

and I tried several similar syntaxes I came up with, such as 我尝试了几种类似的语法,比如

-- |
-- prop> :{ sort xs ==
--           (sort . sort) (xs :: [Int])
-- }:

without any success. 没有任何成功。 (In the example above, the error message is parse error on input '{' .) (在上面的示例中,错误消息是parse error on input '{' 。)

How can I use multi-line input with Quickcheck in doctest? 如何在doctest中使用Quickcheck进行多行输入?

As of September 2017, doctest does not allow multi-line properties . 截至2017年9月, doctest不允许多行属性 However, you can use quickCheck as usual in a doctest: 但是,您可以像往常一样在doctest中使用quickCheck

-- >>> import Test.QuickCheck
-- >>> import Data.List (sort)
-- >>> :{
--  quickCheck $ \xs -> 
--      sort xs ==
--            (sort . sort) (xs :: [Int])
-- :}
-- +++ OK, passed 100 tests.

That's verbose, but will enable you to write arbitrary long checks. 这很冗长,但可以让你编写任意长检查。 Note that you can always create a prop_* function and use that in your doctest. 请注意,您始终可以创建prop_*函数并在doctest中使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM