Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 22e601a

Browse filesBrowse files
avivkellertargos
authored andcommitted
test: add util.stripVTControlCharacters test
PR-URL: #54865 Refs: chalk/ansi-regex#58 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent d264639 commit 22e601a
Copy full SHA for 22e601a

File tree

Expand file treeCollapse file tree

1 file changed

+28
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+28
-0
lines changed
Open diff view settings
Collapse file
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
require('../common');
4+
const util = require('util');
5+
const { test } = require('node:test');
6+
7+
// Ref: https://github.com/chalk/ansi-regex/blob/main/test.js
8+
const tests = [
9+
// [before, expected]
10+
['\u001B[0m\u001B[4m\u001B[42m\u001B[31mfoo\u001B[39m\u001B[49m\u001B[24mfoo\u001B[0m', 'foofoo'], // Basic ANSI
11+
['\u001B[0;33;49;3;9;4mbar\u001B[0m', 'bar'], // Advanced colors
12+
['foo\u001B[0gbar', 'foobar'], // Clear tabs
13+
['foo\u001B[Kbar', 'foobar'], // Clear line
14+
['foo\u001B[2Jbar', 'foobar'], // Clear screen
15+
];
16+
17+
for (const ST of ['\u0007', '\u001B\u005C', '\u009C']) {
18+
tests.push(
19+
[`\u001B]8;;mailto:no-replay@mail.com${ST}mail\u001B]8;;${ST}`, 'mail'],
20+
[`\u001B]8;k=v;https://example-a.com/?a_b=1&c=2#tit%20le${ST}click\u001B]8;;${ST}`, 'click'],
21+
);
22+
}
23+
24+
test('util.stripVTControlCharacters', (t) => {
25+
for (const [before, expected] of tests) {
26+
t.assert.strictEqual(util.stripVTControlCharacters(before), expected);
27+
}
28+
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.