deno.land / std@0.177.1 / streams / reader_from_iterable_test.ts

reader_from_iterable_test.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "../testing/asserts.ts";import { readerFromIterable } from "./reader_from_iterable.ts";
Deno.test("[streams] readerFromIterable()", async function () { const reader = readerFromIterable((function* () { const encoder = new TextEncoder(); for (const string of ["hello", "deno", "foo"]) { yield encoder.encode(string); } })());
const readStrings = []; const decoder = new TextDecoder(); const p = new Uint8Array(4); while (true) { const n = await reader.read(p); if (n == null) { break; } readStrings.push(decoder.decode(p.slice(0, n))); } assertEquals(readStrings, ["hell", "o", "deno", "foo"]);});
std

Version Info

Tagged at
10 months ago