Files
boss/tests/android-markdown-cache.test.ts

32 lines
1.0 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
test("BossMarkdown caches rendered markdown spans for repeated bodies", async () => {
const source = await readFile(
new URL("../android/app/src/main/java/com/hyzq/boss/BossMarkdown.java", import.meta.url),
"utf8",
);
assert.match(
source,
/private static final LruCache<String, CharSequence> RENDER_CACHE = new LruCache<>\(/,
"expected markdown renderer to keep an LRU cache for rendered spans",
);
assert.match(
source,
/String cacheKey = buildCacheKey\(context, markdown, outgoing\);/,
"expected markdown renderer to derive a stable cache key before parsing",
);
assert.match(
source,
/CharSequence cached = RENDER_CACHE\.get\(cacheKey\);/,
"expected markdown renderer to reuse cached spans when available",
);
assert.match(
source,
/RENDER_CACHE\.put\(cacheKey, rendered\);/,
"expected markdown renderer to save rendered spans into the cache",
);
});