Search code examples
f#pattern-matchingxunitfsunit

Unit testing: '[] |> should equal List.empty' is not working as expected


I have the following code with a test that fails:

open Xunit
open FsUnit.Xunit

let rec openOrSenior xs = 
    match xs with
    | head :: tail when fst head >= 55 && snd head >= 7 -> "Senior" :: openOrSenior tail
    | head :: tail -> "Open" :: openOrSenior tail
    | [] -> []

[<Fact>]
let ``empty input gives empty result``() =
    openOrSenior [] |> should equal List.empty

The test fails with the following matching error

FsUnit.Xunit+MatchException : Exception of type 'FsUnit.Xunit+MatchException' was thrown. Expected: Equals []
Actual: was []


Solution

  • equal in FsUnit does some fancy match were be is just identity function. Here is the link source

    Your check will be fine if you use:

    |> should be Empty