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

Comparing Arrays does (sometimes) not work. Problem with Objects? #96

Open
skruppy opened this issue Sep 11, 2021 · 4 comments
Open

Comparing Arrays does (sometimes) not work. Problem with Objects? #96

skruppy opened this issue Sep 11, 2021 · 4 comments

Comments

@skruppy
Copy link

skruppy commented Sep 11, 2021

Tested with 0.14.0-alpha.7 I got the following results:

import std.stdio;
import fluent.asserts;
import std.range;
import std.algorithm;



void main() {
	writeln("Edit source/app.d to start your project.");
}


unittest {
	auto a = new Object();
	a.should.equal(a); // Works
	
	int[] i = [1, 2];
	i.should.equal(i); // Works
	i.should.containOnly(i); // Works
	
	Object[] l = [new Object(), new Object()];
	l.should.equal(l); // Works
	l.should.containOnly(l); // There is no `object.Object[].object.Object[].containOnly` or `*[].*[].containOnly` registered to the assert operations.
	
	// Taken from  #85
	auto ll = iota(1,4).map!iota;
	ll.map!array.should.equal([[0], [0,1], [0,1,2]]);       // There is no `int[][].int[][].equal` or `*[][].*[][].equal` registered to the assert operations
	ll.map!array.should.containOnly([[0], [0,1], [0,1,2]]); // There is no `int[][].int[][].containOnly` or `*[][].*[][].containOnly` registered to the assert operations.
}

This doesn't make any sense to me. I think all assertions should pass without error. The last two tests are taken from #85 and should have worked earlier, but not any more.

@gedaiu
Copy link
Owner

gedaiu commented Sep 11, 2021

Hi @skruppy,

I updated the way how the asserts work in 0.14 so this is not a cast problem, because now there are no casts. The problem comes from the fact that the assert operation is not defined for those types. I'll have a look at it.

This happens here: https://github.com/gedaiu/fluent-asserts/blob/master/source/fluentasserts/core/lifecycle.d#L31

@gedaiu
Copy link
Owner

gedaiu commented Sep 11, 2021

I just made another release which enables those operations. Please let me know how it works for you.

@skruppy
Copy link
Author

skruppy commented Sep 11, 2021

Thanks for the quick fix and release 👍 . The MWE seems to work fine with the 0.14.0-alpha.8 release. Testing with my bigger Project is currently not so easy because of #97. I will comment/close on this here issue if I worked around the other issues.

@skruppy
Copy link
Author

skruppy commented Sep 12, 2021

I tested a little bit further and I seems the examples above work, but associative arrays won't. They have worked prior version 0.14. See the following MWE (I hope this problem fits into the same bug report):

import std.stdio;
import fluent.asserts;

void main() {}

unittest {
	string[] l = ["1", "2"];
	assert(l == l); // works
	l.should.equal(l); // works
	
	string[string] al = ["k1": "v1", "k2": "v2"];
	assert(al == al); // works
	al.should.equal(al); // Fails: There is no `string[string].string[string].equal` or `*[string].*[string].equal` registered to the assert operations.
}

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

No branches or pull requests

2 participants