|
| 1 | +import { describe, it, expect } from "vitest" |
| 2 | +import { unescapeHtmlEntities } from "../text-normalization" |
| 3 | + |
| 4 | +describe("HTML Entity Preservation", () => { |
| 5 | + describe("unescapeHtmlEntities", () => { |
| 6 | + it("should unescape basic HTML entities", () => { |
| 7 | + expect(unescapeHtmlEntities("<div>")).toBe("<div>") |
| 8 | + expect(unescapeHtmlEntities("&")).toBe("&") |
| 9 | + expect(unescapeHtmlEntities(""")).toBe('"') |
| 10 | + expect(unescapeHtmlEntities("'")).toBe("'") |
| 11 | + }) |
| 12 | + |
| 13 | + it("should handle complex HTML with multiple entities", () => { |
| 14 | + const input = "<a href="https://example.com?param1=value&param2=value">Link</a>" |
| 15 | + const expected = '<a href="https://example.com?param1=value¶m2=value">Link</a>' |
| 16 | + expect(unescapeHtmlEntities(input)).toBe(expected) |
| 17 | + }) |
| 18 | + |
| 19 | + it("should preserve text without entities", () => { |
| 20 | + const text = "Plain text without entities" |
| 21 | + expect(unescapeHtmlEntities(text)).toBe(text) |
| 22 | + }) |
| 23 | + |
| 24 | + it("should handle empty or undefined input", () => { |
| 25 | + expect(unescapeHtmlEntities("")).toBe("") |
| 26 | + expect(unescapeHtmlEntities(undefined as unknown as string)).toBe(undefined) |
| 27 | + }) |
| 28 | + |
| 29 | + it("should unescape square bracket entities", () => { |
| 30 | + expect(unescapeHtmlEntities("array[0]")).toBe("array[0]") |
| 31 | + expect(unescapeHtmlEntities("string[]")).toBe("string[]") |
| 32 | + }) |
| 33 | + }) |
| 34 | + |
| 35 | + describe("Setting-based HTML entity handling", () => { |
| 36 | + it("should document that preserveHtmlEntities=false triggers unescaping", () => { |
| 37 | + // When preserveHtmlEntities is false (default for non-Claude models), |
| 38 | + // HTML entities should be unescaped |
| 39 | + const input = "<test>" |
| 40 | + const output = unescapeHtmlEntities(input) |
| 41 | + expect(output).toBe("<test>") |
| 42 | + }) |
| 43 | + |
| 44 | + it("should document that preserveHtmlEntities=true skips unescaping", () => { |
| 45 | + // When preserveHtmlEntities is true, the content should remain as-is |
| 46 | + // This is tested by NOT calling unescapeHtmlEntities |
| 47 | + const input = "<test>" |
| 48 | + // In actual usage, when preserveHtmlEntities=true, we skip calling unescapeHtmlEntities |
| 49 | + expect(input).toBe("<test>") |
| 50 | + }) |
| 51 | + |
| 52 | + it("should handle code with HTML-like syntax", () => { |
| 53 | + const codeWithHtml = "if (x < 10 && y > 5) { return true; }" |
| 54 | + const expected = "if (x < 10 && y > 5) { return true; }" |
| 55 | + expect(unescapeHtmlEntities(codeWithHtml)).toBe(expected) |
| 56 | + }) |
| 57 | + |
| 58 | + it("should handle XML/JSX code", () => { |
| 59 | + const jsx = "<Component prop="value">{children}</Component>" |
| 60 | + const expected = '<Component prop="value">{children}</Component>' |
| 61 | + expect(unescapeHtmlEntities(jsx)).toBe(expected) |
| 62 | + }) |
| 63 | + }) |
| 64 | +}) |
0 commit comments