-
Notifications
You must be signed in to change notification settings - Fork 214
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
Incorrectly rejects identical structure when encountering circularity #113
Comments
I've left this issue here for about a year. Seems like a theoretical question... here's why I say that: const { log, inspect } = require('util');
const assert = require('assert');
const diff = require('../');
const o1 = {};
const o2 = {};
o1.foo = o1;
o2.foo = o2;
assert.notEqual(o1, o2, 'not same object');
assert.notEqual(o1.foo, o2.foo, 'not same object');
const differences = diff(o1, o2);
log(inspect(differences, false, 9)); Produces:
Seems correct to me. I suppose the README
may be the counter argument, after all, the structures are similar. I'm inclined to close this. |
The use case I would have for diff, absent this bug, is testing serialisation / deserialisation round-tripping or other deep-copy routines. My test code consists of creating various datastructures, serialising and then deserialising them, and then diffing the deserialised result against the original input. The data I am serialising is arbitrary JavaScript data, so the serialisation routines need to handle cyclic data—and therefore the tests must too. Having already had to write my own diff routines for the golang version of this code, I will observe that the algorithm is actually pretty easy:
(Object prototypes, set members, and map keys and values ought to be treated just like properties: i.e., recursed upon and with the same two-way map tests. WeakMaps and WeakSets present some difficulty, though there are other possible workarounds if we can constrain the set of possible keys.) |
Thanks for the feedback. Now I'm inclined to fix it. |
Any update on this? Thanks! |
In this case there is no difference between o1 and o2, but diff incorrectly reports that there is:
By comparison, in this case there is actually a structural difference (which is correctly detected, albeit with less than entirely illuminating output):
The text was updated successfully, but these errors were encountered: