GeezerVison is showing github.com — path: remove dead code in favor of unit tests · nodejs/node@4750a2a
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/path.js +1-11Lines changed: 1 addition & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -76,7 +76,7 @@ function win32SplitPath(filename) { | 76 | 76 | // Separate device+slash from tail | 77 | 77 | var result = splitDeviceRe.exec(filename), | 78 | 78 | device = (result[1] || '') + (result[2] || ''), | 79 | | - tail = result[3] || ''; | | 79 | + tail = result[3]; | 80 | 80 | // Split the tail into dir, basename and extension | 81 | 81 | var result2 = splitTailRe.exec(tail), | 82 | 82 | dir = result2[1], | @@ -386,9 +386,6 @@ win32.parse = function(pathString) { | 386 | 386 | assertPath(pathString); | 387 | 387 |
| 388 | 388 | var allParts = win32SplitPath(pathString); | 389 | | - if (!allParts || allParts.length !== 4) { | 390 | | - throw new TypeError("Invalid path '" + pathString + "'"); | 391 | | - } | 392 | 389 | return { | 393 | 390 | root: allParts[0], | 394 | 391 | dir: allParts[0] + allParts[1].slice(0, -1), | @@ -590,13 +587,6 @@ posix.parse = function(pathString) { | 590 | 587 | assertPath(pathString); | 591 | 588 |
| 592 | 589 | var allParts = posixSplitPath(pathString); | 593 | | - if (!allParts || allParts.length !== 4) { | 594 | | - throw new TypeError("Invalid path '" + pathString + "'"); | 595 | | - } | 596 | | - allParts[1] = allParts[1] || ''; | 597 | | - allParts[2] = allParts[2] || ''; | 598 | | - allParts[3] = allParts[3] || ''; | 599 | | - | 600 | 590 | return { | 601 | 591 | root: allParts[0], | 602 | 592 | dir: allParts[0] + allParts[1].slice(0, -1), | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-path-parse-format.js +9-4Lines changed: 9 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -9,6 +9,7 @@ var winPaths = [ | 9 | 9 | '\\foo\\C:', | 10 | 10 | 'file', | 11 | 11 | '.\\file', | | 12 | + '', | 12 | 13 |
| 13 | 14 | // unc | 14 | 15 | '\\\\server\\share\\file_path', | @@ -32,7 +33,8 @@ var unixPaths = [ | 32 | 33 | 'file', | 33 | 34 | '.\\file', | 34 | 35 | './file', | 35 | | - 'C:\\foo' | | 36 | + 'C:\\foo', | | 37 | + '' | 36 | 38 | ]; | 37 | 39 |
| 38 | 40 | var unixSpecialCaseFormatTests = [ | @@ -52,8 +54,6 @@ var errors = [ | 52 | 54 | message: /Path must be a string. Received 1/}, | 53 | 55 | {method: 'parse', input: [], | 54 | 56 | message: /Path must be a string. Received undefined/}, | 55 | | - // {method: 'parse', input: [''], | 56 | | - // message: /Invalid path/}, // omitted because it's hard to trigger! | 57 | 57 | {method: 'format', input: [null], | 58 | 58 | message: /Parameter 'pathObject' must be an object, not/}, | 59 | 59 | {method: 'format', input: [''], | @@ -93,8 +93,13 @@ function checkErrors(path) { | 93 | 93 | } | 94 | 94 |
| 95 | 95 | function checkParseFormat(path, paths) { | 96 | | - paths.forEach(function(element, index, array) { | | 96 | + paths.forEach(function(element) { | 97 | 97 | var output = path.parse(element); | | 98 | + assert.strictEqual(typeof output.root, 'string'); | | 99 | + assert.strictEqual(typeof output.dir, 'string'); | | 100 | + assert.strictEqual(typeof output.base, 'string'); | | 101 | + assert.strictEqual(typeof output.ext, 'string'); | | 102 | + assert.strictEqual(typeof output.name, 'string'); | 98 | 103 | assert.strictEqual(path.format(output), element); | 99 | 104 | assert.strictEqual(output.dir, output.dir ? path.dirname(element) : ''); | 100 | 105 | assert.strictEqual(output.base, path.basename(element)); | |
|