diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-04-29 22:38:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-29 22:38:10 +0200 |
commit | d308e8d0c0469419517e05a36ba070633168dc67 (patch) | |
tree | 1b9b76c8a443cb781f6c557e964ebae73d64c4bc /std/ws/test.ts | |
parent | b51c863550cb377f6e720bccf4f1485ed8d97222 (diff) |
BREAKING: remove custom implementation of Deno.Buffer.toString() (#4992)
Keep in mind Buffer.toString() still exists, but returns [object Object].
Reason for removal of Buffer.toString() was that it implicitly used
TextDecoder with fixed "utf-8" encoding and no way to customize
the encoding.
Diffstat (limited to 'std/ws/test.ts')
-rw-r--r-- | std/ws/test.ts | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/std/ws/test.ts b/std/ws/test.ts index c6e74dadc..796bf3bb8 100644 --- a/std/ws/test.ts +++ b/std/ws/test.ts @@ -31,7 +31,8 @@ test("[ws] read unmasked text frame", async () => { const frame = await readFrame(buf); assertEquals(frame.opcode, OpCode.TextFrame); assertEquals(frame.mask, undefined); - assertEquals(new Buffer(frame.payload).toString(), "Hello"); + const actual = new TextDecoder().decode(new Buffer(frame.payload).bytes()); + assertEquals(actual, "Hello"); assertEquals(frame.isLastFrame, true); }); @@ -57,7 +58,8 @@ test("[ws] read masked text frame", async () => { const frame = await readFrame(buf); assertEquals(frame.opcode, OpCode.TextFrame); unmask(frame.payload, frame.mask); - assertEquals(new Buffer(frame.payload).toString(), "Hello"); + const actual = new TextDecoder().decode(new Buffer(frame.payload).bytes()); + assertEquals(actual, "Hello"); assertEquals(frame.isLastFrame, true); }); @@ -72,12 +74,14 @@ test("[ws] read unmasked split text frames", async () => { assertEquals(f1.isLastFrame, false); assertEquals(f1.mask, undefined); assertEquals(f1.opcode, OpCode.TextFrame); - assertEquals(new Buffer(f1.payload).toString(), "Hel"); + const actual1 = new TextDecoder().decode(new Buffer(f1.payload).bytes()); + assertEquals(actual1, "Hel"); assertEquals(f2.isLastFrame, true); assertEquals(f2.mask, undefined); assertEquals(f2.opcode, OpCode.Continue); - assertEquals(new Buffer(f2.payload).toString(), "lo"); + const actual2 = new TextDecoder().decode(new Buffer(f2.payload).bytes()); + assertEquals(actual2, "lo"); }); test("[ws] read unmasked ping / pong frame", async () => { @@ -87,7 +91,8 @@ test("[ws] read unmasked ping / pong frame", async () => { ); const ping = await readFrame(buf); assertEquals(ping.opcode, OpCode.Ping); - assertEquals(new Buffer(ping.payload).toString(), "Hello"); + const actual1 = new TextDecoder().decode(new Buffer(ping.payload).bytes()); + assertEquals(actual1, "Hello"); // prettier-ignore const pongFrame= [0x8a, 0x85, 0x37, 0xfa, 0x21, 0x3d, 0x7f, 0x9f, 0x4d, 0x51, 0x58] const buf2 = new BufReader(new Buffer(new Uint8Array(pongFrame))); @@ -95,7 +100,8 @@ test("[ws] read unmasked ping / pong frame", async () => { assertEquals(pong.opcode, OpCode.Pong); assert(pong.mask !== undefined); unmask(pong.payload, pong.mask); - assertEquals(new Buffer(pong.payload).toString(), "Hello"); + const actual2 = new TextDecoder().decode(new Buffer(pong.payload).bytes()); + assertEquals(actual2, "Hello"); }); test("[ws] read unmasked big binary frame", async () => { |