Skip to content

Commit

Permalink
Add tests for verboseRegExp().
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsnowcurrently committed Aug 12, 2019
1 parent 8881cb0 commit ad2f095
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions src/test/common/utils/regexp.unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

'use strict';

// tslint:disable:no-multiline-string

import { expect } from 'chai';

import {
verboseRegExp
} from '../../../client/common/utils/regexp';

suite('Utils for regular expressions - verboseRegExp()', () => {
test('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');
});
}
});

0 comments on commit ad2f095

Please sign in to comment.