Skip to content

Commit

Permalink
add getcwd function and add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
puritys committed Nov 26, 2014
1 parent cde205e commit f2ffc57
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Completed PHP Method
* parse_str : parse "a=b&c=d" to {"a": "b", "c": "d"}
* array_merge
* clone: clone a object or array
* getcwd

<h2>Install phplike</h2>

Expand Down
5 changes: 5 additions & 0 deletions nodejs/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ exports.date = function (format)
return format;
}/*}}}*/

// Get current working directory (path).
exports.getcwd = function () {//{{{
return process.cwd();
}//}}}

/*
* @param obj
* @param prefix space
Expand Down
2 changes: 1 addition & 1 deletion nodejs/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ exports.mkdir = function(dirName) {/*{{{*/
try{
fs.mkdirSync(dir);
} catch(e) {
print_r(e);
console.log(e);
throw e
}
}
Expand Down
7 changes: 7 additions & 0 deletions tests/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,11 @@ describe('Test function: clone', function() {

});

describe('Test function: getcwd', function() {
it('string to object', function() {
var res = phplikeMod.getcwd();
assert.equal("/", res.substring(0, 1));
})

});

18 changes: 18 additions & 0 deletions tests/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,24 @@ describe('dir handle', function () {
phplikeMod.rmdir("test_dir");
});

it('create dir from "/"', function () {
var cwd = phplikeMod.getcwd();
phplikeMod.mkdir(cwd + "/test_dir");
var isDir = phplikeMod.is_dir(cwd + "/test_dir");
assert.equal(true, isDir);
phplikeMod.rmdir(cwd + "/test_dir");
});

it('get exception when create dir in no permission path.', function () {
try {
phplikeMod.mkdir("/admin");
assert.equal(false, true);
} catch (e) {
assert.equal(true, true);
}
});


it('delete dir - force', function() {
var isForce = true;
phplikeMod.mkdir(dir);
Expand Down

0 comments on commit f2ffc57

Please sign in to comment.