From 0e0f06d634bd66a3dc37cda2d71cf910d2455d66 Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Sun, 24 Jul 2016 01:23:10 +0200 Subject: [PATCH] Add some tests. --- src/_h5ai/public/js/lib/view/base.js | 3 +- test/index.js | 1 + test/tests/unit/util/parsePatten.js | 42 ++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 test/tests/unit/util/parsePatten.js diff --git a/src/_h5ai/public/js/lib/view/base.js b/src/_h5ai/public/js/lib/view/base.js index 053f000c..3f51c397 100644 --- a/src/_h5ai/public/js/lib/view/base.js +++ b/src/_h5ai/public/js/lib/view/base.js @@ -16,10 +16,9 @@ const mainrowTpl = `; const init = () => { - dom('#fallback, #fallback-hints').rm(); - const $root = dom(rootSelector) .attr('id', 'root') + .clr() .app(topbarTpl) .app(mainrowTpl); diff --git a/test/index.js b/test/index.js index e4133ee4..3174d2a8 100644 --- a/test/index.js +++ b/test/index.js @@ -9,6 +9,7 @@ require('./tests/premisses'); require('./tests/unit/core/event'); require('./tests/unit/core/format'); require('./tests/unit/util/naturalCmp'); +require('./tests/unit/util/parsePatten'); pinHtml(); diff --git a/test/tests/unit/util/parsePatten.js b/test/tests/unit/util/parsePatten.js new file mode 100644 index 00000000..4c46dc4c --- /dev/null +++ b/test/tests/unit/util/parsePatten.js @@ -0,0 +1,42 @@ +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'); +}); + +[ + ['', 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); + }); +});