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