Skip to content

Commit 00c0e12

Browse files
committed
more tests, fix check for completer being a function or undefined
1 parent cc62029 commit 00c0e12

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

lib/readline.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const util = require('util');
1212
const inherits = util.inherits;
1313
const EventEmitter = require('events').EventEmitter;
1414

15-
1615
exports.createInterface = function(input, output, completer, terminal) {
1716
var rl;
1817
if (arguments.length === 1) {
@@ -49,7 +48,7 @@ function Interface(input, output, completer, terminal) {
4948

5049
completer = completer || undefined;
5150

52-
if (! typeof completer in ['function', 'undefined']) {
51+
if (typeof completer !== 'function' && typeof completer !== 'undefined') {
5352
throw new TypeError('Argument \'completer\' must be a function');
5453
}
5554

test/parallel/test-readline-interface.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,41 @@ function isWarned(emitter) {
190190
assert.equal(callCount, expectedLines.length);
191191
rli.close();
192192

193+
// \t does not become part of the input when there is a completer function
194+
fi = new FakeInput();
195+
var completer = function(line) {
196+
return [[], line];
197+
};
198+
rli = new readline.Interface({
199+
input: fi,
200+
output: fi,
201+
terminal: true,
202+
completer: completer
203+
});
204+
expectedLines = ['foo'];
205+
callCount = 0;
206+
rli.on('line', function(line) {
207+
assert.equal(line, expectedLines[callCount]);
208+
callCount++;
209+
});
210+
fi.emit('data', '\tfo\to\t');
211+
fi.emit('data', '\n');
212+
assert.equal(callCount, expectedLines.length);
213+
rli.close();
214+
215+
// constructor throws if completer is not a function or undefined
216+
fi = new FakeInput();
217+
assert.throws(function () {
218+
readline.createInterface({
219+
input: fi,
220+
completer: 'string is not valid'
221+
});
222+
}, function (err) {
223+
if ( (err instanceof TypeError) && /Argument \'completer\' must be a function/.test(err) ) {
224+
return true;
225+
}
226+
});
227+
193228
// sending a multi-byte utf8 char over multiple writes
194229
var buf = Buffer('☮', 'utf8');
195230
fi = new FakeInput();

0 commit comments

Comments
 (0)