Skip to content

Commit

Permalink
test,readline: improve tab completion coverage
Browse files Browse the repository at this point in the history
PR-URL: #38465
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
  • Loading branch information
aduh95 authored and targos committed May 3, 2021
1 parent 7ce39b8 commit 16eb078
Showing 1 changed file with 40 additions and 8 deletions.
48 changes: 40 additions & 8 deletions test/parallel/test-readline-tab-complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@ common.skipIfDumbTerminal();
const width = getStringWidth(char) - 1;

class FakeInput extends EventEmitter {
columns = ((width + 1) * 10 + (lineBreak ? 0 : 10)) * 3
columns = ((width + 1) * 10 + (lineBreak ? 0 : 10)) * 3

write = common.mustCall((data) => {
output += data;
}, 6)
write = common.mustCall((data) => {
output += data;
}, 6)

resume() {}
pause() {}
end() {}
resume() {}
pause() {}
end() {}
}

const fi = new FakeInput();
const rli = new readline.Interface({
input: fi,
output: fi,
terminal: true,
completer: completer
completer: common.mustCallAtLeast(completer),
});

const last = '\r\nFirst group\r\n\r\n' +
Expand All @@ -68,3 +68,35 @@ common.skipIfDumbTerminal();
rli.close();
});
});

{
let output = '';
class FakeInput extends EventEmitter {
columns = 80

write = common.mustCall((data) => {
output += data;
}, 1)

resume() {}
pause() {}
end() {}
}

const fi = new FakeInput();
const rli = new readline.Interface({
input: fi,
output: fi,
terminal: true,
completer:
common.mustCallAtLeast((_, cb) => cb(new Error('message'))),
});

rli.on('line', common.mustNotCall());
fi.emit('data', '\t');
queueMicrotask(() => {
assert.match(output, /^Tab completion error: Error: message/);
output = '';
});
rli.close();
}

0 comments on commit 16eb078

Please sign in to comment.