Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

collectUint8StreamText.test.ts

38 lines1.1 KB

1import { assert, describe, it } from "@effect/vitest";
2import { Effect, Stream } from "effect";
3​
4import { collectUint8StreamText } from "./collectUint8StreamText.ts";
5​
6const encoder = new TextEncoder();
7​
8describe("collectUint8StreamText", () => {
9 it.effect("collects Uint8Array chunks into decoded text", () =>
10 Effect.gen(function* () {
11 const result = yield* collectUint8StreamText({
12 stream: Stream.make(encoder.encode("hello "), encoder.encode("world")),
13 });
14​
15 assert.deepStrictEqual(result, {
16 text: "hello world",
17 bytes: 11,
18 truncated: false,
19 });
20 }),
21 );
22​
23 it.effect("truncates by bytes and appends an optional marker once", () =>
24 Effect.gen(function* () {
25 const result = yield* collectUint8StreamText({
26 stream: Stream.make(encoder.encode("abcdef"), encoder.encode("ghij")),
27 maxBytes: 5,
28 truncatedMarker: "[truncated]",
29 });
30​
31 assert.deepStrictEqual(result, {
32 text: "abcde[truncated]",
33 bytes: 5,
34 truncated: true,
35 });
36 }),
37 );
38});