test: refactor test-repl-tab-complete
* Add check for `data` object in tab completion callback * Replace `.indexOf()` with `.startsWith()` where appropriate PR-URL: https://github.com/nodejs/node/pull/10879 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
ba776b3a56
commit
b5474c8cee
@ -231,6 +231,7 @@ putIn.run([
|
|||||||
|
|
||||||
testMe.complete('proxy.', common.mustCall(function(error, data) {
|
testMe.complete('proxy.', common.mustCall(function(error, data) {
|
||||||
assert.strictEqual(error, null);
|
assert.strictEqual(error, null);
|
||||||
|
assert(Array.isArray(data));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Make sure tab completion does not include integer members of an Array
|
// Make sure tab completion does not include integer members of an Array
|
||||||
@ -307,9 +308,7 @@ const testCustomCompleterSyncMode = repl.start({
|
|||||||
input: putIn,
|
input: putIn,
|
||||||
output: putIn,
|
output: putIn,
|
||||||
completer: function completer(line) {
|
completer: function completer(line) {
|
||||||
const hits = customCompletions.filter((c) => {
|
const hits = customCompletions.filter((c) => c.startsWith(line));
|
||||||
return c.indexOf(line) === 0;
|
|
||||||
});
|
|
||||||
// Show all completions if none found.
|
// Show all completions if none found.
|
||||||
return [hits.length ? hits : customCompletions, line];
|
return [hits.length ? hits : customCompletions, line];
|
||||||
}
|
}
|
||||||
@ -339,9 +338,7 @@ const testCustomCompleterAsyncMode = repl.start({
|
|||||||
input: putIn,
|
input: putIn,
|
||||||
output: putIn,
|
output: putIn,
|
||||||
completer: function completer(line, callback) {
|
completer: function completer(line, callback) {
|
||||||
const hits = customCompletions.filter((c) => {
|
const hits = customCompletions.filter((c) => c.startsWith(line));
|
||||||
return c.indexOf(line) === 0;
|
|
||||||
});
|
|
||||||
// Show all completions if none found.
|
// Show all completions if none found.
|
||||||
callback(null, [hits.length ? hits : customCompletions, line]);
|
callback(null, [hits.length ? hits : customCompletions, line]);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user