tpierrain / NFluent

Smooth your .NET TDD experience with NFluent! NFluent is an ergonomic assertion library which aims to fluent your .NET TDD experience (based on simple Check.That() assertion statements). NFluent aims your tests to be fluent to write (with a super-duper-happy 'dot' auto-completion experience), fluent to read (i.e. as close as possible to plain English expression), but also fluent to troubleshoot, in a less-error-prone way comparing to the classical .NET test frameworks. NFluent is also directly inspired by the awesome Java FEST Fluent assertion/reflection library (http://fest.easytesting.org/)
Apache License 2.0
310 stars 53 forks source link

Add support for FSharpList #322

Open johanhaleby opened 4 years ago

johanhaleby commented 4 years ago

It would be great if NFluent would add support for asserting elements in an FSharpList the same way you can do on a Seq or List. I.e. allow this:

let myList : int list = [1;2;3]
Check.That(events).Contains(1, 2, 3)
dupdob commented 4 years ago

Thanks for opening the first F# issue we ever had. This gives me the opportunity to start having a F# test projects.

johanhaleby commented 4 years ago

Thanks for opening the first F# issue we ever had.

@dupdob Oh wow :) I just started playing around with F# two days ago (as my first CLR language). I'm from a JVM background and I've been using assertj heavily for many years and I was glad to find this lib.

pirrmann commented 4 years ago

Hello! Although I love NFluent and would very highly recommend its usage on C# projects, I'm not certain this is the best fit for F# projects. The reason I'm saying this is because NFluent heavily relies on extension methods, type inference et implicit casts, in the way they work in C#. In F#, you code will work if you do the following:

let myList: int list = [1;2;3]
Check.That(events :> System.Collections.IEnumerable).Contains(1, 2, 3)

It's not the lack of support in NFluent here, it's that F# will not implicitely cast from FSharpList to IEnumerable. The same test, written in C#, even when testing the content of an FSharpList, would work out of the box.

johanhaleby commented 4 years ago

@pirrmann Interesting point.

But for me at least, I think that it would be ok to add a small wrapper for F#. For example in the case of FSharpList I think it would be almost enough for NFluent provide a function that transforms the FSharpList into an IEnumerable or "sequence" (sorry for not being fluent in dotnet parlance yet).

I.e. the problem I have today is that this doesn't work:

let myList : int list = [1;2;3]
Check.That(events).Contains(1, 2, 3)

But if I simply change the code to this it works (or if I cast it to IEnumerable that you imply) :

let myList : int seq = [1;2;3] |> Seq.ofList
Check.That(events).Contains(1, 2, 3)

If NFluent would provide a Contains method that does this simple transformation it would be (almost) enough for me. The reason I say "almost" is that the HasSize method is unavailable for sequences.

WDYT?