summaryrefslogtreecommitdiff
path: root/fs/path
diff options
context:
space:
mode:
Diffstat (limited to 'fs/path')
-rw-r--r--fs/path/mod.ts4
-rw-r--r--fs/path/parse_format_test.ts67
2 files changed, 36 insertions, 35 deletions
diff --git a/fs/path/mod.ts b/fs/path/mod.ts
index 4ca630ed6..ffcc721a9 100644
--- a/fs/path/mod.ts
+++ b/fs/path/mod.ts
@@ -847,7 +847,7 @@ export const win32 = {
parse(path: string): ParsedPath {
assertPath(path);
- let ret = { root: "", dir: "", base: "", ext: "", name: "" } as ParsedPath;
+ let ret: ParsedPath = { root: "", dir: "", base: "", ext: "", name: "" };
const len = path.length;
if (len === 0) return ret;
@@ -1324,7 +1324,7 @@ export const posix = {
parse(path: string): ParsedPath {
assertPath(path);
- let ret = { root: "", dir: "", base: "", ext: "", name: "" } as ParsedPath;
+ let ret: ParsedPath = { root: "", dir: "", base: "", ext: "", name: "" };
if (path.length === 0) return ret;
let isAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
let start: number;
diff --git a/fs/path/parse_format_test.ts b/fs/path/parse_format_test.ts
index 29d840453..05327a139 100644
--- a/fs/path/parse_format_test.ts
+++ b/fs/path/parse_format_test.ts
@@ -79,6 +79,39 @@ const unixSpecialCaseFormatTests = [
[{}, ""]
];
+function checkParseFormat(path, paths): void {
+ paths.forEach(function(p) {
+ const element = p[0];
+ const output = path.parse(element);
+ assertEquals(typeof output.root, "string");
+ assertEquals(typeof output.dir, "string");
+ assertEquals(typeof output.base, "string");
+ assertEquals(typeof output.ext, "string");
+ assertEquals(typeof output.name, "string");
+ assertEquals(path.format(output), element);
+ assertEquals(output.rooroot, undefined);
+ assertEquals(output.dir, output.dir ? path.dirname(element) : "");
+ assertEquals(output.base, path.basename(element));
+ });
+}
+
+function checkSpecialCaseParseFormat(path, testCases): void {
+ testCases.forEach(function(testCase) {
+ const element = testCase[0];
+ const expect = testCase[1];
+ const output = path.parse(element);
+ Object.keys(expect).forEach(function(key) {
+ assertEquals(output[key], expect[key]);
+ });
+ });
+}
+
+function checkFormat(path, testCases): void {
+ testCases.forEach(function(testCase) {
+ assertEquals(path.format(testCase[0]), testCase[1]);
+ });
+}
+
test(function parseWin32() {
checkParseFormat(path.win32, winPaths);
checkSpecialCaseParseFormat(path.win32, winSpecialCaseParseTests);
@@ -116,6 +149,7 @@ const windowsTrailingTests = [
}
]
];
+
const posixTrailingTests = [
["./", { root: "", dir: "", base: ".", ext: "", name: "." }],
["//", { root: "/", dir: "/", base: "", ext: "", name: "" }],
@@ -127,39 +161,6 @@ const posixTrailingTests = [
]
];
-function checkParseFormat(path, paths) {
- paths.forEach(function(p) {
- const element = p[0];
- const output = path.parse(element);
- assertEquals(typeof output.root, "string");
- assertEquals(typeof output.dir, "string");
- assertEquals(typeof output.base, "string");
- assertEquals(typeof output.ext, "string");
- assertEquals(typeof output.name, "string");
- assertEquals(path.format(output), element);
- assertEquals(output.rooroot, undefined);
- assertEquals(output.dir, output.dir ? path.dirname(element) : "");
- assertEquals(output.base, path.basename(element));
- });
-}
-
-function checkSpecialCaseParseFormat(path, testCases) {
- testCases.forEach(function(testCase) {
- const element = testCase[0];
- const expect = testCase[1];
- const output = path.parse(element);
- Object.keys(expect).forEach(function(key) {
- assertEquals(output[key], expect[key]);
- });
- });
-}
-
-function checkFormat(path, testCases) {
- testCases.forEach(function(testCase) {
- assertEquals(path.format(testCase[0]), testCase[1]);
- });
-}
-
test(function parseTrailingWin32() {
windowsTrailingTests.forEach(function(p) {
const actual = path.win32.parse(p[0] as string);