Implement Wasm binding for Tree.getChangedRanges()
This commit is contained in:
parent
7de4985a27
commit
0d70b485c0
4 changed files with 94 additions and 5 deletions
|
|
@ -81,6 +81,54 @@ describe("Tree", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe(".getChangedRanges(previous)", () => {
|
||||
it("reports the ranges of text whose syntactic meaning has changed", () => {
|
||||
let sourceCode = "abcdefg + hij";
|
||||
tree = parser.parse(sourceCode);
|
||||
|
||||
assert.equal(
|
||||
tree.rootNode.toString(),
|
||||
"(program (expression_statement (binary_expression (identifier) (identifier))))"
|
||||
);
|
||||
|
||||
sourceCode = "abc + defg + hij";
|
||||
tree.edit({
|
||||
startIndex: 2,
|
||||
oldEndIndex: 2,
|
||||
newEndIndex: 5,
|
||||
startPosition: { row: 0, column: 2 },
|
||||
oldEndPosition: { row: 0, column: 2 },
|
||||
newEndPosition: { row: 0, column: 5 }
|
||||
});
|
||||
|
||||
const tree2 = parser.parse(sourceCode, tree);
|
||||
assert.equal(
|
||||
tree2.rootNode.toString(),
|
||||
"(program (expression_statement (binary_expression (binary_expression (identifier) (identifier)) (identifier))))"
|
||||
);
|
||||
|
||||
const ranges = tree.getChangedRanges(tree2);
|
||||
assert.deepEqual(ranges, [
|
||||
{
|
||||
startIndex: 0,
|
||||
endIndex: "abc + defg".length,
|
||||
startPosition: { row: 0, column: 0 },
|
||||
endPosition: { row: 0, column: "abc + defg".length }
|
||||
}
|
||||
]);
|
||||
|
||||
tree2.delete();
|
||||
});
|
||||
|
||||
it('throws an exception if the argument is not a tree', () => {
|
||||
tree = parser.parse("abcdefg + hij");
|
||||
|
||||
assert.throws(() => {
|
||||
tree.getChangedRanges({});
|
||||
}, /Argument must be a Tree/);
|
||||
})
|
||||
});
|
||||
|
||||
describe(".walk()", () => {
|
||||
let cursor
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue