Skip to content

Commit

Permalink
test: Add configuration validation and kill-ring error handling tests
Browse files Browse the repository at this point in the history
  • Loading branch information
devin-ai-integration[bot] committed Jan 3, 2025
1 parent ce6e5d1 commit be4f0b9
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/test/suite/configuration.test.ts
Original file line number Diff line number Diff line change
@@ -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<string, unknown> | 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;
}
});
});
25 changes: 25 additions & 0 deletions src/test/suite/kill-ring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit be4f0b9

Please sign in to comment.