78 lines
12 KiB
JavaScript
78 lines
12 KiB
JavaScript
/// <reference path="../ts/typings/main.d.ts" />
|
|
var should = require("should");
|
|
var smartpath = require("../dist/index.js");
|
|
describe("smartpath", function () {
|
|
describe(".check", function () {
|
|
var filePathString = "./somedir/somefile.json";
|
|
var dirPathString = "./somedir/anotherdir";
|
|
var dirPathString2 = "./somedir/another.dir/";
|
|
describe(".isFile", function () {
|
|
it("should be true for a file path", function () {
|
|
smartpath.check.isFile(filePathString)
|
|
.should.be.true();
|
|
});
|
|
it("should be false for a directory path", function () {
|
|
smartpath.check.isFile(dirPathString)
|
|
.should.be.false();
|
|
smartpath.check.isFile(dirPathString2)
|
|
.should.be.false();
|
|
});
|
|
});
|
|
describe(".isDir", function () {
|
|
it("should be true for a directory path", function () {
|
|
smartpath.check.isDir(dirPathString)
|
|
.should.be.true();
|
|
smartpath.check.isDir(dirPathString2)
|
|
.should.be.true();
|
|
});
|
|
it("should be false for a file path", function () {
|
|
smartpath.check.isDir(filePathString)
|
|
.should.be.false();
|
|
});
|
|
});
|
|
});
|
|
describe(".transform", function () {
|
|
describe("toAbsolute()", function () {
|
|
var baseString = "/basedir";
|
|
var relativeString = "somedir/somefile.txt";
|
|
var relativeString2 = "anotherdir/anotherfile.txt";
|
|
var relativeArray = [relativeString, relativeString, relativeString2];
|
|
it("should make a string absolute", function () {
|
|
smartpath.transform.toAbsolute(relativeString).should.startWith("/");
|
|
smartpath.transform.toAbsolute(relativeString).should.endWith(relativeString);
|
|
smartpath.transform.toAbsolute(relativeString, baseString).should.equal("/basedir/somedir/somefile.txt");
|
|
});
|
|
it("should make an array of relative Strings an Array of absolute Strings", function () {
|
|
var absoluteArray = smartpath.transform.toAbsolute(relativeArray, baseString);
|
|
absoluteArray[2].should.startWith("/");
|
|
absoluteArray[2].should.endWith(relativeString2);
|
|
});
|
|
it("should return false if neither String nor Array", function () {
|
|
smartpath.transform.toAbsolute(3).should.be.false();
|
|
});
|
|
});
|
|
});
|
|
describe(".get", function () {
|
|
describe(".type()", function () {
|
|
it("should return 'url' for an URL", function () {
|
|
smartpath.get.type("https://push.rocks/some/url").should.equal("url");
|
|
smartpath.get.type("https://push.rocks/some/url").should.not.equal("local");
|
|
});
|
|
it("should return 'path' for a Path", function () {
|
|
smartpath.get.type("/some/absolute/path/").should.equal("local");
|
|
smartpath.get.type("./some/relative/path/").should.not.equal("url");
|
|
});
|
|
});
|
|
describe(".get()", function () {
|
|
it("should a absolute path for an home relative URL", function () {
|
|
console.log(smartpath.get.home("~/test"));
|
|
});
|
|
it("should return the home directory path when no argument is specified", function () {
|
|
console.log(smartpath.get.home());
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsZ0RBQWdEO0FBQ2hELElBQUksTUFBTSxHQUFHLE9BQU8sQ0FBQyxRQUFRLENBQUMsQ0FBQztBQUMvQixJQUFJLFNBQVMsR0FBRyxPQUFPLENBQUMsa0JBQWtCLENBQUMsQ0FBQztBQUU1QyxRQUFRLENBQUMsV0FBVyxFQUFDO0lBQ2pCLFFBQVEsQ0FBQyxRQUFRLEVBQUM7UUFDZCxJQUFJLGNBQWMsR0FBRyx5QkFBeUIsQ0FBQTtRQUM5QyxJQUFJLGFBQWEsR0FBRyxzQkFBc0IsQ0FBQTtRQUMxQyxJQUFJLGNBQWMsR0FBRyx3QkFBd0IsQ0FBQTtRQUM3QyxRQUFRLENBQUMsU0FBUyxFQUFDO1lBQ2YsRUFBRSxDQUFDLGdDQUFnQyxFQUFDO2dCQUNoQyxTQUFTLENBQUMsS0FBSyxDQUFDLE1BQU0sQ0FBQyxjQUFjLENBQUM7cUJBQ2pDLE1BQU0sQ0FBQyxFQUFFLENBQUMsSUFBSSxFQUFFLENBQUM7WUFDMUIsQ0FBQyxDQUFDLENBQUM7WUFDSCxFQUFFLENBQ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ChcInNob3VsZCBiZSBmYWxzZSBmb3IgYSBkaXJlY3RvcnkgcGF0aFwiLGZ1bmN0aW9uKCl7XG4gICAgICAgICAgICAgICAgc21hcnRwYXRoLmNoZWNrLmlzRmlsZShkaXJQYXRoU3RyaW5nKVxuICAgICAgICAgICAgICAgICAgICAuc2hvdWxkLmJlLmZhbHNlKCk7XG4gICAgICAgICAgICAgICAgc21hcnRwYXRoLmNoZWNrLmlzRmlsZShkaXJQYXRoU3RyaW5nMilcbiAgICAgICAgICAgICAgICAgICAgLnNob3VsZC5iZS5mYWxzZSgpO1xuICAgICAgICAgICAgfSk7XG4gICAgICAgIH0pO1xuICAgICAgICBkZXNjcmliZShcIi5pc0RpclwiLGZ1bmN0aW9uKCl7XG4gICAgICAgICAgICBpdChcInNob3VsZCBiZSB0cnVlIGZvciBhIGRpcmVjdG9yeSBwYXRoXCIsZnVuY3Rpb24oKXtcbiAgICAgICAgICAgICAgICBzbWFydHBhdGguY2hlY2suaXNEaXIoZGlyUGF0aFN0cmluZylcbiAgICAgICAgICAgICAgICAgICAgLnNob3VsZC5iZS50cnVlKCk7XG4gICAgICAgICAgICAgICAgc21hcnRwYXRoLmNoZWNrLmlzRGlyKGRpclBhdGhTdHJpbmcyKVxuICAgICAgICAgICAgICAgICAgICAuc2hvdWxkLmJlLnRydWUoKTtcbiAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgaXQoXCJzaG91bGQgYmUgZmFsc2UgZm9yIGEgZmlsZSBwYXRoXCIsZnVuY3Rpb24oKXtcbiAgICAgICAgICAgICAgICBzbWFydHBhdGguY2hlY2suaXNEaXIoZmlsZVBhdGhTdHJpbmcpXG4gICAgICAgICAgICAgICAgICAgIC5zaG91bGQuYmUuZmFsc2UoKTtcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9KTtcbiAgICB9KTtcbiAgICBkZXNjcmliZShcIi50cmFuc2Zvcm1cIixmdW5jdGlvbigpe1xuICAgICAgICBkZXNjcmliZShcInRvQWJzb2x1d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C5lcXVhbChcImxvY2FsXCIpO1xuICAgICAgICAgICAgICAgIHNtYXJ0cGF0aC5nZXQudHlwZShcIi4vc29tZS9yZWxhdGl2ZS9wYXRoL1wiKS5zaG91bGQubm90LmVxdWFsKFwidXJsXCIpO1xuICAgICAgICAgICAgfSk7XG4gICAgICAgIH0pO1xuICAgICAgICBkZXNjcmliZShcIi5nZXQoKVwiLGZ1bmN0aW9uKCl7XG4gICAgICAgICAgICBpdChcInNob3VsZCBhIGFic29sdXRlIHBhdGggZm9yIGFuIGhvbWUgcmVsYXRpdmUgVVJMXCIsZnVuY3Rpb24oKXtcbiAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhzbWFydHBhdGguZ2V0LmhvbWUoXCJ+L3Rlc3RcIikpO1xuICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICBpdChcInNob3VsZCByZXR1cm4gdGhlIGhvbWUgZGlyZWN0b3J5IHBhdGggd2hlbiBubyBhcmd1bWVudCBpcyBzcGVjaWZpZWRcIixmdW5jdGlvbigpe1xuICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKHNtYXJ0cGF0aC5nZXQuaG9tZSgpKTtcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9KTtcbiAgICB9KTtcbn0pO1xuIl19
|