Merge pull request #819 from joelspadin/equals-fix
web binding: fix equals()
This commit is contained in:
commit
53949b09fd
2 changed files with 21 additions and 5 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue