Repository navigation
Expand file tree
/
Copy pathsed.js
More file actions
58 lines (42 loc) · 1.34 KB
/
Copy pathsed.js
File metadata and controls
58 lines (42 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var shell = require('..');
var assert = require('assert'),
path = require('path'),
fs = require('fs');
// Node shims for < v0.7
fs.existsSync = fs.existsSync || path.existsSync;
shell.config.silent = true;
function numLines(str) {
return typeof str === 'string' ? str.match(/\n/g).length : 0;
}
shell.rm('-rf', 'tmp');
shell.mkdir('tmp');
//
// Invalids
//
shell.sed();
assert.ok(shell.error());
shell.sed(/asdf/g); // too few args
assert.ok(shell.error());
shell.sed(/asdf/g, 'nada'); // too few args
assert.ok(shell.error());
assert.equal(fs.existsSync('/asdfasdf'), false); // sanity check
shell.sed(/asdf/g, 'nada', '/asdfasdf'); // no such file
assert.ok(shell.error());
//
// Valids
//
shell.cp('-f', 'resources/file1', 'tmp/file1');
var result = shell.sed('test1', 'hello', 'tmp/file1'); // search string
assert.equal(shell.error(), null);
assert.equal(result, 'hello');
var result = shell.sed(/test1/, 'hello', 'tmp/file1'); // search regex
assert.equal(shell.error(), null);
assert.equal(result, 'hello');
var result = shell.sed(/test1/, 1234, 'tmp/file1'); // numeric replacement
assert.equal(shell.error(), null);
assert.equal(result, '1234');
var result = shell.sed('-i', /test1/, 'hello', 'tmp/file1');
assert.equal(shell.error(), null);
assert.equal(result, 'hello');
assert.equal(shell.cat('tmp/file1'), 'hello');
shell.exit(123);