mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-29 06:25:18 -04:00
Add tests for escapePattern and parsePattern.
This commit is contained in:
parent
a482529fdc
commit
7311cc8e4b
2 changed files with 124 additions and 6 deletions
|
@ -2,7 +2,7 @@
|
|||
'use strict';
|
||||
|
||||
var ID = 'core/util';
|
||||
var DEPS = [];
|
||||
var DEPS = ['_'];
|
||||
|
||||
describe('module \'' + ID + '\'', function () {
|
||||
|
||||
|
@ -12,7 +12,7 @@ describe('module \'' + ID + '\'', function () {
|
|||
|
||||
this.applyFn = function () {
|
||||
|
||||
return this.definition.fn();
|
||||
return this.definition.fn(_);
|
||||
};
|
||||
});
|
||||
|
||||
|
@ -51,11 +51,11 @@ describe('module \'' + ID + '\'', function () {
|
|||
|
||||
describe('application', function () {
|
||||
|
||||
it('returns plain object with 2 properties', function () {
|
||||
it('returns plain object with 4 properties', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOfKeys(instance, 2);
|
||||
assert.lengthOfKeys(instance, 4);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -118,6 +118,115 @@ describe('module \'' + ID + '\'', function () {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.escapePattern()', function () {
|
||||
|
||||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.escapePattern);
|
||||
});
|
||||
|
||||
_.each([
|
||||
['a', 'a'],
|
||||
['1', '1'],
|
||||
['ä', 'ä'],
|
||||
['~', '~'],
|
||||
[':', ':'],
|
||||
['_', '_'],
|
||||
['<', '<'],
|
||||
['-', '\\-'],
|
||||
['[', '\\['],
|
||||
[']', '\\]'],
|
||||
['{', '\\{'],
|
||||
['}', '\\}'],
|
||||
['(', '\\('],
|
||||
[')', '\\)'],
|
||||
['*', '\\*'],
|
||||
['+', '\\+'],
|
||||
['?', '\\?'],
|
||||
['.', '\\.'],
|
||||
[',', '\\,'],
|
||||
['\\', '\\\\'],
|
||||
['$', '\\$'],
|
||||
['^', '\\^'],
|
||||
['|', '\\|'],
|
||||
['#', '\\#'],
|
||||
[' ', '\\ '],
|
||||
['-[]{}()*+?.,\\$^|# ', '\\-\\[\\]\\{\\}\\(\\)\\*\\+\\?\\.\\,\\\\\\$\\^\\|\\#\\ '],
|
||||
['abc123', 'abc123'],
|
||||
['a.b+c*1', 'a\\.b\\+c\\*1']
|
||||
], function (data) {
|
||||
|
||||
var arg = data[0];
|
||||
var exp = data[1];
|
||||
|
||||
it(arg + ' => ' + exp, function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.escapePattern(arg), exp);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.parsePattern()', function () {
|
||||
|
||||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.parsePattern);
|
||||
});
|
||||
|
||||
_.each([
|
||||
['a', false, 'a'],
|
||||
['1', false, '1'],
|
||||
['ä', false, 'ä'],
|
||||
['~', false, '~'],
|
||||
[':', false, ':'],
|
||||
['_', false, '_'],
|
||||
['<', false, '<'],
|
||||
['-', false, '\\-'],
|
||||
['[', false, '\\['],
|
||||
[']', false, '\\]'],
|
||||
['{', false, '\\{'],
|
||||
['}', false, '\\}'],
|
||||
['(', false, '\\('],
|
||||
[')', false, '\\)'],
|
||||
['*', false, '\\*'],
|
||||
['+', false, '\\+'],
|
||||
['?', false, '\\?'],
|
||||
['.', false, '\\.'],
|
||||
[',', false, '\\,'],
|
||||
['\\', false, '\\\\'],
|
||||
['$', false, '\\$'],
|
||||
['^', false, '\\^'],
|
||||
['|', false, '\\|'],
|
||||
['#', false, '\\#'],
|
||||
[' ', false, '\\ '],
|
||||
['-[]{}()*+?.,\\$^|# ', false, '\\-\\[\\]\\{\\}\\(\\)\\*\\+\\?\\.\\,\\\\\\$\\^\\|\\#\\ '],
|
||||
['abc123', false, 'abc123'],
|
||||
['a.b+c*1', false, 'a\\.b\\+c\\*1'],
|
||||
|
||||
['abc', true, 'a.*?b.*?c'],
|
||||
['abc def', true, 'a.*?b.*?c|d.*?e.*?f'],
|
||||
['*#a b.=', true, '\\*.*?\\#.*?a|b.*?\\..*?='],
|
||||
['re:.', true, '.'],
|
||||
[' .', true, '\\.'],
|
||||
['re: .', true, ' .']
|
||||
|
||||
], function (data) {
|
||||
|
||||
var arg1 = data[0];
|
||||
var arg2 = data[1];
|
||||
var exp = data[2];
|
||||
|
||||
it(arg1 + ', ' + arg2 + ' => ' + exp, function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.parsePattern(arg1, arg2), exp);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
||||
|
|
|
@ -90,11 +90,11 @@ describe('module \'' + ID + '\'', function () {
|
|||
|
||||
describe('application', function () {
|
||||
|
||||
it('returns object with 5 properties', function () {
|
||||
it('returns object with 6 properties', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOfKeys(instance, 5);
|
||||
assert.lengthOfKeys(instance, 6);
|
||||
});
|
||||
|
||||
it('adds HTML #view to #content', function () {
|
||||
|
@ -187,6 +187,15 @@ describe('module \'' + ID + '\'', function () {
|
|||
});
|
||||
});
|
||||
|
||||
describe('.setHint()', function () {
|
||||
|
||||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.ok(_.isFunction(instance.setHint));
|
||||
});
|
||||
});
|
||||
|
||||
// describe('._.createHtml()', function () {
|
||||
|
||||
// before(function () {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue