forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest-startup-empty-regexp-statics.js
68 lines (59 loc) · 2.29 KB
/
test-startup-empty-regexp-statics.js
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
'use strict';
const common = require('../common');
const assert = require('node:assert');
const { spawnSync, spawn } = require('node:child_process');
assert.strictEqual(RegExp.$_, '');
assert.strictEqual(RegExp.$0, undefined);
assert.strictEqual(RegExp.$1, '');
assert.strictEqual(RegExp.$2, '');
assert.strictEqual(RegExp.$3, '');
assert.strictEqual(RegExp.$4, '');
assert.strictEqual(RegExp.$5, '');
assert.strictEqual(RegExp.$6, '');
assert.strictEqual(RegExp.$7, '');
assert.strictEqual(RegExp.$8, '');
assert.strictEqual(RegExp.$9, '');
assert.strictEqual(RegExp.input, '');
assert.strictEqual(RegExp.lastMatch, '');
assert.strictEqual(RegExp.lastParen, '');
assert.strictEqual(RegExp.leftContext, '');
assert.strictEqual(RegExp.rightContext, '');
assert.strictEqual(RegExp['$&'], '');
assert.strictEqual(RegExp['$`'], '');
assert.strictEqual(RegExp['$+'], '');
assert.strictEqual(RegExp["$'"], '');
const allRegExpStatics =
'RegExp.$_ + RegExp["$&"] + RegExp["$`"] + RegExp["$+"] + RegExp["$\'"] + ' +
'RegExp.input + RegExp.lastMatch + RegExp.lastParen + ' +
'RegExp.leftContext + RegExp.rightContext + ' +
Array.from({ length: 10 }, (_, i) => `RegExp.$${i}`).join(' + ');
{
const child = spawnSync(process.execPath,
[ '-p', allRegExpStatics ],
{ stdio: ['inherit', 'pipe', 'inherit'] });
assert.match(child.stdout.toString(), /^undefined\r?\n$/);
assert.strictEqual(child.status, 0);
assert.strictEqual(child.signal, null);
}
{
const child = spawnSync(process.execPath,
[ '-e', `console.log(${allRegExpStatics})`, '--input-type=module' ],
{ stdio: ['inherit', 'pipe', 'inherit'] });
assert.match(child.stdout.toString(), /^undefined\r?\n$/);
assert.strictEqual(child.status, 0);
assert.strictEqual(child.signal, null);
}
{
const child = spawn(process.execPath, [], { stdio: ['pipe', 'pipe', 'inherit'], encoding: 'utf8' });
let stdout = '';
child.stdout.on('data', (chunk) => {
stdout += chunk;
});
child.on('exit', common.mustCall((status, signal) => {
assert.match(stdout, /^undefined\r?\n$/);
assert.strictEqual(status, 0);
assert.strictEqual(signal, null);
}));
child.on('error', common.mustNotCall());
child.stdin.end(`console.log(${allRegExpStatics});\n`);
}