shell-test.js
1.49 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
59
60
var assert = require('chai').assert,
shell = require('..').shell;
/**
* Mocha BDD interface.
*/
/** @name describe @function */
/** @name it @function */
/** @name before @function */
/** @name after @function */
/** @name beforeEach @function */
/** @name afterEach @function */
describe('shell', function() {
describe('escape()', function() {
var escape = shell.escape;
it('Should wrap values with spaces in double quotes', function() {
assert.equal(escape('asd abc'), '"asd abc"');
});
it('Should escape double quote "', function() {
assert.equal(escape('"asd'), '\\"asd');
});
it("Should escape single quote '", function() {
assert.equal(escape("'asd"), "\\'asd");
});
it('Should escape backslash \\', function() {
assert.equal(escape('\\asd'), '\\\\asd');
});
it('Should escape dollar $', function() {
assert.equal(escape('$asd'), '\\$asd');
});
it('Should escape backtick `', function() {
assert.equal(escape('`asd'), '\\`asd');
});
});
describe('unescape()', function() {
var unescape = shell.unescape;
it('Should strip double quotes at the both ends', function() {
assert.equal(unescape('"asd"'), 'asd');
});
it('Should not strip escaped double quotes at the both ends', function() {
assert.equal(unescape('\\"asd\\"'), '"asd"');
});
});
});