summaryrefslogtreecommitdiff
path: root/js/text_encoding_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'js/text_encoding_test.ts')
-rw-r--r--js/text_encoding_test.ts46
1 files changed, 46 insertions, 0 deletions
diff --git a/js/text_encoding_test.ts b/js/text_encoding_test.ts
index 7a9aec833..402044e36 100644
--- a/js/text_encoding_test.ts
+++ b/js/text_encoding_test.ts
@@ -24,3 +24,49 @@ test(function btoaFailed() {
assert(!!err);
assertEqual(err.name, "InvalidInput");
});
+
+test(function textDecoder() {
+ // prettier-ignore
+ const fixture = new Uint8Array([
+ 0xef, 0xbf, 0xbd, 0xef, 0xbf, 0xbd,
+ 0xef, 0xbf, 0xbd, 0xef, 0xbf, 0xbd,
+ 0xef, 0xbf, 0xbd, 0xef, 0xbf, 0xbd
+ ]);
+ const decoder = new TextDecoder();
+ assertEqual(decoder.decode(fixture), "������");
+});
+
+test(function textDecoder2() {
+ // prettier-ignore
+ const fixture = new Uint8Array([
+ 0xf0, 0x9d, 0x93, 0xbd,
+ 0xf0, 0x9d, 0x93, 0xae,
+ 0xf0, 0x9d, 0x94, 0x81,
+ 0xf0, 0x9d, 0x93, 0xbd
+ ]);
+ const decoder = new TextDecoder();
+ assertEqual(decoder.decode(fixture), "𝓽𝓮𝔁𝓽");
+});
+
+test(function textEncoder() {
+ const fixture = "������";
+ const encoder = new TextEncoder();
+ // prettier-ignore
+ assertEqual(Array.from(encoder.encode(fixture)), [
+ 0xef, 0xbf, 0xbd, 0xef, 0xbf, 0xbd,
+ 0xef, 0xbf, 0xbd, 0xef, 0xbf, 0xbd,
+ 0xef, 0xbf, 0xbd, 0xef, 0xbf, 0xbd
+ ]);
+});
+
+test(function textEncoder2() {
+ const fixture = "𝓽𝓮𝔁𝓽";
+ const encoder = new TextEncoder();
+ // prettier-ignore
+ assertEqual(Array.from(encoder.encode(fixture)), [
+ 0xf0, 0x9d, 0x93, 0xbd,
+ 0xf0, 0x9d, 0x93, 0xae,
+ 0xf0, 0x9d, 0x94, 0x81,
+ 0xf0, 0x9d, 0x93, 0xbd
+ ]);
+});