Files
vscode-codeql/extensions/ql-vscode/test/mock-memento.ts
2024-01-05 17:13:45 +01:00

29 lines
693 B
TypeScript

import type { Memento } from "../src/common/memento";
export function createMockMemento(): Memento {
return new MockMemento();
}
class MockMemento<T> implements Memento {
private readonly map: Map<string, T>;
constructor() {
this.map = new Map<string, T>();
}
public keys(): readonly string[] {
return Array.from(this.map.keys());
}
public get<T>(key: string): T | undefined;
public get<T>(key: string, defaultValue: T): T;
public get(key: any, defaultValue?: any): T | T | undefined {
return this.map.get(key) || defaultValue;
}
public update(key: string, value: any): Thenable<void> {
this.map.set(key, value);
return Promise.resolve();
}
}