mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 13:47:35 +00:00
LibWeb: Add TextEncoder encodeInto
This commit is contained in:
parent
f1ead552ce
commit
0104225d9b
9 changed files with 123 additions and 10 deletions
|
@ -0,0 +1,4 @@
|
|||
1. {"0":87,"1":101,"2":108,"3":108,"4":32,"5":72,"6":101,"7":108,"8":108,"9":111,"10":32,"11":70,"12":114,"13":105,"14":101,"15":110,"16":100,"17":115,"18":32,"19":240,"20":159,"21":152,"22":128,"23":33}
|
||||
2. {"0":87,"1":101,"2":108,"3":108,"4":32,"5":72,"6":101,"7":108,"8":108,"9":111,"10":32,"11":70,"12":114,"13":105,"14":101,"15":110,"16":100,"17":115,"18":32,"19":240,"20":159,"21":152,"22":128,"23":33,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0,"30":0,"31":0}
|
||||
3. 22
|
||||
4. 24
|
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