forked from denoland/deno_std
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
std: Move fs/path to the top-level (denoland/deno#3100)
- Loading branch information
Showing
57 changed files
with
323 additions
and
305 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
const { cwd } = Deno; | ||
import { test, runIfMain } from "../testing/mod.ts"; | ||
import { assert, assertEquals } from "../testing/asserts.ts"; | ||
import { | ||
isWindows, | ||
join, | ||
joinGlobs, | ||
normalize, | ||
relative | ||
} from "../path/mod.ts"; | ||
import { | ||
ExpandGlobOptions, | ||
expandGlob, | ||
expandGlobSync | ||
} from "./expand_glob.ts"; | ||
|
||
async function expandGlobArray( | ||
globString: string, | ||
options: ExpandGlobOptions | ||
): Promise<string[]> { | ||
const paths: string[] = []; | ||
for await (const { filename } of expandGlob(globString, options)) { | ||
paths.push(filename); | ||
} | ||
paths.sort(); | ||
const pathsSync = [...expandGlobSync(globString, options)].map( | ||
({ filename }): string => filename | ||
); | ||
pathsSync.sort(); | ||
assertEquals(paths, pathsSync); | ||
const root = normalize(options.root || cwd()); | ||
for (const path of paths) { | ||
assert(path.startsWith(root)); | ||
} | ||
const relativePaths = paths.map( | ||
(path: string): string => relative(root, path) || "." | ||
); | ||
relativePaths.sort(); | ||
return relativePaths; | ||
} | ||
|
||
function urlToFilePath(url: URL): string { | ||
// Since `new URL('file:https:///C:/a').pathname` is `/C:/a`, remove leading slash. | ||
return url.pathname.slice(url.protocol == "file:" && isWindows ? 1 : 0); | ||
} | ||
|
||
const EG_OPTIONS: ExpandGlobOptions = { | ||
root: urlToFilePath(new URL(join("testdata", "glob"), import.meta.url)), | ||
includeDirs: true, | ||
extended: false, | ||
globstar: false | ||
}; | ||
|
||
test(async function expandGlobWildcard(): Promise<void> { | ||
const options = EG_OPTIONS; | ||
assertEquals(await expandGlobArray("*", options), [ | ||
"abc", | ||
"abcdef", | ||
"abcdefghi", | ||
"subdir" | ||
]); | ||
}); | ||
|
||
test(async function expandGlobTrailingSeparator(): Promise<void> { | ||
const options = EG_OPTIONS; | ||
assertEquals(await expandGlobArray("*/", options), ["subdir"]); | ||
}); | ||
|
||
test(async function expandGlobParent(): Promise<void> { | ||
const options = EG_OPTIONS; | ||
assertEquals(await expandGlobArray("subdir/../*", options), [ | ||
"abc", | ||
"abcdef", | ||
"abcdefghi", | ||
"subdir" | ||
]); | ||
}); | ||
|
||
test(async function expandGlobExt(): Promise<void> { | ||
const options = { ...EG_OPTIONS, extended: true }; | ||
assertEquals(await expandGlobArray("abc?(def|ghi)", options), [ | ||
"abc", | ||
"abcdef" | ||
]); | ||
assertEquals(await expandGlobArray("abc*(def|ghi)", options), [ | ||
"abc", | ||
"abcdef", | ||
"abcdefghi" | ||
]); | ||
assertEquals(await expandGlobArray("abc+(def|ghi)", options), [ | ||
"abcdef", | ||
"abcdefghi" | ||
]); | ||
assertEquals(await expandGlobArray("abc@(def|ghi)", options), ["abcdef"]); | ||
assertEquals(await expandGlobArray("abc{def,ghi}", options), ["abcdef"]); | ||
assertEquals(await expandGlobArray("abc!(def|ghi)", options), ["abc"]); | ||
}); | ||
|
||
test(async function expandGlobGlobstar(): Promise<void> { | ||
const options = { ...EG_OPTIONS, globstar: true }; | ||
assertEquals( | ||
await expandGlobArray(joinGlobs(["**", "abc"], options), options), | ||
["abc", join("subdir", "abc")] | ||
); | ||
}); | ||
|
||
test(async function expandGlobGlobstarParent(): Promise<void> { | ||
const options = { ...EG_OPTIONS, globstar: true }; | ||
assertEquals( | ||
await expandGlobArray(joinGlobs(["subdir", "**", ".."], options), options), | ||
["."] | ||
); | ||
}); | ||
|
||
test(async function expandGlobIncludeDirs(): Promise<void> { | ||
const options = { ...EG_OPTIONS, includeDirs: false }; | ||
assertEquals(await expandGlobArray("subdir", options), []); | ||
}); | ||
|
||
runIfMain(import.meta); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.