[英]F# test if the result is Some(any)
I need to check whether my validation function returns some
thing when fails or none
. 我需要检查我的验证功能是否会返回some
失败或当事情none
。 If it returns Some<string>
, there is a validation error, otherwise it's valid and the function returns None
. 如果返回Some<string>
,则表示验证错误,否则有效,函数返回None
。 This is my attempt , but it's not refactoring safe: 这是我的尝试,但它并不安全:
[<Property(Arbitrary=[| typeof<Strings.WithLenFrom1To100> |])>]
let ``lengthValidator should return some error when the string's length is longer than expected``(str:string)=
let maxValidLen = str.Length-1
let actual = lengthValidator maxValidLen str
let expected = Some(sprintf "Maximum string length is %i but %s contains %i characters" maxValidLen str str.Length)
//How can I say **let expected = Some(anything) **instead
test <@actual = expected@>
test <@ actual.IsSome @>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.