import { describe, it, expect } from 'vitest'; import { escapeXml } from '../../../tools/lib/xml-utils.js'; describe('xml-utils', () => { describe('escapeXml()', () => { it('should escape ampersand (&) to &', () => { expect(escapeXml('Tom & Jerry')).toBe('Tom & Jerry'); }); it('should escape less than (<) to <', () => { expect(escapeXml('5 < 10')).toBe('5 < 10'); }); it('should escape greater than (>) to >', () => { expect(escapeXml('10 > 5')).toBe('10 > 5'); }); it('should escape double quote (") to "', () => { expect(escapeXml('He said "hello"')).toBe('He said "hello"'); }); it("should escape single quote (') to '", () => { expect(escapeXml("It's working")).toBe('It's working'); }); it('should preserve Unicode characters', () => { expect(escapeXml('Hello δΈ–η•Œ 🌍')).toBe('Hello δΈ–η•Œ 🌍'); }); it('should escape multiple special characters in sequence', () => { expect(escapeXml('')).toBe('<tag attr="value">'); }); it('should escape all five special characters together', () => { expect(escapeXml(`&<>"'`)).toBe('&<>"''); }); it('should handle empty string', () => { expect(escapeXml('')).toBe(''); }); it('should handle null', () => { expect(escapeXml(null)).toBe(''); }); it('should handle undefined', () => { expect(escapeXml()).toBe(''); }); it('should handle text with no special characters', () => { expect(escapeXml('Hello World')).toBe('Hello World'); }); it('should handle text that is only special characters', () => { expect(escapeXml('&&&')).toBe('&&&'); }); it('should not double-escape already escaped entities', () => { // Note: This is expected behavior - the function WILL double-escape // This test documents the actual behavior expect(escapeXml('&')).toBe('&amp;'); }); it('should escape special characters in XML content', () => { const xmlContent = 'Use tags'; const expected = '<persona role="Developer & Architect">Use <code> tags</persona>'; expect(escapeXml(xmlContent)).toBe(expected); }); it('should handle mixed Unicode and special characters', () => { expect(escapeXml('ζ΅‹θ―• & "quotes"')).toBe('ζ΅‹θ―• <tag> & "quotes"'); }); it('should handle newlines and special characters', () => { const multiline = 'Line 1 & text\n\n"Line 3"'; const expected = 'Line 1 & text\n<Line 2>\n"Line 3"'; expect(escapeXml(multiline)).toBe(expected); }); it('should handle string with only whitespace', () => { expect(escapeXml(' ')).toBe(' '); }); }); });