From dc69b03339cc75af1daa70700d1283fa33c22c3b Mon Sep 17 00:00:00 2001 From: Casper Beyer Date: Thu, 3 Jun 2021 22:14:37 +0800 Subject: feat(runtime): support URL overloads for Deno.rename/Deno.renameSync (#10512) --- cli/tests/unit/rename_test.ts | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'cli/tests') diff --git a/cli/tests/unit/rename_test.ts b/cli/tests/unit/rename_test.ts index 09633aed7..711b63aa7 100644 --- a/cli/tests/unit/rename_test.ts +++ b/cli/tests/unit/rename_test.ts @@ -1,5 +1,11 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals, assertThrows, unitTest } from "./test_util.ts"; +import { + assert, + assertEquals, + assertThrows, + pathToAbsoluteFileUrl, + unitTest, +} from "./test_util.ts"; function assertMissing(path: string): void { let caughtErr = false; @@ -40,6 +46,22 @@ unitTest( }, ); +unitTest( + { perms: { read: true, write: true } }, + function renameSyncWithURL(): void { + const testDir = Deno.makeTempDirSync(); + const oldpath = testDir + "/oldpath"; + const newpath = testDir + "/newpath"; + Deno.mkdirSync(oldpath); + Deno.renameSync( + pathToAbsoluteFileUrl(oldpath), + pathToAbsoluteFileUrl(newpath), + ); + assertDirectory(newpath); + assertMissing(oldpath); + }, +); + unitTest( { perms: { read: false, write: true } }, function renameSyncReadPerm(): void { @@ -75,6 +97,22 @@ unitTest( }, ); +unitTest( + { perms: { read: true, write: true } }, + async function renameWithURL(): Promise { + const testDir = Deno.makeTempDirSync(); + const oldpath = testDir + "/oldpath"; + const newpath = testDir + "/newpath"; + Deno.mkdirSync(oldpath); + await Deno.rename( + pathToAbsoluteFileUrl(oldpath), + pathToAbsoluteFileUrl(newpath), + ); + assertDirectory(newpath); + assertMissing(oldpath); + }, +); + function readFileString(filename: string): string { const dataRead = Deno.readFileSync(filename); const dec = new TextDecoder("utf-8"); -- cgit v1.2.3