forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-repl-load-multiline-from-history.js
More file actions
90 lines (77 loc) · 2.08 KB
/
test-repl-load-multiline-from-history.js
File metadata and controls
90 lines (77 loc) · 2.08 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
'use strict';
// Flags: --expose-internals
const common = require('../common');
const assert = require('assert');
const repl = require('internal/repl');
const stream = require('stream');
const fixtures = require('../common/fixtures');
class ActionStream extends stream.Stream {
run(data) {
const _iter = data[Symbol.iterator]();
const doAction = () => {
const next = _iter.next();
if (next.done) {
// Close the repl. Note that it must have a clean prompt to do so.
this.emit('keypress', '', { ctrl: true, name: 'd' });
return;
}
const action = next.value;
if (typeof action === 'object') {
this.emit('keypress', '', action);
}
setImmediate(doAction);
};
doAction();
}
resume() {}
pause() {}
}
ActionStream.prototype.readable = true;
{
// Testing multiline history loading
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
const replHistoryPath = fixtures.path('.node_repl_history-multiline');
const checkResults = common.mustSucceed((r) => {
assert.strictEqual(r.history.length, 4);
r.input.run([{ name: 'up' }]);
assert.strictEqual(
r.line,
'var d = [\n' +
' {\n' +
' a: 1,\n' +
' b: 2,\n' +
' },\n' +
' {\n' +
' a: 3,\n' +
' b: 4,\n' +
' c: [{ a: 1, b: 2 },\n' +
' {\n' +
' a: 3,\n' +
' b: 4,\n' +
' }\n' +
' ]\n' +
' }\n' +
']'
);
r.input.run([{ name: 'up' }]);
assert.strictEqual(r.line, 'const c = [\n {\n a: 1,\n b: 2,\n }\n]');
r.input.run([{ name: 'up' }]);
assert.strictEqual(r.line, '`const b = [\n 1,\n 2,\n 3,\n 4,\n]`');
r.input.run([{ name: 'up' }]);
assert.strictEqual(r.line, 'a = `\nI am a multiline string\nI can be as long as I want`');
});
repl.createInternalRepl(
{ NODE_REPL_HISTORY: replHistoryPath },
{
terminal: true,
input: new ActionStream(),
output: new stream.Writable({
write(chunk, _, next) {
next();
}
}),
},
checkResults
);
}