Skip to content

Commit

Permalink
more tests, fix check for completer being a function or undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
Trott committed May 23, 2015
1 parent f037436 commit e3b22ae
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const util = require('util');
const inherits = util.inherits;
const EventEmitter = require('events').EventEmitter;


exports.createInterface = function(input, output, completer, terminal) {
var rl;
if (arguments.length === 1) {
Expand Down Expand Up @@ -49,7 +48,7 @@ function Interface(input, output, completer, terminal) {

completer = completer || undefined;

if (! typeof completer in ['function', 'undefined']) {
if (typeof completer !== 'function' && typeof completer !== 'undefined') {
throw new TypeError('Argument \'completer\' must be a function');
}

Expand Down
35 changes: 35 additions & 0 deletions test/parallel/test-readline-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,41 @@ function isWarned(emitter) {
assert.equal(callCount, expectedLines.length);
rli.close();

// \t does not become part of the input when there is a completer function
fi = new FakeInput();
var completer = function(line) {
return [[], line];
};
rli = new readline.Interface({
input: fi,
output: fi,
terminal: true,
completer: completer
});
expectedLines = ['foo'];
callCount = 0;
rli.on('line', function(line) {
assert.equal(line, expectedLines[callCount]);
callCount++;
});
fi.emit('data', '\tfo\to\t');
fi.emit('data', '\n');
assert.equal(callCount, expectedLines.length);
rli.close();

// constructor throws if completer is not a function or undefined
fi = new FakeInput();
assert.throws(function () {
readline.createInterface({
input: fi,
completer: 'string is not valid'
});
}, function (err) {
if ( (err instanceof TypeError) && /Argument \'completer\' must be a function/.test(err) ) {
return true;
}
});

// sending a multi-byte utf8 char over multiple writes
var buf = Buffer('☮', 'utf8');
fi = new FakeInput();
Expand Down

0 comments on commit e3b22ae

Please sign in to comment.