mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
9253dcbd87
* refactor(io): `copy` - deduplicate logic by importing `writeAll` - add JSDoc description of returned value * add test step for return value
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
import { copy } from "./copy.ts";
|
|
import { assertEquals, assertStrictEquals } from "@std/assert";
|
|
|
|
const SRC_PATH = "./io/testdata/copy-src.txt";
|
|
const DST_PATH = "./io/testdata/copy-dst.txt";
|
|
|
|
Deno.test("copy()", async (t) => {
|
|
try {
|
|
using srcFile = await Deno.open(SRC_PATH);
|
|
using dstFile = await Deno.open(DST_PATH, {
|
|
create: true,
|
|
write: true,
|
|
});
|
|
|
|
const actualByteCount = await copy(srcFile, dstFile);
|
|
|
|
await t.step(
|
|
"number of copied bytes equals source size",
|
|
async () => {
|
|
const fileInfo = await srcFile.stat();
|
|
const expectedByteCount = fileInfo.size;
|
|
assertStrictEquals(actualByteCount, expectedByteCount);
|
|
},
|
|
);
|
|
|
|
await t.step(
|
|
"source and destination bytes are equal",
|
|
async () => {
|
|
const srcOutput = await Deno.readFile(SRC_PATH);
|
|
const dstOutput = await Deno.readFile(DST_PATH);
|
|
assertEquals(srcOutput, dstOutput);
|
|
},
|
|
);
|
|
} finally {
|
|
await Deno.remove(DST_PATH);
|
|
}
|
|
});
|