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 ability to compare tuples #227

Closed
abbeycode opened this issue Dec 24, 2015 · 9 comments
Closed

Add ability to compare tuples #227

abbeycode opened this issue Dec 24, 2015 · 9 comments
Assignees

Comments

@abbeycode
Copy link
Contributor

I have test code like this:

let listOfTuples = //...
expect(listOfTuples).to(equal([
    (name: "Name", description: "Description")
]))

I get a compiler error:

Cannot invoke 'equal' with an argument list of type '([(name: String, description: String)])'

I tried removing the labels in the tuple, and I get the same error (but without the labels in the type the error prints). Is there a way to accomplish this type of matching with Nimble?

@wizzardchao
Copy link

It seems it's a swift compiler's bug to support array of tuple. I can also not append an element to an array of tuple.

@jeffh
Copy link
Member

jeffh commented Jan 7, 2016

Unfortunately, swift currently doesn't have a clean way of representing arbitrary tuples for Nimble to perform equality against. There only way is to implement it for each tuple of a given size (unlabeled).

For now, you'll have to compare each element in the tuple manually.

@abbeycode
Copy link
Contributor Author

@briancroom
Copy link
Member

That feature from that proposal is now available in the latest Xcode, however it doesn't do much to help with @abbeycode's original feature request.

Specifically, the standard library now provides additional overloads of == and the comparison operators that accept tuples as their lhs and rhs arguments, however the tuples themselves aren't made Equatable or Comparable. This means that the new functionality is not automatically made available to Nimble's matchers, and it also means that comparing arrays of tuples hasn't gotten any less painful.

let tuple = (1, 2)
tuple == tuple // This works now!
expect(tuple).to(equal(tuple)) // Error: Cannot invoke 'equal' with an argument list of type '(Int, Int)'

let tuples = [(1, 2)]
tuples == tuples // Error: Binary operator '==' cannot be applied to two '[(Int, Int)]' operands

@jonnolen
Copy link

in this case: expect(tuple == tuple2).to(beTrue()) is what I ended up falling back to. still won't handle arrays but solves the expected type issue.

phatblat pushed a commit to phatblat/Nimble that referenced this issue May 3, 2020
update CocoaPods instructions
@wearhere
Copy link

wearhere commented Jun 5, 2020

Looks like the proposal was accepted and is now being implemented 🎉 swiftlang/swift#28833

@revolter
Copy link
Contributor

It was merged but then it was reverted :(

@ikesyo
Copy link
Member

ikesyo commented May 9, 2021

Implemented equal overloads for tuples of up to 6 elements in #880.

For arrays of tuples, you can use elementsEqual instead:

expect([(1, "2"), (3, "4")]).to(elementsEqual([(1, "2"), (3, "4")], by: ==))

@ikesyo ikesyo closed this as completed May 9, 2021
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

8 participants