forked from shelljs/shelljs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort.js
More file actions
99 lines (82 loc) · 2.44 KB
/
Copy pathsort.js
File metadata and controls
99 lines (82 loc) · 2.44 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
import fs from 'fs';
import test from 'ava';
import shell from '..';
shell.config.silent = true;
const doubleSorted = shell.cat('resources/sort/sorted')
.trimRight()
.split('\n')
.reduce((prev, cur) => prev.concat([cur, cur]), [])
.join('\n') + '\n';
//
// Invalids
//
test('no args', t => {
const result = shell.sort();
t.truthy(shell.error());
t.truthy(result.code);
});
test('file does not exist', t => {
t.falsy(fs.existsSync('/asdfasdf')); // sanity check
const result = shell.sort('/adsfasdf');
t.truthy(shell.error());
t.truthy(result.code);
});
//
// Valids
//
test('simple', t => {
const result = shell.sort('resources/sort/file1');
t.falsy(shell.error());
t.is(result.code, 0);
t.is(result.toString(), shell.cat('resources/sort/sorted').toString());
});
test('simple #2', t => {
const result = shell.sort('resources/sort/file2');
t.falsy(shell.error());
t.is(result.code, 0);
t.is(result.toString(), shell.cat('resources/sort/sorted').toString());
});
test('multiple files', t => {
const result = shell.sort('resources/sort/file2', 'resources/sort/file1');
t.falsy(shell.error());
t.is(result.code, 0);
t.is(result.toString(), doubleSorted);
});
test('multiple files, array syntax', t => {
const result = shell.sort(['resources/sort/file2', 'resources/sort/file1']);
t.falsy(shell.error());
t.is(result.code, 0);
t.is(result.toString(), doubleSorted);
});
test('Globbed file', t => {
const result = shell.sort('resources/sort/file?');
t.falsy(shell.error());
t.is(result.code, 0);
t.is(result.toString(), doubleSorted);
});
test('With \'-n\' option', t => {
const result = shell.sort('-n', 'resources/sort/file2');
t.falsy(shell.error());
t.is(result.code, 0);
t.is(result.toString(), shell.cat('resources/sort/sortedDashN').toString());
});
test('With \'-r\' option', t => {
const result = shell.sort('-r', 'resources/sort/file2');
t.falsy(shell.error());
t.is(result.code, 0);
t.is(result.toString(), shell.cat('resources/sort/sorted')
.trimRight()
.split('\n')
.reverse()
.join('\n') + '\n');
});
test('With \'-rn\' option', t => {
const result = shell.sort('-rn', 'resources/sort/file2');
t.falsy(shell.error());
t.is(result.code, 0);
t.is(result.toString(), shell.cat('resources/sort/sortedDashN')
.trimRight()
.split('\n')
.reverse()
.join('\n') + '\n');
});