Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix the bug that cannot parse test cases which contains double quotes#113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
jdneo merged 1 commit intomasterfromcs/fix
Feb 10, 2019
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletionssrc/commands/test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,8 +7,10 @@ import { leetCodeExecutor } from "../leetCodeExecutor";
import { leetCodeManager } from "../leetCodeManager";
import { leetCodeResultProvider } from "../leetCodeResultProvider";
import { IQuickItemEx, UserStatus } from "../shared";
import { isWindows, usingCmd } from "../utils/osUtils";
import { DialogType, promptForOpenOutputChannel, showFileSelectDialog } from "../utils/uiUtils";
import { getActiveFilePath } from "../utils/workspaceUtils";
import * as wsl from "../utils/wslUtils";

export async function testSolution(uri?: vscode.Uri): Promise<void> {
try {
Expand DownExpand Up@@ -59,15 +61,15 @@ export async function testSolution(uri?: vscode.Uri): Promise<void> {
ignoreFocusOut: true,
});
if (testString) {
result = await leetCodeExecutor.testSolution(filePath, testString);
result = await leetCodeExecutor.testSolution(filePath,parseTestString(testString));
}
break;
case ":file":
const testFile: vscode.Uri[] | undefined = await showFileSelectDialog();
if (testFile && testFile.length) {
const input: string = await fse.readFile(testFile[0].fsPath, "utf-8");
if (input.trim()) {
result = await leetCodeExecutor.testSolution(filePath, input.replace(/\r?\n/g, "\\n"));
const input: string =(await fse.readFile(testFile[0].fsPath, "utf-8")).trim();
if (input) {
result = await leetCodeExecutor.testSolution(filePath,parseTestString(input.replace(/\r?\n/g, "\\n")));
} else {
vscode.window.showErrorMessage("The selected test file must not be empty.");
}
Expand All@@ -84,3 +86,17 @@ export async function testSolution(uri?: vscode.Uri): Promise<void> {
await promptForOpenOutputChannel("Failed to test the solution. Please open the output channel for details.", DialogType.error);
}
}

function parseTestString(test: string): string {
if (wsl.useWsl() || !isWindows()) {
return `'${test}'`;
}

// In windows and not using WSL
if (usingCmd()) {
return `"${test.replace(/"/g, '\\"')}"`;
} else {
// Assume using PowerShell
return `'${test.replace(/"/g, '\\"')}'`;
}
}
2 changes: 1 addition & 1 deletionsrc/leetCodeExecutor.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -96,7 +96,7 @@ class LeetCodeExecutor {

public async testSolution(filePath: string, testString?: string): Promise<string> {
if (testString) {
return await this.executeCommandWithProgressEx("Submitting to LeetCode...", "node", [await this.getLeetCodeBinaryPath(), "test", `"${filePath}"`, "-t", `'${testString}'`]);
return await this.executeCommandWithProgressEx("Submitting to LeetCode...", "node", [await this.getLeetCodeBinaryPath(), "test", `"${filePath}"`, "-t", `${testString}`]);
}
return await this.executeCommandWithProgressEx("Submitting to LeetCode...", "node", [await this.getLeetCodeBinaryPath(), "test", `"${filePath}"`]);
}
Expand Down
19 changes: 19 additions & 0 deletionssrc/utils/osUtils.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
// Copyright (c) jdneo. All rights reserved.
// Licensed under the MIT license.

export function isWindows(): boolean {
return process.platform === "win32";
}

export function usingCmd(): boolean {
const comSpec: string = process.env.ComSpec;
// 'cmd.exe' is used as a fallback if process.env.ComSpec is unavailable.
if (!comSpec) {
return true;
}

if (comSpec.indexOf("cmd.exe") > -1) {
return true;
}
return false;
}

[8]ページ先頭

©2009-2025 Movatter.jp