Skip to content

Commit 4c05d91

Browse files
committed
test(config): prove UTF-16 allowed-value hint boundary
1 parent ade1821 commit 4c05d91

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/config/allowed-values.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ describe("summarizeAllowedValues", () => {
2323
});
2424
});
2525

26+
it("counts the omitted UTF-16 units after preserving a surrogate pair", () => {
27+
const prefix = "a".repeat(159);
28+
const value = `${prefix}😀tail`;
29+
30+
expect(summarizeAllowedValues([value])).toStrictEqual({
31+
formatted: `"${prefix}... (+6 chars)"`,
32+
hiddenCount: 0,
33+
values: [value],
34+
});
35+
});
36+
2637
it("returns empty label for undefined allowed value", () => {
2738
const summary = summarizeAllowedValues([undefined]);
2839
expect(summary).toStrictEqual({

src/config/allowed-values.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ function truncateHintText(text: string, limit: number): string {
1515
if (text.length <= limit) {
1616
return text;
1717
}
18-
return `${truncateUtf16Safe(text, limit)}... (+${text.length - limit} chars)`;
18+
const truncated = truncateUtf16Safe(text, limit);
19+
return `${truncated}... (+${text.length - truncated.length} chars)`;
1920
}
2021

2122
function safeStringify(value: unknown): string {

0 commit comments

Comments
 (0)