Skip to content

Commit b1de92b

Browse files
committed
test: simplify encodeInto large buffer regression test
Drop the bounded subarray case, remove the unnecessary error code check, and use a 2**31 byte Uint8Array directly instead of slicing an offset subarray. Signed-off-by: semimikoh <ejffjeosms@gmail.com>
1 parent 71282c0 commit b1de92b

File tree

1 file changed

+6
-21
lines changed

1 file changed

+6
-21
lines changed

test/parallel/test-whatwg-encoding-encodeinto-large.js

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,17 @@ const encoder = new TextEncoder();
1010
const source = 'a\xFF\u6211\u{1D452}';
1111
const expected = encoder.encode(source);
1212

13-
const size = 2 ** 31 + expected.length;
14-
const offset = expected.length - 1;
1513
let dest;
1614

1715
try {
18-
dest = new Uint8Array(size);
19-
} catch (e) {
20-
if (e.code === 'ERR_MEMORY_ALLOCATION_FAILED' ||
21-
/Array buffer allocation failed/.test(e.message)) {
22-
common.skip('insufficient space for Uint8Array allocation');
23-
}
24-
throw e;
16+
dest = new Uint8Array(2 ** 31);
17+
} catch {
18+
common.skip('insufficient space for Uint8Array allocation');
2519
}
2620

27-
const large = encoder.encodeInto(source, dest.subarray(offset));
28-
assert.deepStrictEqual(large, {
21+
const result = encoder.encodeInto(source, dest);
22+
assert.deepStrictEqual(result, {
2923
read: source.length,
3024
written: expected.length,
3125
});
32-
assert.deepStrictEqual(dest.slice(offset, offset + expected.length), expected);
33-
34-
const bounded = encoder.encodeInto(source,
35-
dest.subarray(offset,
36-
offset + expected.length));
37-
assert.deepStrictEqual(bounded, {
38-
read: source.length,
39-
written: expected.length,
40-
});
41-
assert.deepStrictEqual(dest.slice(offset, offset + expected.length), expected);
26+
assert.deepStrictEqual(dest.subarray(0, expected.length), expected);

0 commit comments

Comments
 (0)