diff --git a/src/test/suite/configuration.test.ts b/src/test/suite/configuration.test.ts new file mode 100644 index 0000000000..4311640edc --- /dev/null +++ b/src/test/suite/configuration.test.ts @@ -0,0 +1,59 @@ +import assert from "assert"; +import * as vscode from "vscode"; +import { Configuration } from "../../configuration/configuration"; + +interface MockWorkspaceConfig { + get(key: string): unknown; +} + +suite("Configuration", () => { + test("validates killRingMax configuration", () => { + const config = Configuration.instance; + const mockConfig: MockWorkspaceConfig = { + get: (key: string): number | undefined => { + if (key === "killRingMax") return -1; + return undefined; + }, + }; + + // Mock workspace configuration + const originalGetConfiguration = vscode.workspace.getConfiguration; + vscode.workspace.getConfiguration = (): vscode.WorkspaceConfiguration => + mockConfig as vscode.WorkspaceConfiguration; + + try { + // Access configuration to trigger validation + assert.throws(() => { + void config.killRingMax; + }, /killRingMax must be a positive integer/); + } finally { + // Restore mock + vscode.workspace.getConfiguration = originalGetConfiguration; + } + }); + + test("validates debug configuration", () => { + const config = Configuration.instance; + const mockConfig: MockWorkspaceConfig = { + get: (key: string): Record | undefined => { + if (key === "debug") return { silent: "not-a-boolean", loggingLevelForAlert: "invalid" }; + return undefined; + }, + }; + + // Mock workspace configuration + const originalGetConfiguration = vscode.workspace.getConfiguration; + vscode.workspace.getConfiguration = (): vscode.WorkspaceConfiguration => + mockConfig as vscode.WorkspaceConfiguration; + + try { + // Access configuration to trigger validation + assert.throws(() => { + void config.debug; + }, /debug.silent must be a boolean/); + } finally { + // Restore mock + vscode.workspace.getConfiguration = originalGetConfiguration; + } + }); +}); diff --git a/src/test/suite/kill-ring.test.ts b/src/test/suite/kill-ring.test.ts index 97d24b7f4d..bfbbc505d1 100644 --- a/src/test/suite/kill-ring.test.ts +++ b/src/test/suite/kill-ring.test.ts @@ -67,4 +67,29 @@ suite("KillRing", () => { assert.strictEqual(killRing.popNext(), undefined); assert.strictEqual(killRing.popNext(), undefined); }); + + test("handles invalid push data gracefully", () => { + const killRing = new KillRing(3); + + // Test pushing null + assert.doesNotThrow(() => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + killRing.push(null as any); // Testing error handling + }); + assert.strictEqual(killRing.getTop(), undefined); + + // Test pushing undefined + assert.doesNotThrow(() => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + killRing.push(undefined as any); // Testing error handling + }); + assert.strictEqual(killRing.getTop(), undefined); + + // Test pushing invalid entity + assert.doesNotThrow(() => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + killRing.push({ invalid: "entity" } as any); // Testing error handling + }); + assert.strictEqual(killRing.getTop(), undefined); + }); });