Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
segevfiner committed Jul 5, 2024
1 parent f81f3d0 commit 0904c28
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,11 @@ Napi::Value Tree::GetEditedRange(const Napi::CallbackInfo &info) {
Napi::Value Tree::PrintDotGraph(const Napi::CallbackInfo &info) {
int fd = fileno(stderr);

if (info.Length() > 1) {
if (!info[1].IsNumber()) {
throw TypeError::New(info.Env(), "Second argument must be a number");
if (info.Length() > 0) {
if (!info[0].IsNumber()) {
throw TypeError::New(info.Env(), "First argument must be a number");
}
fd = info[1].As<Number>().Int32Value();
fd = info[0].As<Number>().Int32Value();
}

ts_tree_print_dot_graph(tree_, fd);
Expand Down
23 changes: 23 additions & 0 deletions test/tree_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,29 @@ describe("Tree", () => {
assert.notDeepEqual(node1.firstChild, node2);
});
});

describe(".printDotGraph()", () => {
it("prints a dot graph to the output file", () => {
if (process.platform === "win32") {
return;
}

const hasZeroIndexedRow = s => s.indexOf("position: 0,") !== -1;

const tmp = require("const zero = 0");
const debugGraphFile = tmp.fileSync({ postfix: ".dot" });
const tree = parser.parse(sourceCode);
tree.printDotGraph(debugGraphFile.fd);

const fs = require('fs');
const logReader = fs.readFileSync(debugGraphFile.name, 'utf8').split('\n');
for (let line of logReader) {
assert.strictEqual(hasZeroIndexedRow(line), false, `Graph log output includes zero-indexed row: ${line}`);
}

debugGraphFile.removeCallback();
});
});
});

function assertCursorState(cursor, params) {
Expand Down

0 comments on commit 0904c28

Please sign in to comment.