haf / expecto

A smooth testing lib for F#. APIs made for humans! Strong testing methodologies for everyone!
Apache License 2.0
663 stars 96 forks source link

Add helpers for nullable value types to `Expect` module #477

Closed bisen2 closed 9 months ago

bisen2 commented 9 months ago

Currently, there are helper functions in the Expect module named isNull and isNotNull for checking if a reference type is null. I think that it would be beneficial to have similar helper functions for Nullable<'t>. It is currently possible to work around this either by using Expect.isTrue x.HasValue in your test or defining the helper functions for yourself, but it seems to me like this would be a good thing to have built in.

Currently, I am defining the helper functions in my test library like so:

module Expect =
  let isNullValue (x: Nullable<'t>) message =
    if not x.HasValue then ()
    else failtestf "%s. Expected null, but was %A." message x
  let isNotNullValue (x: Nullable<'t>) message =
    if x.HasValue then ()
    else failtestf "%s. Expected non-null, but was null." message

I would be happy to PR this if it is something you would be interested in. Thanks!

farlee2121 commented 9 months ago

Seems like a decision for @haf

haf commented 9 months ago

Sounds good :) I generally don't mind adding more assert functions to the Expect module.