From fd8fd3f535ffe1b07b19abf178a6604df55ac9d2 Mon Sep 17 00:00:00 2001 From: Daumantas Kavolis Date: Fri, 16 Jun 2023 13:22:11 +0300 Subject: [PATCH] Add tests for previous sibling, last child --- lib/binding_web/exports.json | 2 +- lib/binding_web/test/tree-test.js | 44 +++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/lib/binding_web/exports.json b/lib/binding_web/exports.json index 1c638bb0..9e219d70 100644 --- a/lib/binding_web/exports.json +++ b/lib/binding_web/exports.json @@ -105,7 +105,7 @@ "_ts_tree_cursor_end_index_wasm", "_ts_tree_cursor_end_position_wasm", "_ts_tree_cursor_goto_first_child_wasm", - "_ts_tree_cursor_goto_last_child", + "_ts_tree_cursor_goto_last_child_wasm", "_ts_tree_cursor_goto_next_sibling_wasm", "_ts_tree_cursor_goto_previous_sibling_wasm", "_ts_tree_cursor_goto_parent_wasm", diff --git a/lib/binding_web/test/tree-test.js b/lib/binding_web/test/tree-test.js index 8c04e63e..a98d216a 100644 --- a/lib/binding_web/test/tree-test.js +++ b/lib/binding_web/test/tree-test.js @@ -244,6 +244,50 @@ describe("Tree", () => { endIndex: 13 }); + { + const copy = tree.walk(); + copy.resetTo(cursor); + + assert(copy.gotoPreviousSibling()); + assertCursorState(copy, { + nodeType: '+', + nodeIsNamed: false, + startPosition: {row: 0, column: 6}, + endPosition: {row: 0, column: 7}, + startIndex: 6, + endIndex: 7 + }); + + assert(copy.gotoPreviousSibling()); + assertCursorState(copy, { + nodeType: 'binary_expression', + nodeIsNamed: true, + startPosition: {row: 0, column: 0}, + endPosition: {row: 0, column: 5}, + startIndex: 0, + endIndex: 5 + }); + + assert(copy.gotoLastChild()); + assertCursorState(copy, { + nodeType: "identifier", + nodeIsNamed: true, + startPosition: {row: 0, column: 4}, + endPosition: {row: 0, column: 5}, + startIndex: 4, + endIndex: 5 + }) + + assert(copy.gotoParent()); + assert(copy.gotoParent()); + assert.equal(copy.nodeType, 'binary_expression') + assert(copy.gotoParent()); + assert.equal(copy.nodeType, 'expression_statement') + assert(copy.gotoParent()); + assert.equal(copy.nodeType, 'program') + assert(!copy.gotoParent()); + } + // const childIndex = cursor.gotoFirstChildForIndex(12); // assertCursorState(cursor, { // nodeType: 'identifier',