Skip to content

Commit 2b23902

Browse files
committed
Docs updated, tests rewritten
1 parent f81a1ca commit 2b23902

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ Compare for array.sort with priority
12601260
_Example:_
12611261

12621262
```js
1263-
files.sort(common.sortComparePriority);
1263+
files.sort(common.sortComparePriority(priority));
12641264
```
12651265

12661266
### sortCompareDirectories(a, b)

Diff for: lib/sort.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// s2 - <string>, to compare
77
// Returns: <number>
88
//
9-
// Example: files.sort(common.sortComparePriority)
9+
// Example: files.sort(common.sortComparePriority(priority))
1010
const sortComparePriority = priority => (s1, s2) => {
1111
let a = priority.indexOf(s1);
1212
let b = priority.indexOf(s2);

Diff for: test/sort.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,24 @@ const CONFIG_FILES_PRIORITY = [
2121
'routes.js',
2222
];
2323

24+
const getTestSorting = config => (file1, file2, sortRes) => {
25+
return [config, cb => cb(file1, file2) === sortRes];
26+
};
27+
const testSorting = getTestSorting(CONFIG_FILES_PRIORITY);
28+
2429
metatests.case(
2530
'Common / sort',
2631
{ common },
2732
{
2833
'common.sortComparePriority': [
29-
[CONFIG_FILES_PRIORITY, res => res('files.js', 'sandbox.js') === 1],
30-
[CONFIG_FILES_PRIORITY, res => res('filestorage.js', 'routes.js') === -1],
31-
[CONFIG_FILES_PRIORITY, res => res('unknown.js', 'sandbox.js') === 1],
32-
[CONFIG_FILES_PRIORITY, res => res('log.js', 'sandbox.js') === 1],
33-
[CONFIG_FILES_PRIORITY, res => res('sandbox.js', 'sandbox.js') === 0],
34-
[CONFIG_FILES_PRIORITY, res => res('log.js', 'log.js') === 0],
35-
[CONFIG_FILES_PRIORITY, res => res('tasks.js', 'application.js') === -1],
34+
testSorting('files.js', 'sandbox.js', 1),
35+
testSorting('filestorage.js', 'routes.js', -1),
36+
testSorting('unknown.js', 'sandbox.js', 1),
37+
testSorting('log.js', 'sandbox.js', 1),
38+
testSorting('sandbox.js', 'sandbox.js', 0),
39+
testSorting('log.js', 'log.js', 0),
40+
testSorting('tasks.js', 'application.js', -1),
41+
testSorting('files.js', 'sandbox.js', 1),
3642
],
3743
'common.sortCompareDirectories': [
3844
[{ name: '/abc' }, { name: 'abc.ext' }, -1],

0 commit comments

Comments
 (0)