Skip to content

Commit

Permalink
Docs updated, tests rewritten
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob-chemist committed Dec 31, 2019
1 parent f81a1ca commit 2b23902
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,7 @@ Compare for array.sort with priority
_Example:_

```js
files.sort(common.sortComparePriority);
files.sort(common.sortComparePriority(priority));
```

### sortCompareDirectories(a, b)
Expand Down
2 changes: 1 addition & 1 deletion lib/sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// s2 - <string>, to compare
// Returns: <number>
//
// Example: files.sort(common.sortComparePriority)
// Example: files.sort(common.sortComparePriority(priority))
const sortComparePriority = priority => (s1, s2) => {
let a = priority.indexOf(s1);
let b = priority.indexOf(s2);
Expand Down
20 changes: 13 additions & 7 deletions test/sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,24 @@ const CONFIG_FILES_PRIORITY = [
'routes.js',
];

const getTestSorting = config => (file1, file2, sortRes) => {
return [config, cb => cb(file1, file2) === sortRes];
};
const testSorting = getTestSorting(CONFIG_FILES_PRIORITY);

metatests.case(
'Common / sort',
{ common },
{
'common.sortComparePriority': [
[CONFIG_FILES_PRIORITY, res => res('files.js', 'sandbox.js') === 1],
[CONFIG_FILES_PRIORITY, res => res('filestorage.js', 'routes.js') === -1],
[CONFIG_FILES_PRIORITY, res => res('unknown.js', 'sandbox.js') === 1],
[CONFIG_FILES_PRIORITY, res => res('log.js', 'sandbox.js') === 1],
[CONFIG_FILES_PRIORITY, res => res('sandbox.js', 'sandbox.js') === 0],
[CONFIG_FILES_PRIORITY, res => res('log.js', 'log.js') === 0],
[CONFIG_FILES_PRIORITY, res => res('tasks.js', 'application.js') === -1],
testSorting('files.js', 'sandbox.js', 1),
testSorting('filestorage.js', 'routes.js', -1),
testSorting('unknown.js', 'sandbox.js', 1),
testSorting('log.js', 'sandbox.js', 1),
testSorting('sandbox.js', 'sandbox.js', 0),
testSorting('log.js', 'log.js', 0),
testSorting('tasks.js', 'application.js', -1),
testSorting('files.js', 'sandbox.js', 1),
],
'common.sortCompareDirectories': [
[{ name: '/abc' }, { name: 'abc.ext' }, -1],
Expand Down

0 comments on commit 2b23902

Please sign in to comment.