0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-25 08:19:38 +01:00
nodejs/test/parallel/test-readline-set-raw-mode.js
isaacs 3e1b1dd4a9 Remove excessive copyright/license boilerplate
The copyright and license notice is already in the LICENSE file.  There
is no justifiable reason to also require that it be included in every
file, since the individual files are not individually distributed except
as part of the entire package.
2015-01-12 15:30:28 -08:00

68 lines
1.4 KiB
JavaScript

var assert = require('assert');
var readline = require('readline');
var Stream = require('stream');
var stream = new Stream();
var expectedRawMode = true;
var rawModeCalled = false;
var resumeCalled = false;
var pauseCalled = false;
stream.setRawMode = function(mode) {
rawModeCalled = true;
assert.equal(mode, expectedRawMode);
};
stream.resume = function() {
resumeCalled = true;
};
stream.pause = function() {
pauseCalled = true;
};
// when the "readline" starts in "terminal" mode,
// then setRawMode(true) should be called
var rli = readline.createInterface({
input: stream,
output: stream,
terminal: true
});
assert(rli.terminal);
assert(rawModeCalled);
assert(resumeCalled);
assert(!pauseCalled);
// pause() should call *not* call setRawMode()
rawModeCalled = false;
resumeCalled = false;
pauseCalled = false;
rli.pause();
assert(!rawModeCalled);
assert(!resumeCalled);
assert(pauseCalled);
// resume() should *not* call setRawMode()
rawModeCalled = false;
resumeCalled = false;
pauseCalled = false;
rli.resume();
assert(!rawModeCalled);
assert(resumeCalled);
assert(!pauseCalled);
// close() should call setRawMode(false)
expectedRawMode = false;
rawModeCalled = false;
resumeCalled = false;
pauseCalled = false;
rli.close();
assert(rawModeCalled);
assert(!resumeCalled);
assert(pauseCalled);
assert.deepEqual(stream.listeners('keypress'), []);
// one data listener for the keypress events.
assert.equal(stream.listeners('data').length, 1);