我需要检查我的验证函数是否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@>