mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-24 12:07:10 -04:00
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
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);
|
|
});
|
|
});
|