forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregexp.unit.test.ts
More file actions
71 lines (60 loc) · 1.71 KB
/
regexp.unit.test.ts
File metadata and controls
71 lines (60 loc) · 1.71 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { expect } from 'chai';
import { verboseRegExp } from '../../../client/common/utils/regexp';
suite('Utils for regular expressions - verboseRegExp()', () => {
test('whitespace removed in multiline pattern (example of typical usage)', () => {
const regex = verboseRegExp(`
^
(?:
spam \\b .*
) |
(?:
eggs \\b .*
)
$
`);
expect(regex.source).to.equal('^(?:spam\\b.*)|(?:eggs\\b.*)$', 'mismatch');
});
const whitespaceTests = [
['spam eggs', 'spameggs'],
[
`spam
eggs`,
'spameggs',
],
// empty
[' ', '(?:)'],
[
`
`,
'(?:)',
],
];
for (const [pat, expected] of whitespaceTests) {
test(`whitespace removed ("${pat}")`, () => {
const regex = verboseRegExp(pat);
expect(regex.source).to.equal(expected, 'mismatch');
});
}
const noopPatterns = ['^(?:spam\\b.*)$', 'spam', '^spam$', 'spam$', '^spam'];
for (const pat of noopPatterns) {
test(`pattern not changed ("${pat}")`, () => {
const regex = verboseRegExp(pat);
expect(regex.source).to.equal(pat, 'mismatch');
});
}
const emptyPatterns = [
'',
`
`,
' ',
];
for (const pat of emptyPatterns) {
test(`no pattern ("${pat}")`, () => {
const regex = verboseRegExp(pat);
expect(regex.source).to.equal('(?:)', 'mismatch');
});
}
});