- render comment rows and line selection state in the native diff view - wire long-press/tap gestures to start and complete review comments - tighten shared diff utilities and add coverage
53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { LRUCache } from "./lruCache";
|
|
|
|
describe("LRUCache", () => {
|
|
it("returns null for missing keys", () => {
|
|
const cache = new LRUCache<string>(2, 100);
|
|
expect(cache.get("missing")).toBeNull();
|
|
});
|
|
|
|
it("evicts oldest by max entries", () => {
|
|
const cache = new LRUCache<string>(2, 1_000);
|
|
cache.set("a", "A", 10);
|
|
cache.set("b", "B", 10);
|
|
cache.set("c", "C", 10);
|
|
|
|
expect(cache.get("a")).toBeNull();
|
|
expect(cache.get("b")).toBe("B");
|
|
expect(cache.get("c")).toBe("C");
|
|
});
|
|
|
|
it("promotes on get and evicts least recently used", () => {
|
|
const cache = new LRUCache<string>(2, 1_000);
|
|
cache.set("a", "A", 10);
|
|
cache.set("b", "B", 10);
|
|
expect(cache.get("a")).toBe("A");
|
|
|
|
cache.set("c", "C", 10);
|
|
expect(cache.get("a")).toBe("A");
|
|
expect(cache.get("b")).toBeNull();
|
|
expect(cache.get("c")).toBe("C");
|
|
});
|
|
|
|
it("evicts by memory budget", () => {
|
|
const cache = new LRUCache<string>(10, 25);
|
|
cache.set("a", "A", 10);
|
|
cache.set("b", "B", 10);
|
|
cache.set("c", "C", 10);
|
|
|
|
expect(cache.get("a")).toBeNull();
|
|
expect(cache.get("b")).toBe("B");
|
|
expect(cache.get("c")).toBe("C");
|
|
});
|
|
|
|
it("does not cache entries larger than the memory budget", () => {
|
|
const cache = new LRUCache<string>(2, 25);
|
|
cache.set("a", "A", 10);
|
|
cache.set("oversized", "X", 30);
|
|
|
|
expect(cache.get("a")).toBe("A");
|
|
expect(cache.get("oversized")).toBeNull();
|
|
});
|
|
});
|