-
Notifications
You must be signed in to change notification settings - Fork 576
/
copy_n_test.ts
37 lines (31 loc) · 1.17 KB
/
copy_n_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
27
28
29
30
31
32
33
34
35
36
37
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "../testing/asserts.ts";
import { copyN } from "./copy_n.ts";
import { Buffer } from "./buffer.ts";
import { StringReader } from "./string_reader.ts";
Deno.test("testCopyN1", async function () {
const w = new Buffer();
const r = new StringReader("abcdefghij");
const n = await copyN(r, w, 3);
assertEquals(n, 3);
assertEquals(new TextDecoder().decode(w.bytes()), "abc");
});
Deno.test("testCopyN2", async function () {
const w = new Buffer();
const r = new StringReader("abcdefghij");
const n = await copyN(r, w, 11);
assertEquals(n, 10);
assertEquals(new TextDecoder().decode(w.bytes()), "abcdefghij");
});
Deno.test("copyNWriteAllData", async function () {
const tmpDir = await Deno.makeTempDir();
const filepath = `${tmpDir}/data`;
const file = await Deno.open(filepath, { create: true, write: true });
const size = 16 * 1024 + 1;
const data = "a".repeat(32 * 1024);
const r = new StringReader(data);
const n = await copyN(r, file, size); // Over max file possible buffer
file.close();
await Deno.remove(filepath);
assertEquals(n, size);
});