From 3fe1b2d6f862ffa745563a3f741b0319edf6f0b8 Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Sat, 23 Jul 2016 03:03:35 +0200 Subject: [PATCH] Add tests. --- test/index.js | 1 + test/tests/unit/util/naturalCmp.js | 43 ++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 test/tests/unit/util/naturalCmp.js diff --git a/test/index.js b/test/index.js index 59aa6dbd..e4133ee4 100644 --- a/test/index.js +++ b/test/index.js @@ -8,6 +8,7 @@ const {pinHtml} = require('./util/pin'); require('./tests/premisses'); require('./tests/unit/core/event'); require('./tests/unit/core/format'); +require('./tests/unit/util/naturalCmp'); pinHtml(); diff --git a/test/tests/unit/util/naturalCmp.js b/test/tests/unit/util/naturalCmp.js new file mode 100644 index 00000000..a1eabcea --- /dev/null +++ b/test/tests/unit/util/naturalCmp.js @@ -0,0 +1,43 @@ +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'); +}); + +[ + '-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); + }); +});