blob: 7810dfeda839d5a00e503924b45ca574be179119 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
'use strict';
require('../common');
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);
|