forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drop dedent-on-enter for "return" statements. (#6939)
- Loading branch information
1 parent
10ab7e7
commit 11dd074
Showing
8 changed files
with
447 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Drop dedent-on-enter for "return" statements. It will be addressed in: | ||
https://github.com/microsoft/vscode-python/issues/6564 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
'use strict'; | ||
|
||
/* Generate a RegExp from a "verbose" pattern. | ||
* | ||
* All whitespace in the pattern is removed, including newlines. This | ||
* allows the pattern to be much more readable by allowing it to span | ||
* multiple lines and to separate tokens with insignificant whitespace. | ||
* The functionality is similar to the VERBOSE ("x") flag in Python's | ||
* regular expressions. | ||
* | ||
* Note that significant whitespace in the pattern must be explicitly | ||
* indicated by "\s". Also, unlike with regular expression literals, | ||
* backslashes must be escaped. Conversely, forward slashes do not | ||
* need to be escaped. | ||
*/ | ||
export function verboseRegExp(pattern: string): RegExp { | ||
pattern = pattern.replace(/\s+?/g, ''); | ||
return RegExp(pattern); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('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'); | ||
}); | ||
} | ||
}); |
Oops, something went wrong.