|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { escapeText } from "./index"; |
| 3 | + |
| 4 | +describe("escapeText", () => { |
| 5 | + it("should handle empty string", () => { |
| 6 | + expect(escapeText("")).toBe(""); |
| 7 | + }); |
| 8 | + |
| 9 | + it("should return unchanged string when no special characters present", () => { |
| 10 | + expect(escapeText("hello world")).toBe("hello world"); |
| 11 | + }); |
| 12 | + |
| 13 | + it("should escape single less than symbol", () => { |
| 14 | + expect(escapeText("<")).toBe("<"); |
| 15 | + }); |
| 16 | + |
| 17 | + it("should escape single ampersand", () => { |
| 18 | + expect(escapeText("&")).toBe("&"); |
| 19 | + }); |
| 20 | + |
| 21 | + it("should escape multiple less than symbols", () => { |
| 22 | + expect(escapeText("a < b < c")).toBe("a < b < c"); |
| 23 | + }); |
| 24 | + |
| 25 | + it("should escape multiple ampersands", () => { |
| 26 | + expect(escapeText("a & b & c")).toBe("a & b & c"); |
| 27 | + }); |
| 28 | + |
| 29 | + it("should escape mixed special characters", () => { |
| 30 | + expect(escapeText("a < b & c")).toBe("a < b & c"); |
| 31 | + }); |
| 32 | + |
| 33 | + it("should handle special characters at string boundaries", () => { |
| 34 | + expect(escapeText("<start>&end")).toBe("<start>&end"); |
| 35 | + }); |
| 36 | + |
| 37 | + it("should handle HTML-like content", () => { |
| 38 | + expect(escapeText("<div> </div>")).toBe("<div>&nbsp;</div>"); |
| 39 | + }); |
| 40 | + |
| 41 | + it("should handle consecutive special characters", () => { |
| 42 | + expect(escapeText("<<&&")).toBe("<<&&"); |
| 43 | + }); |
| 44 | + |
| 45 | + it("should handle long text with multiple special characters", () => { |
| 46 | + const input = "This is a <test> with multiple & special < characters & more"; |
| 47 | + const expected = "This is a <test> with multiple & special < characters & more"; |
| 48 | + expect(escapeText(input)).toBe(expected); |
| 49 | + }); |
| 50 | + |
| 51 | + it("should handle special characters with surrounding whitespace", () => { |
| 52 | + expect(escapeText(" < & ")).toBe(" < & "); |
| 53 | + }); |
| 54 | + |
| 55 | + it("should maintain other special characters unchanged", () => { |
| 56 | + expect(escapeText("\"'!@#$%^*()_+")).toBe("\"'!@#$%^*()_+"); |
| 57 | + }); |
| 58 | + |
| 59 | + it("should handle unicode characters correctly", () => { |
| 60 | + expect(escapeText("→ < & →")).toBe("→ < & →"); |
| 61 | + }); |
| 62 | +}); |
0 commit comments