2

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

1 回答 1

4
test <@ actual.IsSome @>
于 2017-10-29T11:59:11.833 回答