Fix even even even more bugs

This commit is contained in:
Kalle
2026-08-05 16:33:23 +03:00
parent e65dd86683
commit b3e723e245
17 changed files with 517 additions and 29 deletions

View File

@@ -21,6 +21,11 @@ describe("pathnameFromPotentialURL()", () => {
"FW4dKrY",
);
});
test("Resolves a scheme-less URL paste to the path", () => {
// otherwise the generated discordUrl becomes https://discord.gg/discord.gg/FW4dKrY
expect(pathnameFromPotentialURL("discord.gg/FW4dKrY")).toBe("FW4dKrY");
});
});
describe("truncateBySentence()", () => {
@@ -53,6 +58,17 @@ describe("truncateBySentence()", () => {
const text = "First line\nSecond line\nThird line";
expect(truncateBySentence(text, 20)).toBe("First line");
});
test("Does not treat a period inside a time like 18.00 as a sentence end", () => {
const text =
"Doors at 18.00, we will be playing five rounds of swiss followed by a top cut.";
expect(truncateBySentence(text, 40)).not.toBe("Doors at 18.");
});
test("Does not return a tiny fraction of the budget when a long sentence follows a short one", () => {
const text = `Hi. ${"x".repeat(400)}. Everyone is welcome.`;
expect(truncateBySentence(text, 300)).not.toBe("Hi.");
});
});
describe("removeMarkdown()", () => {
@@ -71,6 +87,11 @@ describe("removeMarkdown()", () => {
expect(removeMarkdown("café & tea")).toBe("café & tea");
});
test("Does not throw on an out of range numeric entity", () => {
// e.g. an organizer writing a hex color code in the description
expect(() => removeMarkdown("background: � here")).not.toThrow();
});
test("Leaves unknown named entities untouched", () => {
expect(removeMarkdown("AT&T &fakeentity; rules")).toBe(
"AT&T &fakeentity; rules",