Merge pull request #819 from joelspadin/equals-fix

web binding: fix equals()
This commit is contained in:
Max Brunsfeld 2020-11-26 15:39:07 -08:00 committed by GitHub
commit 53949b09fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 5 deletions

View file

@ -258,11 +258,7 @@ class Node {
}
equals(other) {
if (this === other) return true;
for (let i = 0; i < 5; i++) {
if (this[i] !== other[i]) return false;
}
return true;
return this.id === other.id;
}
child(index) {

View file

@ -388,4 +388,24 @@ describe("Node", () => {
assert.throws(() => number.closest({a: 1}), /Argument must be a string or array of strings/)
});
});
describe('.equals(other)', () => {
it('returns true if the nodes are the same', () => {
tree = parser.parse('1 + 2');
const sumNode = tree.rootNode.firstChild.firstChild;
const node1 = sumNode.firstChild;
const node2 = sumNode.firstChild;
assert(node1.equals(node2));
});
it('returns false if the nodes are not the same', () => {
tree = parser.parse('1 + 2');
const sumNode = tree.rootNode.firstChild.firstChild;
const node1 = sumNode.firstChild;
const node2 = node1.nextSibling;
assert(!node1.equals(node2));
});
});
});