forked from jamesshore/lets_code_javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopd.js
More file actions
118 lines (97 loc) · 2.85 KB
/
popd.js
File metadata and controls
118 lines (97 loc) · 2.85 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
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;
var root = path.resolve(), trail;
function reset() {
shell.dirs('-c');
shell.cd(root);
}
// Valid
shell.pushd('resources/pushd');
trail = shell.popd();
assert.equal(shell.error(), null);
assert.equal(process.cwd(), trail[0]);
assert.deepEqual(trail, [ root ]);
shell.pushd('resources/pushd');
shell.pushd('a');
trail = shell.popd();
assert.equal(shell.error(), null);
assert.equal(process.cwd(), trail[0]);
assert.deepEqual(trail, [
path.resolve(root, 'resources/pushd'),
root
]);
shell.pushd('b');
trail = shell.popd();
assert.equal(shell.error(), null);
assert.equal(process.cwd(), trail[0]);
assert.deepEqual(trail, [
path.resolve(root, 'resources/pushd'),
root
]);
shell.pushd('b');
shell.pushd('c');
trail = shell.popd();
assert.equal(shell.error(), null);
assert.equal(process.cwd(), trail[0]);
assert.deepEqual(trail, [
path.resolve(root, 'resources/pushd/b'),
path.resolve(root, 'resources/pushd'),
root
]);
trail = shell.popd();
assert.equal(shell.error(), null);
assert.equal(process.cwd(), trail[0]);
assert.deepEqual(trail, [
path.resolve(root, 'resources/pushd'),
root
]);
trail = shell.popd();
assert.equal(shell.error(), null);
assert.equal(trail.length, 1);
assert.equal(process.cwd(), trail[0]);
assert.deepEqual(trail, [ root ]);
// Valid by index
shell.pushd('resources/pushd');
trail = shell.popd('+0');
assert.equal(shell.error(), null);
assert.equal(process.cwd(), trail[0]);
assert.deepEqual(trail, [ root ]);
shell.pushd('resources/pushd');
trail = shell.popd('+1');
assert.equal(shell.error(), null);
assert.equal(process.cwd(), trail[0]);
assert.deepEqual(trail, [ path.resolve(root, 'resources/pushd') ]);
reset(); shell.pushd('resources/pushd');
trail = shell.popd('-0');
assert.equal(shell.error(), null);
assert.equal(process.cwd(), trail[0]);
assert.deepEqual(trail, [ path.resolve(root, 'resources/pushd') ]);
reset(); shell.pushd('resources/pushd');
trail = shell.popd('-1');
assert.equal(shell.error(), null);
assert.equal(process.cwd(), trail[0]);
assert.deepEqual(trail, [ root ]);
reset(); shell.pushd('resources/pushd');
trail = shell.popd('-n');
assert.equal(shell.error(), null);
assert.equal(process.cwd(), trail[0]);
assert.deepEqual(trail, [ path.resolve(root, 'resources/pushd') ]);
// Invalid
trail = shell.popd();
assert.ok(shell.error('popd: directory stack empty\n'));
// Test that the root dir is not stored
shell.cd('resources/pushd');
shell.pushd('b');
trail = shell.popd();
assert.equal(shell.error(), null);
assert.equal(trail[0], path.resolve(root, 'resources/pushd'));
assert.equal(process.cwd(), trail[0]);
shell.popd();
assert.ok(shell.error(), null);
shell.cd(root);
shell.exit(123);