mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
2b5d71224f
Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com>
26 lines
758 B
TypeScript
26 lines
758 B
TypeScript
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
|
|
import { assertEquals } from "../assert/mod.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"]);
|
|
});
|