summaryrefslogtreecommitdiff
path: root/js/text_encoding_test.ts
diff options
context:
space:
mode:
authorandy finch <andyfinch7@gmail.com>2019-06-21 18:32:14 -0400
committerRyan Dahl <ry@tinyclouds.org>2019-06-21 15:32:14 -0700
commiteb93dc58a11d9e9a295eff31f9c2c6a3a4c5170b (patch)
tree1143049825f1adad073988a65799a76be6f1090b /js/text_encoding_test.ts
parent20f41e719d2cb5add8e9168d00f239843fd56d31 (diff)
add encodeInto to TextEncoder (#2558)
Diffstat (limited to 'js/text_encoding_test.ts')
-rw-r--r--js/text_encoding_test.ts31
1 files changed, 30 insertions, 1 deletions
diff --git a/js/text_encoding_test.ts b/js/text_encoding_test.ts
index b5ce78a8f..7633e105a 100644
--- a/js/text_encoding_test.ts
+++ b/js/text_encoding_test.ts
@@ -91,7 +91,7 @@ test(function textDecoderErrorEncoding(): void {
assert(didThrow);
});
-test(function textEncoder2(): void {
+test(function textEncoder(): void {
const fixture = "𝓽𝓮𝔁𝓽";
const encoder = new TextEncoder();
// prettier-ignore
@@ -103,6 +103,35 @@ test(function textEncoder2(): void {
]);
});
+test(function textEncodeInto(): void {
+ const fixture = "text";
+ const encoder = new TextEncoder();
+ const bytes = new Uint8Array(5);
+ const result = encoder.encodeInto(fixture, bytes);
+ assertEquals(result.read, 4);
+ assertEquals(result.written, 4);
+ // prettier-ignore
+ assertEquals(Array.from(bytes), [
+ 0x74, 0x65, 0x78, 0x74, 0x00,
+ ]);
+});
+
+test(function textEncodeInto2(): void {
+ const fixture = "𝓽𝓮𝔁𝓽";
+ const encoder = new TextEncoder();
+ const bytes = new Uint8Array(17);
+ const result = encoder.encodeInto(fixture, bytes);
+ assertEquals(result.read, 8);
+ assertEquals(result.written, 16);
+ // prettier-ignore
+ assertEquals(Array.from(bytes), [
+ 0xf0, 0x9d, 0x93, 0xbd,
+ 0xf0, 0x9d, 0x93, 0xae,
+ 0xf0, 0x9d, 0x94, 0x81,
+ 0xf0, 0x9d, 0x93, 0xbd, 0x00,
+ ]);
+});
+
test(function textDecoderSharedUint8Array(): void {
const ab = new SharedArrayBuffer(6);
const dataView = new DataView(ab);