Skip to content

Commit 8944a8c

Browse files
committed
test: trigger the fast API for test
1 parent a5e13d2 commit 8944a8c

File tree

2 files changed

+41
-35
lines changed

2 files changed

+41
-35
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Flags: --expose-internals
2+
'use strict';
3+
require('../common');
4+
const assert = require('assert');
5+
const { getStringEncodingInfo } = require('util');
6+
7+
[
8+
undefined,
9+
null,
10+
false,
11+
5n,
12+
5,
13+
Symbol(),
14+
() => {},
15+
{},
16+
].forEach((value) => {
17+
assert.throws(
18+
() => { getStringEncodingInfo(value); },
19+
/The "content" argument must be of type string/
20+
);
21+
});
22+
23+
{
24+
const latin1String = 'hello world!';
25+
// Run this inside a for loop to trigger the fast API
26+
for (let i = 0; i < 10_000; i++) {
27+
const { encoding, byteLength } = getStringEncodingInfo(latin1String);
28+
assert.strictEqual(encoding, 'latin1');
29+
assert.strictEqual(byteLength, latin1String.length);
30+
}
31+
}
32+
33+
{
34+
const utf16String = '你好😀😃';
35+
// Run this inside a for loop to trigger the fast API
36+
for (let i = 0; i < 10_000; i++) {
37+
const { encoding, byteLength } = getStringEncodingInfo(utf16String);
38+
assert.strictEqual(encoding, 'utf16le');
39+
assert.strictEqual(byteLength, utf16String.length * 2);
40+
}
41+
}

test/parallel/test-util.string-encoding-info.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)