|
1 | | -import { normalizeString } from "../text-normalization" |
| 1 | +import { normalizeString, unescapeHtmlEntities } from "../text-normalization" |
2 | 2 |
|
3 | 3 | describe("Text normalization utilities", () => { |
4 | 4 | describe("normalizeString", () => { |
@@ -30,4 +30,50 @@ describe("Text normalization utilities", () => { |
30 | 30 | expect(normalizeString(input)).toBe('Let\'s test this-with some "fancy" punctuation... and spaces') |
31 | 31 | }) |
32 | 32 | }) |
| 33 | + |
| 34 | + describe("unescapeHtmlEntities", () => { |
| 35 | + test("unescapes basic HTML entities", () => { |
| 36 | + expect(unescapeHtmlEntities("<div>Hello</div>")).toBe("<div>Hello</div>") |
| 37 | + }) |
| 38 | + |
| 39 | + test("unescapes ampersand entity", () => { |
| 40 | + expect(unescapeHtmlEntities("This & that")).toBe("This & that") |
| 41 | + }) |
| 42 | + |
| 43 | + test("unescapes quote entities", () => { |
| 44 | + expect(unescapeHtmlEntities(""quoted" and 'single-quoted'")).toBe( |
| 45 | + "\"quoted\" and 'single-quoted'", |
| 46 | + ) |
| 47 | + }) |
| 48 | + |
| 49 | + test("unescapes apostrophe entity", () => { |
| 50 | + expect(unescapeHtmlEntities("Don't worry")).toBe("Don't worry") |
| 51 | + }) |
| 52 | + |
| 53 | + test("handles mixed content with multiple entity types", () => { |
| 54 | + expect( |
| 55 | + unescapeHtmlEntities( |
| 56 | + "<a href="https://example.com?param1=value&param2=value">Link</a>", |
| 57 | + ), |
| 58 | + ).toBe('<a href="https://example.com?param1=value¶m2=value">Link</a>') |
| 59 | + }) |
| 60 | + |
| 61 | + test("handles mixed content with apostrophe entities", () => { |
| 62 | + expect( |
| 63 | + unescapeHtmlEntities( |
| 64 | + "<div>Don't forget that Tom&Jerry's show is at 3 o'clock</div>", |
| 65 | + ), |
| 66 | + ).toBe("<div>Don't forget that Tom&Jerry's show is at 3 o'clock</div>") |
| 67 | + }) |
| 68 | + |
| 69 | + test("returns original string when no entities are present", () => { |
| 70 | + const original = "Plain text without entities" |
| 71 | + expect(unescapeHtmlEntities(original)).toBe(original) |
| 72 | + }) |
| 73 | + |
| 74 | + test("handles empty or undefined input", () => { |
| 75 | + expect(unescapeHtmlEntities("")).toBe("") |
| 76 | + expect(unescapeHtmlEntities(undefined as unknown as string)).toBe(undefined) |
| 77 | + }) |
| 78 | + }) |
33 | 79 | }) |
0 commit comments