29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
import { test } from 'node:test';
|
|||
|
|
import assert from 'node:assert/strict';
|
||
|
|
import { decodeHtmlEntities } from './htmlEntities';
|
||
|
|
|
||
|
|
test('decodes the leftover entity from a double-encoded meta tag (Steam)', () => {
|
||
|
|
assert.equal(
|
||
|
|
decodeHtmlEntities('The "Perpetual Testing Initiative" has been expanded'),
|
||
|
|
'The "Perpetual Testing Initiative" has been expanded',
|
||
|
|
);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('named, decimal and hex references', () => {
|
||
|
|
assert.equal(
|
||
|
|
decodeHtmlEntities('Tom & Jerry 'n' co — …'),
|
||
|
|
"Tom & Jerry 'n' co — …",
|
||
|
|
);
|
||
|
|
assert.equal(decodeHtmlEntities('emoji 😀'), 'emoji 😀');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('leaves plain text, unknown names and bare ampersands alone', () => {
|
||
|
|
assert.equal(decodeHtmlEntities('no entities here'), 'no entities here');
|
||
|
|
assert.equal(decodeHtmlEntities('AT&T and &bogus; stay'), 'AT&T and &bogus; stay');
|
||
|
|
assert.equal(decodeHtmlEntities('� �'), '� �');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('decodes only one level (a literal &lt; becomes <, not <)', () => {
|
||
|
|
assert.equal(decodeHtmlEntities('&lt;b&gt;'), '<b>');
|
||
|
|
});
|