Files
Matt Bierner 3c8134184b Enable no-unexternalized-strings in repo (#2448)
Enables the same `no-unexternalized-strings` with have in `vscode` in this repo. This make sure we have a more consistent style across repos and when generating edits
2025-12-05 18:45:12 +00:00

55 lines
2.0 KiB
TypeScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { expect, suite, test } from 'vitest';
import { validateDocstringFormat } from '../slashDoc.py.stest';
suite('hasCorrectlyFormattedDocstring Tests', function () {
test('Correctly formatted docstring', function () {
const fileContents = `
def my_function(param1, param2):
"""
This is a docstring for my_function.
"""
pass
`;
const targetLineString = 'def my_function(param1, param2):';
validateDocstringFormat(fileContents, targetLineString);
});
test('error: not indented', function () {
const fileContents = `
def my_function(param1, param2):
"""
This is a wrongly indented docstring for my_function.
"""
pass
`;
const targetLineString = 'def my_function(param1, param2):';
expect(() => validateDocstringFormat(fileContents, targetLineString)).toThrowErrorMatchingInlineSnapshot(`[Error: Incorrect docstring indentation. Expected: ' ', but got: '']`);
});
test('error: no docstring', function () {
const fileContents = `
def my_function(param1, param2):
pass
`;
const targetLineString = 'def my_function(param1, param2):';
expect(() => validateDocstringFormat(fileContents, targetLineString)).toThrowErrorMatchingInlineSnapshot(`[Error: No docstring found after the target line.]`);
});
test('Docstring with correct indentation using tabs', function () {
const fileContents = `
def my_function(param1, param2):
"""
This is a docstring for my_function with tabs.
"""
`;
const targetLineString = 'def my_function(param1, param2):';
expect(() => validateDocstringFormat(fileContents, targetLineString)).toThrowErrorMatchingInlineSnapshot(`[Error: Incorrect docstring indentation. Expected: ' ········', but got: '········']`);
});
});