Permalink
Browse files

Normalize absolute paths

This Fixes relativeFromDirectory, and presumably others.

Fixes #9 but ports that test suite to Jasmine
Fixes #10
  • Loading branch information...
kriskowal committed Dec 31, 2012
1 parent 140105e commit 9704904303ba781f4ac8af23bc577137e69b0cf4
Showing with 27 additions and 2 deletions.
  1. +1 −1 fs-boot.js
  2. +1 −1 fs-common.js
  3. +25 −0 spec/fs/relative-spec.js
View
@@ -181,7 +181,7 @@ exports.normal = function () {
}
for (var j = 0, jj = parts.length; j < jj; j++) {
var part = parts[j];
- if (part == "." || part == "") {
+ if (part === "." || part === "") {
} else if (part == "..") {
if (children.length) {
children.pop();
View
@@ -273,7 +273,7 @@ exports.update = function (exports, workingDirectory) {
exports.absolute = function (path) {
if (this.isAbsolute(path))
- return path;
+ return this.normal(path);
return this.join(workingDirectory(), path);
};
View
@@ -0,0 +1,25 @@
+
+var FS = require("../../fs");
+
+describe("relativeFromDirectory", function () {
+
+ it("should find the relative path from a directory", function () {
+
+ expect(FS.relativeFromDirectory("/a/b", "/a/b")).toBe("");
+ expect(FS.relativeFromDirectory("/a/b/", "/a/b")).toBe("");
+ expect(FS.relativeFromDirectory("/a/b", "/a/b/")).toBe("");
+ expect(FS.relativeFromDirectory("/a/b/", "/a/b/")).toBe("");
+
+ expect(FS.relativeFromDirectory("/a/b", "/a/b/c")).toBe("c");
+ expect(FS.relativeFromDirectory("/a/b/", "/a/b/c")).toBe("c");
+ expect(FS.relativeFromDirectory("/a/b", "/a/b/c/")).toBe("c");
+ expect(FS.relativeFromDirectory("/a/b/", "/a/b/c/")).toBe("c");
+
+ expect(FS.relativeFromDirectory("/a/b", "/a")).toBe("..");
+ expect(FS.relativeFromDirectory("/a/b/", "/a")).toBe("..");
+ expect(FS.relativeFromDirectory("/a/b", "/a/")).toBe("..");
+ expect(FS.relativeFromDirectory("/a/b/", "/a/")).toBe("..");
+
+ });
+
+});

0 comments on commit 9704904

Please sign in to comment.