mirror of
https://github.com/zebrajr/node.git
synced 2025-12-07 12:20:50 +01:00
PR-URL: https://github.com/nodejs/node/pull/59964 Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
66 lines
1.9 KiB
JavaScript
66 lines
1.9 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const { startNewREPLServer } = require('../common/repl');
|
|
|
|
// To test custom completer function.
|
|
// Sync mode.
|
|
{
|
|
const customCompletions = 'aaa aa1 aa2 bbb bb1 bb2 bb3 ccc ddd eee'.split(' ');
|
|
const { replServer } = startNewREPLServer({
|
|
completer: function completer(line) {
|
|
const hits = customCompletions.filter((c) => c.startsWith(line));
|
|
// Show all completions if none found.
|
|
return [hits.length ? hits : customCompletions, line];
|
|
}
|
|
});
|
|
|
|
// On empty line should output all the custom completions
|
|
// without complete anything.
|
|
replServer.complete('', common.mustCall((error, data) => {
|
|
assert.deepStrictEqual(data, [
|
|
customCompletions,
|
|
'',
|
|
]);
|
|
}));
|
|
|
|
// On `a` should output `aaa aa1 aa2` and complete until `aa`.
|
|
replServer.complete('a', common.mustCall((error, data) => {
|
|
assert.deepStrictEqual(data, [
|
|
'aaa aa1 aa2'.split(' '),
|
|
'a',
|
|
]);
|
|
}));
|
|
}
|
|
|
|
// To test custom completer function.
|
|
// Async mode.
|
|
{
|
|
const customCompletions = 'aaa aa1 aa2 bbb bb1 bb2 bb3 ccc ddd eee'.split(' ');
|
|
const { replServer } = startNewREPLServer({
|
|
completer: function completer(line, callback) {
|
|
const hits = customCompletions.filter((c) => c.startsWith(line));
|
|
// Show all completions if none found.
|
|
callback(null, [hits.length ? hits : customCompletions, line]);
|
|
}
|
|
});
|
|
|
|
// On empty line should output all the custom completions
|
|
// without complete anything.
|
|
replServer.complete('', common.mustCall((error, data) => {
|
|
assert.deepStrictEqual(data, [
|
|
customCompletions,
|
|
'',
|
|
]);
|
|
}));
|
|
|
|
// On `a` should output `aaa aa1 aa2` and complete until `aa`.
|
|
replServer.complete('a', common.mustCall((error, data) => {
|
|
assert.deepStrictEqual(data, [
|
|
'aaa aa1 aa2'.split(' '),
|
|
'a',
|
|
]);
|
|
}));
|
|
}
|