mirror of https://github.com/openclaw/openclaw.git
test: tighten shared code region coverage
This commit is contained in:
parent
fa04e62201
commit
73c2edbc0c
|
|
@ -52,4 +52,14 @@ describe("resolveGlobalMap", () => {
|
|||
|
||||
expect(resolveGlobalMap<string, number>(TEST_MAP_KEY).get("a")).toBe(1);
|
||||
});
|
||||
|
||||
it("reuses a prepopulated global map without creating a new one", () => {
|
||||
const existing = new Map<string, number>([["a", 1]]);
|
||||
(globalThis as Record<PropertyKey, unknown>)[TEST_MAP_KEY] = existing;
|
||||
|
||||
const resolved = resolveGlobalMap<string, number>(TEST_MAP_KEY);
|
||||
|
||||
expect(resolved).toBe(existing);
|
||||
expect(resolved.get("a")).toBe(1);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -27,13 +27,25 @@ describe("shared/text/code-regions", () => {
|
|||
expect(text.slice(regions[1].start, regions[1].end)).toBe("```\nunterminated");
|
||||
});
|
||||
|
||||
it("keeps adjacent inline code outside fenced regions", () => {
|
||||
const text = ["```ts", "const a = 1;", "```", "after `inline` tail"].join("\n");
|
||||
|
||||
const regions = findCodeRegions(text);
|
||||
|
||||
expect(regions).toHaveLength(2);
|
||||
expect(text.slice(regions[0].start, regions[0].end)).toContain("```ts");
|
||||
expect(text.slice(regions[1].start, regions[1].end)).toBe("`inline`");
|
||||
});
|
||||
|
||||
it("reports whether positions are inside discovered regions", () => {
|
||||
const text = "plain `code` done";
|
||||
const regions = findCodeRegions(text);
|
||||
const codeStart = text.indexOf("code");
|
||||
const plainStart = text.indexOf("plain");
|
||||
const regionEnd = regions[0]?.end ?? -1;
|
||||
|
||||
expect(isInsideCode(codeStart, regions)).toBe(true);
|
||||
expect(isInsideCode(plainStart, regions)).toBe(false);
|
||||
expect(isInsideCode(regionEnd, regions)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue