Skip to content

Commit

Permalink
test: test cases for surrogate to usv string
Browse files Browse the repository at this point in the history
Added test cases to check surrogate code points to usv string conversion
in stream consumers and text decoder

Fixes: #39804
  • Loading branch information
git-srinivas committed Oct 21, 2021
1 parent 37ab7b0 commit e5857ba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
16 changes: 9 additions & 7 deletions test/parallel/test-stream-consumers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
} = require('stream/consumers');

const {
Readable,
PassThrough
} = require('stream');

Expand Down Expand Up @@ -74,15 +75,16 @@ const kArrayBuffer =
}

{
const passthrough = new PassThrough();
const readable = new Readable({
read() {}
});

text(passthrough).then(common.mustCall(async (str) => {
assert.strictEqual(str.length, 11);
assert.deepStrictEqual(str, 'hellothere\ufffd');
}));
text(readable).then((data) => {
assert.deepStrictEqual(data, 'foo\ufffd\ufffd\ufffd');
});

passthrough.write('hello');
setTimeout(() => passthrough.end('there\ud801'), 10);
readable.push(new Uint8Array([0x66, 0x6f, 0x6f, 0xed, 0xa0, 0x80]));
readable.push(null);
}

{
Expand Down
11 changes: 2 additions & 9 deletions test/parallel/test-whatwg-encoding-custom-textdecoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,7 @@ if (common.hasIntl) {
// Test TextDecoder for surrogate code points
{
const decoder = new TextDecoder();
const chunk = Buffer.from([0x66, 0x6f, 0x6f, 0xed, 0xa0, 0x80]);
const chunk = new Uint8Array([0x66, 0x6f, 0x6f, 0xed]);
const str = decoder.decode(chunk);
assert.strictEqual(str, 'foo\ufffd\ufffd\ufffd');
}

{
const decoder = new TextDecoder();
const chunk = Buffer.from('\ud807');
const str = decoder.decode(chunk);
assert.strictEqual(str, '\ufffd');
assert.strictEqual(str, 'foo\ufffd');
}

0 comments on commit e5857ba

Please sign in to comment.