mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-29 04:18:59 -05:00
Address code review: expand punctuation regex, add edge case tests
Agent-Logs-Url: https://github.com/microsoft/vscode/sessions/a55f8192-679d-45d7-b1ba-637b1df2730d Co-authored-by: vijayupadya <41652029+vijayupadya@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
87e70edaa2
commit
b8dd7e3ad7
@@ -35,5 +35,14 @@ suite('isLikelyNaturalLanguage', () => {
|
||||
expect(isLikelyNaturalLanguage('const a = new Map()')).toBe(false);
|
||||
expect(isLikelyNaturalLanguage('a === b ? c : d')).toBe(false);
|
||||
expect(isLikelyNaturalLanguage('Array<string | number>')).toBe(false);
|
||||
expect(isLikelyNaturalLanguage('foo.bar.baz method call')).toBe(false);
|
||||
expect(isLikelyNaturalLanguage('a & b | c ^ d')).toBe(false);
|
||||
expect(isLikelyNaturalLanguage('result = a + b / c')).toBe(false);
|
||||
});
|
||||
|
||||
test('should handle edge cases', () => {
|
||||
expect(isLikelyNaturalLanguage('')).toBe(false);
|
||||
expect(isLikelyNaturalLanguage(' ')).toBe(false);
|
||||
expect(isLikelyNaturalLanguage(' a ')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -131,7 +131,7 @@ export function isLikelyNaturalLanguage(text: string): boolean {
|
||||
|
||||
// Code expressions with many tokens typically contain punctuation like
|
||||
// parentheses, brackets, operators, etc. that natural language lacks.
|
||||
if (/[()[\]{}<>=:;@#]/.test(text)) {
|
||||
if (/[()[\]{}<>=:;@#.&|*+/%^~]/.test(text)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user