-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add configuration validation and kill-ring error handling tests
- Loading branch information
1 parent
ce6e5d1
commit be4f0b9
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters