smartpath/test/test.js

77 lines
7.4 KiB
JavaScript
Raw Normal View History

2016-06-14 03:16:43 +00:00
"use strict";
require("typings-test");
require("should");
2016-09-30 15:08:09 +00:00
let smartpath = require("../dist/index.js");
2016-03-12 08:36:30 +00:00
describe("smartpath", function () {
2016-04-30 09:02:03 +00:00
describe(".check", function () {
2016-09-30 15:08:09 +00:00
let filePathString = "./somedir/somefile.json";
let dirPathString = "./somedir/anotherdir";
let dirPathString2 = "./somedir/another.dir/";
2016-04-30 09:02:03 +00:00
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();
});
});
});
2016-03-20 17:59:30 +00:00
describe(".transform", function () {
describe("toAbsolute()", function () {
2016-09-30 15:08:09 +00:00
let baseString = "/basedir";
let relativeString = "somedir/somefile.txt";
let relativeString2 = "anotherdir/anotherfile.txt";
let relativeArray = [relativeString, relativeString, relativeString2];
2016-03-20 17:59:30 +00:00
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 () {
2016-09-30 15:08:09 +00:00
let absoluteArray = smartpath.transform.toAbsolute(relativeArray, baseString);
2016-03-20 17:59:30 +00:00
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();
});
2016-03-12 08:36:30 +00:00
});
2016-03-20 17:59:30 +00:00
});
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");
});
2016-03-12 08:36:30 +00:00
});
2016-04-04 14:25:17 +00:00
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());
});
});
2016-03-12 08:36:30 +00:00
});
});
2016-09-30 15:08:09 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFzQjtBQUN0QixrQkFBZ0I7QUFDaEIsSUFBSSxTQUFTLEdBQUcsT0FBTyxDQUFDLGtCQUFrQixDQUFDLENBQUM7QUFFNUMsUUFBUSxDQUFDLFdBQVcsRUFBQztJQUNqQixRQUFRLENBQUMsUUFBUSxFQUFDO1FBQ2QsSUFBSSxjQUFjLEdBQUcseUJBQXlCLENBQUE7UUFDOUMsSUFBSSxhQUFhLEdBQUcsc0JBQXNCLENBQUE7UUFDMUMsSUFBSSxjQUFjLEdBQUcsd0JBQXdCLENBQUE7UUFDN0MsUUFBUSxDQUFDLFNBQVMsRUFBQztZQUNmLEVBQUUsQ0FBQyxnQ0FBZ0MsRUFBQztnQkFDaEMsU0FBUyxDQUFDLEtBQUssQ0FBQyxNQUFNLENBQUMsY0FBYyxDQUFDO3FCQUNqQyxNQUFNLENBQUMsRUFBRSxDQUFDLElBQUksRUFBRSxDQUFDO1lBQzFCLENBQUMsQ0FBQyxDQUFDO1lBQ0gsRUFBRSxDQUFDLHNDQUFzQyxFQUFDO2d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