diff --git a/test/tests/unit/core/event.js b/test/tests/unit/core/event.js index c1900dda..33e2658d 100644 --- a/test/tests/unit/core/event.js +++ b/test/tests/unit/core/event.js @@ -1,18 +1,9 @@ const {test, assert} = require('scar'); const event = require('../../../../src/_h5ai/public/js/lib/core/event'); -test('event is object', () => { - assert.equal(typeof event, 'object'); -}); - -test('event has the right props', () => { - assert.deepEqual(Object.keys(event), ['sub', 'pub']); -}); - -test('event.sub is function', () => { +test('core.event', () => { + assert.equal(typeof event, 'object', 'is object'); + assert.deepEqual(Object.keys(event).sort(), ['sub', 'pub'].sort()); assert.equal(typeof event.sub, 'function'); -}); - -test('event.pub is function', () => { assert.equal(typeof event.pub, 'function'); }); diff --git a/test/tests/unit/core/format.js b/test/tests/unit/core/format.js index 06b83264..dd65c8e8 100644 --- a/test/tests/unit/core/format.js +++ b/test/tests/unit/core/format.js @@ -1,26 +1,11 @@ const {test, assert} = require('scar'); const format = require('../../../../src/_h5ai/public/js/lib/core/format'); -test('format is object', () => { +test('core.format', () => { assert.equal(typeof format, 'object'); -}); - -test('format has the right props', () => { - assert.deepEqual(Object.keys(format), ['setDefaultMetric', 'formatSize', 'setDefaultDateFormat', 'formatDate']); -}); - -test('format.setDefaultMetric is function', () => { + assert.deepEqual(Object.keys(format).sort(), ['setDefaultMetric', 'formatSize', 'setDefaultDateFormat', 'formatDate'].sort()); assert.equal(typeof format.setDefaultMetric, 'function'); -}); - -test('format.formatSize is function', () => { assert.equal(typeof format.formatSize, 'function'); -}); - -test('format.setDefaultDateFormat is function', () => { assert.equal(typeof format.setDefaultDateFormat, 'function'); -}); - -test('format.formatDate is function', () => { assert.equal(typeof format.formatDate, 'function'); }); diff --git a/test/tests/unit/util/naturalCmp.js b/test/tests/unit/util/naturalCmp.js index a1eabcea..e79a0800 100644 --- a/test/tests/unit/util/naturalCmp.js +++ b/test/tests/unit/util/naturalCmp.js @@ -1,43 +1,41 @@ const {test, assert, insp} = require('scar'); const {naturalCmp} = require('../../../../src/_h5ai/public/js/lib/util'); -test('util.naturalCmp is function', () => { - assert.equal(typeof naturalCmp, 'function'); -}); +test('util.naturalCmp()', () => { + assert.equal(typeof naturalCmp, 'function', 'is function'); -[ - '-1', - '0', - '00', - '000', - '001', - '01', - '02', - '1', - '3', - 'a0', - 'a00', - 'a1', - 'a2', - 'a 0', - 'a 00', - 'a 000', - 'a 01', - 'a 1', - 'a 2', - 'a 3', - 'a.1', - 'a.1.0', - 'a.1.1', - 'a.1.1.0', - 'a.1.10', - 'z' -].forEach((b, idx, arr) => { - if (idx === 0) { - return; - } - const a = arr[idx - 1]; - test(`util.naturalCmp(): ${insp(a)} < ${insp(b)}`, () => { - assert.equal(naturalCmp(a, b), -1); + [ + '-1', + '0', + '00', + '000', + '001', + '01', + '02', + '1', + '3', + 'a0', + 'a00', + 'a1', + 'a2', + 'a 0', + 'a 00', + 'a 000', + 'a 01', + 'a 1', + 'a 2', + 'a 3', + 'a.1', + 'a.1.0', + 'a.1.1', + 'a.1.1.0', + 'a.1.10', + 'z' + ].forEach((b, idx, arr) => { + if (idx === 0) { + return; + } + const a = arr[idx - 1]; + assert.equal(naturalCmp(a, b), -1, `fix#${idx} - ${insp(a)} < ${insp(b)}`); }); }); diff --git a/test/tests/unit/util/parsePatten.js b/test/tests/unit/util/parsePatten.js index 4c46dc4c..597db932 100644 --- a/test/tests/unit/util/parsePatten.js +++ b/test/tests/unit/util/parsePatten.js @@ -1,42 +1,40 @@ const {test, assert, insp} = require('scar'); const {parsePattern} = require('../../../../src/_h5ai/public/js/lib/util'); -test('util.parsePattern is function', () => { - assert.equal(typeof parsePattern, 'function'); -}); +test('util.parsePattern()', () => { + assert.equal(typeof parsePattern, 'function', 'is function'); -[ - ['', false, ''], - [' ', false, '\\ '], - ['a', false, 'a'], - ['ä', false, 'ä'], - ['á', false, 'á'], - ['*', false, '\\*'], - ['ab', false, 'ab'], - ['rea', false, 'rea'], - ['re:', false, 're:'], - ['re:a', false, 're:a'], - ['a b', false, 'a\\ b'], - ['ab c', false, 'ab\\ c'], - [' a ', false, '\\ a\\ '], + [ + ['', false, ''], + [' ', false, '\\ '], + ['a', false, 'a'], + ['ä', false, 'ä'], + ['á', false, 'á'], + ['*', false, '\\*'], + ['ab', false, 'ab'], + ['rea', false, 'rea'], + ['re:', false, 're:'], + ['re:a', false, 're:a'], + ['a b', false, 'a\\ b'], + ['ab c', false, 'ab\\ c'], + [' a ', false, '\\ a\\ '], - ['', true, ''], - [' ', true, ''], - ['a', true, 'a'], - ['ä', true, 'ä'], - ['á', true, 'á'], - ['*', true, '\\*'], - ['ab', true, 'a.*?b'], - ['rea', true, 'r.*?e.*?a'], - [' re:', true, 'r.*?e.*?:'], - ['are:', true, 'a.*?r.*?e.*?:'], - ['re:', true, ''], - ['re:a', true, 'a'], - ['a b', true, 'a|b'], - ['ab c', true, 'a.*?b|c'], - [' a ', true, 'a'] -].forEach(([pattern, advanced, exp]) => { - test(`util.parsePattern(${insp(pattern)}, ${insp(advanced)}) === ${insp(exp)}`, () => { - assert.equal(parsePattern(pattern, advanced), exp); + ['', true, ''], + [' ', true, ''], + ['a', true, 'a'], + ['ä', true, 'ä'], + ['á', true, 'á'], + ['*', true, '\\*'], + ['ab', true, 'a.*?b'], + ['rea', true, 'r.*?e.*?a'], + [' re:', true, 'r.*?e.*?:'], + ['are:', true, 'a.*?r.*?e.*?:'], + ['re:', true, ''], + ['re:a', true, 'a'], + ['a b', true, 'a|b'], + ['ab c', true, 'a.*?b|c'], + [' a ', true, 'a'] + ].forEach(([pattern, advanced, exp], idx) => { + assert.equal(parsePattern(pattern, advanced), exp, `fix#${idx} - (${insp(pattern)}, ${insp(advanced)}) -> ${insp(exp)}`); }); });