MCPcopy Index your code
hub / github.com/LeetCode-OpenSource/vscode-leetcode / testSolution

Function testSolution

src/commands/test.ts:15–88  ·  view source on GitHub ↗
(uri?: vscode.Uri)

Source from the content-addressed store, hash-verified

13import { leetCodeSubmissionProvider } from "../webview/leetCodeSubmissionProvider";
14
15export async function testSolution(uri?: vscode.Uri): Promise<void> {
16 try {
17 if (leetCodeManager.getStatus() === UserStatus.SignedOut) {
18 return;
19 }
20
21 const filePath: string | undefined = await getActiveFilePath(uri);
22 if (!filePath) {
23 return;
24 }
25 const picks: Array<IQuickItemEx<string>> = [];
26 picks.push(
27 {
28 label: "$(three-bars) Default test cases",
29 description: "",
30 detail: "Test with the default cases",
31 value: ":default",
32 },
33 {
34 label: "$(pencil) Write directly...",
35 description: "",
36 detail: "Write test cases in input box",
37 value: ":direct",
38 },
39 {
40 label: "$(file-text) Browse...",
41 description: "",
42 detail: "Test with the written cases in file",
43 value: ":file",
44 },
45 );
46 const choice: IQuickItemEx<string> | undefined = await vscode.window.showQuickPick(picks);
47 if (!choice) {
48 return;
49 }
50
51 let result: string | undefined;
52 switch (choice.value) {
53 case ":default":
54 result = await leetCodeExecutor.testSolution(filePath);
55 break;
56 case ":direct":
57 const testString: string | undefined = await vscode.window.showInputBox({
58 prompt: "Enter the test cases.",
59 validateInput: (s: string): string | undefined => s && s.trim() ? undefined : "Test case must not be empty.",
60 placeHolder: "Example: [1,2,3]\\n4",
61 ignoreFocusOut: true,
62 });
63 if (testString) {
64 result = await leetCodeExecutor.testSolution(filePath, parseTestString(testString));
65 }
66 break;
67 case ":file":
68 const testFile: vscode.Uri[] | undefined = await showFileSelectDialog(filePath);
69 if (testFile && testFile.length) {
70 const input: string = (await fse.readFile(testFile[0].fsPath, "utf-8")).trim();
71 if (input) {
72 result = await leetCodeExecutor.testSolution(filePath, parseTestString(input.replace(/\r?\n/g, "\\n")));

Callers

nothing calls this directly

Calls 7

getActiveFilePathFunction · 0.90
showFileSelectDialogFunction · 0.90
parseTestStringFunction · 0.85
getStatusMethod · 0.80
testSolutionMethod · 0.80
showMethod · 0.45

Tested by

no test coverage detected