64 lines
1.9 KiB
JavaScript
64 lines
1.9 KiB
JavaScript
/**
|
|
* Unit Tests for XML Utilities
|
|
* Tests XML escaping functionality
|
|
*/
|
|
|
|
import { test, describe } from 'node:test';
|
|
import assert from 'node:assert';
|
|
import { escapeXml } from '../../src/xml-utils.js';
|
|
|
|
describe('Unit: XML Escaping', () => {
|
|
|
|
test('T045: Should escape ampersand (&)', () => {
|
|
const input = 'Rock & Roll';
|
|
const expected = 'Rock & Roll';
|
|
assert.strictEqual(escapeXml(input), expected);
|
|
});
|
|
|
|
test('T045: Should escape less than (<)', () => {
|
|
const input = '5 < 10';
|
|
const expected = '5 < 10';
|
|
assert.strictEqual(escapeXml(input), expected);
|
|
});
|
|
|
|
test('T045: Should escape greater than (>)', () => {
|
|
const input = '10 > 5';
|
|
const expected = '10 > 5';
|
|
assert.strictEqual(escapeXml(input), expected);
|
|
});
|
|
|
|
test('T045: Should escape double quote (")', () => {
|
|
const input = 'Say "Hello"';
|
|
const expected = 'Say "Hello"';
|
|
assert.strictEqual(escapeXml(input), expected);
|
|
});
|
|
|
|
test('T045: Should escape single quote (\')', () => {
|
|
const input = "It's working";
|
|
const expected = 'It's working';
|
|
assert.strictEqual(escapeXml(input), expected);
|
|
});
|
|
|
|
test('T045: Should escape multiple special characters', () => {
|
|
const input = '<tag attr="value">Content & stuff</tag>';
|
|
const expected = '<tag attr="value">Content & stuff</tag>';
|
|
assert.strictEqual(escapeXml(input), expected);
|
|
});
|
|
|
|
test('T045: Should handle empty string', () => {
|
|
assert.strictEqual(escapeXml(''), '');
|
|
});
|
|
|
|
test('T045: Should handle non-string input', () => {
|
|
assert.strictEqual(escapeXml(null), '');
|
|
assert.strictEqual(escapeXml(undefined), '');
|
|
assert.strictEqual(escapeXml(123), '');
|
|
});
|
|
|
|
test('T045: Should not modify safe strings', () => {
|
|
const input = 'This is a safe string 123';
|
|
assert.strictEqual(escapeXml(input), input);
|
|
});
|
|
|
|
});
|