deno.land / std@0.224.0 / io / read_string_delim_test.ts
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.// This code has been ported almost directly from Go's src/bytes/buffer_test.go// Copyright 2009 The Go Authors. All rights reserved. BSD license.// https://github.com/golang/go/blob/master/LICENSEimport { assertEquals } from "../assert/mod.ts";import { readStringDelim } from "./read_string_delim.ts";import { StringReader } from "./string_reader.ts";
Deno.test("[io] readStringDelim basic", async () => { const delim = "!#$%&()=~"; const exp = [ "", "a", "bc", "def", "", "!", "!#", "!#$%&()=", "#$%&()=~", "", "", ]; const str = exp.join(delim); const arr: string[] = []; for await (const v of readStringDelim(new StringReader(str), delim)) { arr.push(v); } assertEquals(arr, exp);});
Deno.test("[io] readStringDelim bigger delim than buf size", async () => { // 0123456789... const delim = Array.from({ length: 1025 }).map((_, i) => i % 10).join(""); const exp = ["", "a", "bc", "def", "01", "012345678", "123456789", "", ""]; const str = exp.join(delim); const arr: string[] = []; for await (const v of readStringDelim(new StringReader(str), delim)) { arr.push(v); } assertEquals(arr, exp);});
Deno.test("[io] readStringDelim delim=1213", async () => { const delim = "1213"; const exp = ["", "a", "bc", "def", "01", "012345678", "123456789", "", ""]; const str = exp.join(delim); const arr: string[] = []; for await (const v of readStringDelim(new StringReader(str), "1213")) { arr.push(v); } assertEquals(arr, exp);});
Version Info