-
Notifications
You must be signed in to change notification settings - Fork 621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(path/unstable): support URL
in first arg of join()
#5863
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,9 @@ import { join } from "./join.ts"; | |
|
||
const backslashRE = /\\/g; | ||
|
||
const joinTests = | ||
type TestCase = [string[] | [URL, ...string[]], string]; | ||
|
||
const joinTests: TestCase[] = | ||
// arguments result | ||
[ | ||
[[".", "x/b", "..", "/b/c.js"], "x/b/c.js"], | ||
|
@@ -56,10 +58,18 @@ const joinTests = | |
[["/", "", "/foo"], "/foo"], | ||
[["", "/", "foo"], "/foo"], | ||
[["", "/", "/foo"], "/foo"], | ||
|
||
// URLs | ||
[[new URL("file:///"), "x/b", "..", "/b/c.js"], "/x/b/c.js"], | ||
[[new URL("file:///foo"), "../../../bar"], "/bar"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first test case looks good. But I'd expect the result of the 2nd test case to be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I tested with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How did you test it? The below prints import { join } from "node:path";
console.log(join("/foo", "../../../bar")); BTW |
||
[ | ||
[new URL("file:///foo"), "bar", "baz/asdf", "quux", ".."], | ||
"/foo/bar/baz/asdf", | ||
], | ||
]; | ||
|
||
// Windows-specific join tests | ||
const windowsJoinTests = [ | ||
const windowsJoinTests: TestCase[] = [ | ||
// arguments result | ||
// UNC path expected | ||
[["//foo/bar"], "\\\\foo\\bar\\"], | ||
|
@@ -106,24 +116,28 @@ const windowsJoinTests = [ | |
[["c:.", "file"], "c:file"], | ||
[["c:", "/"], "c:\\"], | ||
[["c:", "file"], "c:\\file"], | ||
// URLs | ||
[[new URL("file:///c:")], "c:\\"], | ||
[[new URL("file:///c:"), "file"], "c:\\file"], | ||
[[new URL("file:///c:/"), "file"], "c:\\file"], | ||
]; | ||
|
||
Deno.test("posix.join()", function () { | ||
joinTests.forEach(function (p) { | ||
const _p = p[0] as string[]; | ||
const _p = p[0]; | ||
const actual = posix.join.apply(null, _p); | ||
assertEquals(actual, p[1]); | ||
}); | ||
}); | ||
|
||
Deno.test("windows.join()", function () { | ||
joinTests.forEach(function (p) { | ||
const _p = p[0] as string[]; | ||
const _p = p[0]; | ||
const actual = windows.join.apply(null, _p).replace(backslashRE, "/"); | ||
assertEquals(actual, p[1]); | ||
}); | ||
windowsJoinTests.forEach(function (p) { | ||
const _p = p[0] as string[]; | ||
const _p = p[0]; | ||
const actual = windows.join.apply(null, _p); | ||
assertEquals(actual, p[1]); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current tests seem a little bare. Could we please add the tests from the examples?