Skip to content

Commit

Permalink
test(cbor): empty string being excluded from expected result (denolan…
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackAsLight authored Oct 13, 2024
1 parent 123c1fe commit 3927872
Showing 1 changed file with 45 additions and 51 deletions.
96 changes: 45 additions & 51 deletions cbor/text_encoder_stream_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,48 @@ import { random } from "./_common_test.ts";
import { encodeCbor } from "./encode_cbor.ts";
import { CborTextEncoderStream } from "./text_encoder_stream.ts";

Deno.test(
"CborTextEncoderStream() correctly encoding",
{ ignore: true },
async () => {
const strings = [
"a".repeat(random(0, 24)),
"a".repeat(random(24, 2 ** 8)),
"a".repeat(random(2 ** 8, 2 ** 10)),
];

const expectedOutput = concat([
new Uint8Array([0b011_11111]),
...strings.filter((x) => x).map((x) => encodeCbor(x)),
new Uint8Array([0b111_11111]),
]);

const actualOutput = concat(
await Array.fromAsync(
ReadableStream.from(strings).pipeThrough(new CborTextEncoderStream()),
),
);

assertEquals(actualOutput, expectedOutput);
},
);

Deno.test(
"CborTextEncoderStream.from() correctly encoding",
{ ignore: true },
async () => {
const strings = [
"a".repeat(random(0, 24)),
"a".repeat(random(24, 2 ** 8)),
"a".repeat(random(2 ** 8, 2 ** 10)),
];

const expectedOutput = concat([
new Uint8Array([0b011_11111]),
...strings.filter((x) => x).map((x) => encodeCbor(x)),
new Uint8Array([0b111_11111]),
]);

const actualOutput = concat(
await Array.fromAsync(
CborTextEncoderStream.from(strings).readable,
),
);

assertEquals(actualOutput, expectedOutput);
},
);
Deno.test("CborTextEncoderStream() correctly encoding", async () => {
const strings = [
"a".repeat(random(0, 24)),
"a".repeat(random(24, 2 ** 8)),
"a".repeat(random(2 ** 8, 2 ** 16)),
"a".repeat(random(2 ** 16, 2 ** 17)),
];

const expectedOutput = concat([
new Uint8Array([0b011_11111]),
...strings.map((x) => encodeCbor(x)),
new Uint8Array([0b111_11111]),
]);

const actualOutput = concat(
await Array.fromAsync(
ReadableStream.from(strings).pipeThrough(new CborTextEncoderStream()),
),
);

assertEquals(actualOutput, expectedOutput);
});

Deno.test("CborTextEncoderStream.from() correctly encoding", async () => {
const strings = [
"a".repeat(random(0, 24)),
"a".repeat(random(24, 2 ** 8)),
"a".repeat(random(2 ** 8, 2 ** 16)),
"a".repeat(random(2 ** 16, 2 ** 17)),
];

const expectedOutput = concat([
new Uint8Array([0b011_11111]),
...strings.map((x) => encodeCbor(x)),
new Uint8Array([0b111_11111]),
]);

const actualOutput = concat(
await Array.fromAsync(
CborTextEncoderStream.from(strings).readable,
),
);

assertEquals(actualOutput, expectedOutput);
});

0 comments on commit 3927872

Please sign in to comment.