From 2b2390276a63d45e7616c2fd5020a39eec46794b Mon Sep 17 00:00:00 2001 From: Bob_chemist Date: Tue, 31 Dec 2019 09:44:14 +0300 Subject: [PATCH] Docs updated, tests rewritten --- README.md | 2 +- lib/sort.js | 2 +- test/sort.js | 20 +++++++++++++------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index ec080480..a7ec9fe6 100644 --- a/README.md +++ b/README.md @@ -1260,7 +1260,7 @@ Compare for array.sort with priority _Example:_ ```js -files.sort(common.sortComparePriority); +files.sort(common.sortComparePriority(priority)); ``` ### sortCompareDirectories(a, b) diff --git a/lib/sort.js b/lib/sort.js index 13f2cb2e..5847e294 100644 --- a/lib/sort.js +++ b/lib/sort.js @@ -6,7 +6,7 @@ // s2 - , to compare // Returns: // -// 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); diff --git a/test/sort.js b/test/sort.js index 9ef67420..1cb7d7a5 100644 --- a/test/sort.js +++ b/test/sort.js @@ -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],