我需要检查我的验证函数在失败或some
时是否返回none
。如果它返回Some<string>
,则存在验证错误,否则它是有效的,函数返回None
。
这是我的尝试,但它不是重构安全:
[<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@>
答案 0 :(得分:4)
test <@ actual.IsSome @>