mirror of
https://github.com/shelljs/shelljs.git
synced 2026-01-18 16:03:37 +00:00
Merge pull request #276 from TimothyGu/to
feat(end/round): make to and toEnd chainable
This commit is contained in:
commit
49b60cd59e
@ -22,6 +22,7 @@ function _to(options, file) {
|
||||
|
||||
try {
|
||||
fs.writeFileSync(file, this.toString(), 'utf8');
|
||||
return this;
|
||||
} catch(e) {
|
||||
common.error('could not write to file (code '+e.code+'): '+file, true);
|
||||
}
|
||||
|
||||
@ -22,6 +22,7 @@ function _toEnd(options, file) {
|
||||
|
||||
try {
|
||||
fs.appendFileSync(file, this.toString(), 'utf8');
|
||||
return this;
|
||||
} catch(e) {
|
||||
common.error('could not append to file (code '+e.code+'): '+file, true);
|
||||
}
|
||||
|
||||
@ -23,9 +23,12 @@ assert.ok(shell.error());
|
||||
// Valids
|
||||
//
|
||||
|
||||
'hello world'.to('tmp/to1');
|
||||
'hello world'.to('tmp/to1').to('tmp/to2');
|
||||
var result = shell.cat('tmp/to1');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result, 'hello world');
|
||||
result = shell.cat('tmp/to2');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result, 'hello world');
|
||||
|
||||
shell.exit(123);
|
||||
|
||||
@ -22,11 +22,15 @@ assert.ok(shell.error());
|
||||
//
|
||||
|
||||
assert.equal(fs.existsSync('tmp/toEnd1'), false); //Check file toEnd() creates does not already exist
|
||||
assert.equal(fs.existsSync('tmp/toEnd2'), false);
|
||||
'hello '.toEnd('tmp/toEnd1');
|
||||
assert.equal(fs.existsSync('tmp/toEnd1'), true); //Check that file was created
|
||||
'world'.toEnd('tmp/toEnd1'); //Write some more to the file
|
||||
'world'.toEnd('tmp/toEnd1').toEnd('tmp/toEnd2'); //Write some more to the file
|
||||
var result = shell.cat('tmp/toEnd1');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result, 'hello world'); //Check that the result is what we expect
|
||||
result = shell.cat('tmp/toEnd2');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result, 'world'); //Check that the result is what we expect
|
||||
|
||||
shell.exit(123);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user