Closed anryoshi closed 5 years ago
Hi. LuaUnit is supposed to deal with cycles. There were several rounds of commits / review to handle this but it seems like we missed one.
I will look into your test case and how to solve it, although not immediatly. Be patient...
The last time this was discussed is in #48 and #57 .
After revisiting the topic, I believe the final implementation made an incorrect choice : table with cycles and similar structure do not compare equally. I think that they should compare equally.
Examples :
local A, B, C, D = {1}, {1}, {2}, {2}
lu.assertEquals(A, B)
lu.assertEquals(C, D)
A.ref = C
B.ref = D
lu.assertEquals(A, B)
A.self = A
B.self = B
lu.assertEquals(A, B)
local A, B, C = {}, {}, {}
A.circular = C
B.circular = A
C.circular = B
lu.assertEquals(A, B)
lu.assertEquals(C, C)
I will make the requested changes to make these example succeed in addition to the code you proposed.
Your example shall now work successfully with the latest master. I included an explicit test for it.
In example below, the assertion fails however tables have the same structure
I am not familiar with code base of luaunit and decisions that was made during the development of this project, but possibly assertEquals can be extended with approach correlated with code below. This is some kind of prototype that works but maybe it is not optimal. The idea beyound this is if two tables have the same structure and we maintain current path to subtable that currenlty compared, we can check a new table gotten as a value from current subtable on existance in this path. If this table is in the path we asume that the table in the table we compare against should have correlated table on the same position in the path, if not assert fails.