asynctest(
'browser.tinymce.core.html.EntitiesTest',
[
'ephox.mcagar.api.LegacyUnit',
'ephox.agar.api.Pipeline',
'tinymce.core.html.Entities'
],
function (LegacyUnit, Pipeline, Entities) {
var success = arguments[arguments.length - 2];
var failure = arguments[arguments.length - 1];
var suite = LegacyUnit.createSuite();
suite.test('encodeRaw', function () {
LegacyUnit.equal(
Entities.encodeRaw('<>"\'&\u00e5\u00e4\u00f6\u0060'),
'<>"\'&\u00e5\u00e4\u00f6\u0060',
'Raw encoding text'
);
LegacyUnit.equal(
Entities.encodeRaw('<>"\'&\u00e5\u00e4\u00f6\u0060', true),
'<>"\'&\u00e5\u00e4\u00f6`',
'Raw encoding attribute'
);
});
suite.test('encodeAllRaw', function () {
LegacyUnit.equal(Entities.encodeAllRaw('<>"\'&\u00e5\u00e4\u00f6'), '<>"'&\u00e5\u00e4\u00f6', 'Raw encoding all');
});
suite.test('encodeNumeric', function () {
LegacyUnit.equal(
Entities.encodeNumeric('<>"\'&\u00e5\u00e4\u00f6\u03b8\u2170\ufa11'),
'<>"\'&åäöθⅰ﨑',
'Numeric encoding text'
);
LegacyUnit.equal(
Entities.encodeNumeric('<>"\'&\u00e5\u00e4\u00f6', true),
'<>"\'&åäö',
'Numeric encoding attribute'
);
});
suite.test('encodeNamed', function () {
LegacyUnit.equal(Entities.encodeNamed('<>"\'&\u00e5\u00e4\u00f6'), '<>"\'&åäö', 'Named encoding text');
LegacyUnit.equal(
Entities.encodeNamed('<>"\'&\u00e5\u00e4\u00f6', true),
'<>"\'&åäö',
'Named encoding attribute'
);
LegacyUnit.equal(
Entities.encodeNamed('<>"\'\u00e5\u00e4\u00f6', false, { '\u00e5': 'å' }),
'<>"\'å\u00e4\u00f6',
'Named encoding text'
);
LegacyUnit.equal(
Entities.encodeNamed('<>"\'\u00e5\u00e4\u00f6', true, { '\u00e5': 'å' }),
'<>"\'å\u00e4\u00f6',
'Named encoding attribute'
);
});
suite.test('getEncodeFunc', function () {
var encodeFunc;
encodeFunc = Entities.getEncodeFunc('raw');
LegacyUnit.equal(encodeFunc('<>"\'&\u00e5\u00e4\u00f6'), '<>"\'&\u00e5\u00e4\u00f6', 'Raw encoding text');
LegacyUnit.equal(encodeFunc('<>"\'&\u00e5\u00e4\u00f6', true), '<>"\'&\u00e5\u00e4\u00f6', 'Raw encoding attribute');
LegacyUnit.equal(encodeFunc('\ud87e\udc04'), '\ud87e\udc04', 'Raw high-byte encoding text');
LegacyUnit.equal(encodeFunc('\ud87e\udc04', true), '\ud87e\udc04', 'Raw high-byte encoding attribute');
encodeFunc = Entities.getEncodeFunc('named');
LegacyUnit.equal(encodeFunc('<>"\'&\u00e5\u00e4\u00f6'), '<>"\'&åäö', 'Named encoding text');
LegacyUnit.equal(
encodeFunc('<>"\'&\u00e5\u00e4\u00f6', true),
'<>"\'&åäö',
'Named encoding attribute'
);
LegacyUnit.equal(encodeFunc('\ud87e\udc04'), '\ud87e\udc04', 'Named high-byte encoding text');
LegacyUnit.equal(encodeFunc('\ud87e\udc04', true), '\ud87e\udc04', 'Named high-byte encoding attribute');
encodeFunc = Entities.getEncodeFunc('numeric');
LegacyUnit.equal(encodeFunc('<>"\'&\u00e5\u00e4\u00f6'), '<>"\'&åäö', 'Numeric encoding text');
LegacyUnit.equal(
encodeFunc('<>"\'&\u00e5\u00e4\u00f6', true),
'<>"\'&åäö',
'Numeric encoding attribute');
LegacyUnit.equal(encodeFunc('\ud87e\udc04'), '你', 'Numeric high-byte encoding text');
LegacyUnit.equal(encodeFunc('\ud87e\udc04', true), '你', 'Numeric high-byte encoding attribute');
encodeFunc = Entities.getEncodeFunc('named+numeric', '229,aring');
LegacyUnit.equal(encodeFunc('<>"\'&\u00e5\u00e4\u00f6'), '<>"\'&åäö', 'Named+numeric encoding text');
LegacyUnit.equal(
encodeFunc('<>"\'&\u00e5\u00e4\u00f6', true),
'<>"\'&åäö',
'Named+numeric encoding attribute'
);
LegacyUnit.equal(encodeFunc('\ud87e\udc04'), '你', 'Named+numeric high-byte encoding text');
LegacyUnit.equal(encodeFunc('\ud87e\udc04', true), '你', 'Named+numeric high-byte encoding attribute');
encodeFunc = Entities.getEncodeFunc('named,numeric', '229,aring');
LegacyUnit.equal(encodeFunc('<>"\'&\u00e5\u00e4\u00f6'), '<>"\'&åäö', 'Named+numeric encoding text');
LegacyUnit.equal(
encodeFunc('<>"\'&\u00e5\u00e4\u00f6', true),
'<>"\'&åäö',
'Named+numeric encoding attribute'
);
LegacyUnit.equal(encodeFunc('\ud87e\udc04'), '你', 'Named+numeric high-byte encoding text');
LegacyUnit.equal(encodeFunc('\ud87e\udc04', true), '你', 'Named+numeric high-byte encoding attribute');
});
suite.test('decode', function () {
LegacyUnit.equal(
Entities.decode('<>"'&åäö&unknown;'),
'<>"\'&\u00e5\u00e4\u00f6&unknown;',
'Decode text with various entities'
);
LegacyUnit.equal(Entities.decode('AB''), 'AB\'', 'Decode numeric entities');
LegacyUnit.equal(Entities.decode('OO''), 'OO\'', 'Decode hexanumeric entities');
LegacyUnit.equal(Entities.decode('ABC'), 'ABC', 'Decode numeric entities with no semicolon');
LegacyUnit.equal(Entities.decode('&test'), '&test', 'Dont decode invalid entity name without semicolon');
LegacyUnit.equal(Entities.encodeNumeric(Entities.decode(
'‚ƒ„…†‡ˆ‰Š' +
'‹ŒŽ‘’“”•–—˜' +
'™š›œžŸ')
), '‚ƒ„…†‡ˆ‰Š‹ŒŽ' +
'‘’“”•–—˜™š' +
'›œžŸ',
'Entity decode ascii');
LegacyUnit.equal(Entities.encodeNumeric(Entities.decode('你')), '你', "High byte non western character.");
});
Pipeline.async({}, suite.toSteps({}), function () {
success();
}, failure);
}
);
|