From c8e9adb13587693285b4d5206bc09f786ea12113 Mon Sep 17 00:00:00 2001 From: Prince J Wesley Date: Wed, 22 Jun 2016 16:24:52 +0530 Subject: [PATCH] repl: fix tab completion for defined commands PR-URL: https://github.com/nodejs/node/pull/7364 Reviewed-By: Anna Henningsen Reviewed-By: Jeremiah Senkpiel --- lib/repl.js | 4 ++-- test/parallel/test-repl-tab-complete.js | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/repl.js b/lib/repl.js index 71377b1cc7582d..33f72b6d12e7c5 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -659,11 +659,11 @@ REPLServer.prototype.complete = function(line, callback) { // REPL commands (e.g. ".break"). var match = null; - match = line.match(/^\s*(\.\w*)$/); + match = line.match(/^\s*\.(\w*)$/); if (match) { completionGroups.push(Object.keys(this.commands)); completeOn = match[1]; - if (match[1].length > 1) { + if (match[1].length) { filter = match[1]; } diff --git a/test/parallel/test-repl-tab-complete.js b/test/parallel/test-repl-tab-complete.js index 86a0444c953d27..0925222014f76f 100644 --- a/test/parallel/test-repl-tab-complete.js +++ b/test/parallel/test-repl-tab-complete.js @@ -306,3 +306,10 @@ putIn.run(['var obj = {1:"a","1a":"b",a:"b"};']); testMe.complete('obj.', common.mustCall(function(error, data) { assert.deepEqual(data, obj_elements); })); + +// tab completion for defined commands +putIn.run(['.clear']); + +testMe.complete('.b', common.mustCall((error, data) => { + assert.deepStrictEqual(data, [['break'], 'b']); +}));