-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
58 lines (48 loc) · 2.13 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*!
* delimiter-regex <https://github.com/jonschlinkert/delimiter-regex>
*
* Copyright (c) 2014-2015, Jon Schlinkert.
* Licensed under the MIT License.
*/
'use strict';
var assert = require('assert');
var delims = require('./');
function match(str, re) {
return re.exec(str);
}
describe('delims', function () {
it('should return default es6 regex:', function () {
assert.deepEqual(/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g, delims());
assert.deepEqual(/\$\{([\s\S]+?)\}/, delims('\\$\\{', '\\}'));
});
it('should match correctly:', function () {
assert.equal(match('abc/${foo}/xyz', delims())[0], '${foo}');
assert.equal(match('abc/${foo}/xyz', delims())[1], 'foo');
assert.equal(match('abc/${foo}/${bar}/xyz', delims())[0], '${foo}');
assert.equal(match('abc/${foo}/${bar}/xyz', delims())[1], 'foo');
assert.equal(match('---\na: b\nc: d\n---\ncontent', delims('---', '---'))[0], '---\na: b\nc: d\n---');
assert.equal(match('---\na: b\nc: d\n---\ncontent', delims('---\\s*', '\\s*---'))[1], 'a: b\nc: d');
assert.equal(match('abc/${foo}/${bar}/xyz', delims())[1], 'foo');
});
it('should support array format:', function () {
assert.deepEqual(/---([\s\S]+?)---/, delims(['---', '---']));
assert.deepEqual(/\{\{([\s\S]+?)\}\}/, delims(['\\{\\{', '\\}\\}']));
assert.deepEqual(/\{{([\s\S]+?)}}/, delims(['\\{{', '}}']));
});
it('should support regexp flags:', function () {
assert.deepEqual(/---([\s\S]+?)---/g, delims('---', '---', {flags: 'g'}));
assert.deepEqual(/\$\{([\s\S]+?)\}/gm, delims({flags: 'gm'}));
});
it('should not escape characters:', function () {
assert.deepEqual(/---(\w)*([\s\S]+?)---/, delims('---(\\w)*', '---'));
});
it('should support list format:', function () {
assert.deepEqual(/---([\s\S]+?)---/, delims('---', '---'));
assert.deepEqual(/\{\{([\s\S]+?)\}\}/, delims('\\{\\{', '\\}\\}'));
});
it('should respect escapes', function () {
assert.deepEqual(/\-\-\-([\s\S]+?)\-\-\-/, delims('\\-\\-\\-', '\\-\\-\\-'));
assert.deepEqual(/\{\{([\s\S]+?)}}/, delims('\\{\\{', '}}'));
assert.deepEqual(/\{{([\s\S]+?)}}/, delims('\\{{', '}}'));
});
});