mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 22:48:11 +00:00
LibWeb: Add TextEncoder encodeInto
This commit is contained in:
parent
f1ead552ce
commit
0104225d9b
9 changed files with 123 additions and 10 deletions
33
Tests/LibWeb/Text/input/Encoding/TextEncoder-encode.html
Normal file
33
Tests/LibWeb/Text/input/Encoding/TextEncoder-encode.html
Normal file
|
@ -0,0 +1,33 @@
|
|||
<script src="../include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
let testCounter = 1;
|
||||
function testPart(part) {
|
||||
println(`${testCounter++}. ${JSON.stringify(part())}`);
|
||||
}
|
||||
|
||||
// 1. TextEncoder encode
|
||||
testPart(() => new TextEncoder().encode('Well Hello Friends 😀!'));
|
||||
|
||||
// 2. TextEncoder encodeInto
|
||||
testPart(() => {
|
||||
const buffer = new Uint8Array(32);
|
||||
new TextEncoder().encodeInto('Well Hello Friends 😀!', buffer);
|
||||
return buffer
|
||||
});
|
||||
|
||||
// 3. TextEncoder encodeInto result read
|
||||
testPart(() => {
|
||||
const buffer = new Uint8Array(32);
|
||||
const result = new TextEncoder().encodeInto('Well Hello Friends 😀!', buffer);
|
||||
return result.read;
|
||||
});
|
||||
|
||||
// 3. TextEncoder encodeInto result written
|
||||
testPart(() => {
|
||||
const buffer = new Uint8Array(32);
|
||||
const result = new TextEncoder().encodeInto('Well Hello Friends 😀!', buffer);
|
||||
return result.written;
|
||||
});
|
||||
});
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue