|
| 1 | +var tape = require("tape"); |
| 2 | + |
| 3 | +var path = require(".."); |
| 4 | + |
| 5 | +tape.test("path", function(test) { |
| 6 | + |
| 7 | + test.ok(path.isAbsolute("X:\\some\\path\\file.js"), "should identify absolute windows paths"); |
| 8 | + test.ok(path.isAbsolute("/some/path/file.js"), "should identify absolute unix paths"); |
| 9 | + |
| 10 | + test.notOk(path.isAbsolute("some\\path\\file.js"), "should identify relative windows paths"); |
| 11 | + test.notOk(path.isAbsolute("some/path/file.js"), "should identify relative unix paths"); |
| 12 | + |
| 13 | + var paths = [ |
| 14 | + { |
| 15 | + actual: "X:\\some\\..\\.\\path\\\\file.js", |
| 16 | + normal: "X:/path/file.js", |
| 17 | + resolve: { |
| 18 | + origin: "X:/path/origin.js", |
| 19 | + expected: "X:/path/file.js" |
| 20 | + } |
| 21 | + }, { |
| 22 | + actual: "some\\..\\.\\path\\\\file.js", |
| 23 | + normal: "path/file.js", |
| 24 | + resolve: { |
| 25 | + origin: "X:/path/origin.js", |
| 26 | + expected: "X:/path/path/file.js" |
| 27 | + } |
| 28 | + }, { |
| 29 | + actual: "/some/.././path//file.js", |
| 30 | + normal: "/path/file.js", |
| 31 | + resolve: { |
| 32 | + origin: "/path/origin.js", |
| 33 | + expected: "/path/file.js" |
| 34 | + } |
| 35 | + }, { |
| 36 | + actual: "some/.././path//file.js", |
| 37 | + normal: "path/file.js", |
| 38 | + resolve: { |
| 39 | + origin: "", |
| 40 | + expected: "path/file.js" |
| 41 | + } |
| 42 | + }, { |
| 43 | + actual: ".././path//file.js", |
| 44 | + normal: "../path/file.js" |
| 45 | + }, { |
| 46 | + actual: "/.././path//file.js", |
| 47 | + normal: "/path/file.js" |
| 48 | + } |
| 49 | + ]; |
| 50 | + |
| 51 | + paths.forEach(function(p) { |
| 52 | + test.equal(path.normalize(p.actual), p.normal, "should normalize " + p.actual); |
| 53 | + if (p.resolve) { |
| 54 | + test.equal(path.resolve(p.resolve.origin, p.actual), p.resolve.expected, "should resolve " + p.actual); |
| 55 | + test.equal(path.resolve(p.resolve.origin, p.normal, true), p.resolve.expected, "should resolve " + p.normal + " (already normalized)"); |
| 56 | + } |
| 57 | + }); |
| 58 | + |
| 59 | + test.end(); |
| 60 | +}); |
0 commit comments