const test = require('tap').test;
const xml = require('../../src/util/xml-escape');
test('escape', t => {
const input = '';
const output = '<foo bar="he & llo '"></foo>';
t.strictEqual(xml(input), output);
t.end();
});
test('xmlEscape (more)', t => {
const empty = '';
t.equal(xml(empty), empty);
const safe = 'hello';
t.equal(xml(safe), safe);
const unsafe = '< > & \' "';
t.equal(xml(unsafe), '< > & ' "');
const single = '&';
t.equal(xml(single), '&');
const mix = 'b& c\'def_-"';
t.equal(xml(mix), '<a>b& c'def_-"');
const dupes = '<<&_"_"_&>>';
t.equal(xml(dupes), '<<&_"_"_&>>');
const emoji = '(>^_^)>';
t.equal(xml(emoji), '(>^_^)>');
t.end();
});
test('xmlEscape should handle non strings', t => {
const array = ['hello', 'world'];
t.equal(xml(array), String(array));
const arrayWithSpecialChar = ['hello', ''];
t.equal(xml(arrayWithSpecialChar), 'hello,<world>');
const arrayWithNumbers = [1, 2, 3];
t.equal(xml(arrayWithNumbers), '1,2,3');
// Objects shouldn't get provided to replaceUnsafeChars, but in the event
// they do, it should just return the object (and log an error)
const object = {hello: 'world'};
t.equal(xml(object), object);
t.end();
});