Very Popular
// Copyright 2018-2020 the oak authors. All rights reserved. MIT license.
import { assertEquals, StringReader, test } from "./test_deps.ts";
import { BufReader } from "./buf_reader.ts";
const decoder = new TextDecoder();
const fixture = `Lorem ipsum dolor sit amet, consectetuer adipiscing elit, seddiam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam eratvolutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorpersuscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eumiriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illumdolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odiodignissim qui blandit praesent luptatum zzril delenit augue duis dolore tefeugait nulla facilisi.
Epsum factorial non deposit quid pro quo hic escorol. Olypian quarrels etgorilla congolium sic ad nauseum. Souvlaki ignitus carborundum e pluribus unum.Defacto lingo est igpay atinlay. Marquee selectus non provisio incongruousfeline nolo contendre. Gratuitous octopus niacin, sodium glutimate. Quote meonan estimate et non interruptus stadium. Sic tempus fugit esperanto hiccupestrogen. Glorious baklava ex librus hup hey ad infinitum. Non sequiturcondominium facile et geranium incognito. Epsum factorial non deposit quid proquo hic escorol. Marquee selectus non provisio incongruous feline nolo contendreOlypian quarrels et gorilla congolium sic ad nauseum. Souvlaki ignituscarborundum e pluribus unum.`;
function append(a: Uint8Array, b: Uint8Array): Uint8Array { const ab = new Uint8Array(a.length + b.length); ab.set(a, 0); ab.set(b, a.length); return ab;}
test({ name: "BufReader - readLine()", async fn() { const reader = new StringReader(fixture); const bufReader = new BufReader(reader, 100); let reads = 0; let actual = new Uint8Array(); let readResult: { bytes: Uint8Array; eol: boolean } | null; while ((readResult = await bufReader.readLine(false))) { reads++; actual = append(actual, readResult.bytes); } assertEquals(decoder.decode(actual), fixture); assertEquals(reads, 19); },});