Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for FSharpList #322

Open
johanhaleby opened this issue Mar 1, 2020 · 4 comments
Open

Add support for FSharpList #322

johanhaleby opened this issue Mar 1, 2020 · 4 comments
Assignees

Comments

@johanhaleby
Copy link

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 dupdob self-assigned this Mar 1, 2020
@dupdob
Copy link
Collaborator

dupdob commented Mar 1, 2020

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

@johanhaleby
Copy link
Author

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
Copy link

pirrmann commented Mar 2, 2020

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
Copy link
Author

johanhaleby commented Mar 2, 2020

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants