/* global describe, it */ import { replaceEmoji } from '../../src/routes/_utils/replaceEmoji.js' import assert from 'assert' const mindBlown = String.fromCodePoint(0x1F92F) const elephant = String.fromCodePoint(0x1F418) const womanBowing = [0x1f647, 0x200d, 0x2640, 0xfe0f].map(_ => String.fromCodePoint(_)).join('') describe('test-emoji.js', function () { it('does emoji replacement correctly', function () { const replacer = _ => `
${_}
` assert.strictEqual( replaceEmoji('hello world', replacer), 'hello world' ) assert.strictEqual( replaceEmoji(`${mindBlown}`, replacer), `
${mindBlown}
` ) assert.strictEqual( replaceEmoji(`${mindBlown} ${elephant}`, replacer), `
${mindBlown}
${elephant}
` ) assert.strictEqual( replaceEmoji(`${elephant} woot ${mindBlown}`, replacer), `
${elephant}
woot
${mindBlown}
` ) assert.strictEqual( replaceEmoji(`woot ${mindBlown}`, replacer), `woot
${mindBlown}
` ) assert.strictEqual( replaceEmoji(`${mindBlown} woot`, replacer), `
${mindBlown}
woot` ) }) it('handles multi-code emoji', function () { const replacer = _ => `
${_}
` assert.strictEqual( replaceEmoji(`hello ${womanBowing}`, replacer), `hello
${womanBowing}
` ) }) it('handles emoji mixed with custom emoji', function () { const replacer = _ => `
${_}
` assert.strictEqual( replaceEmoji(`hello ${womanBowing} and :blobpats: and ${elephant}`, replacer), `hello
${womanBowing}
and :blobpats: and
${elephant}
` ) }) it('handles sequential emoji', function () { const replacer = _ => `
${_}
` assert.strictEqual( replaceEmoji(`${elephant}${elephant}${womanBowing}${mindBlown}`, replacer), `
${elephant}
${elephant}
${womanBowing}
${mindBlown}
` ) }) it('does not replace non-emoji characters', function () { const replacer = _ => `
${_}
` assert.strictEqual( replaceEmoji('it\'s over #9000', replacer), 'it\'s over #9000' ) assert.strictEqual( replaceEmoji('woot !@#$%^&*()~' + '`' + '{[}]:;"\'<,>.?/£™℠®', replacer), 'woot !@#$%^&*()~' + '`' + '{[}]:;"\'<,>.?/£™℠®' ) assert.strictEqual( replaceEmoji('woot !@#$%^&*()~' + '`' + '{[}]:;"\'<,>.?/£™℠®', replacer), 'woot !@#$%^&*()~' + '`' + '{[}]:;"\'<,>.?/£™℠®' ) // hidden VARIATION SELECTOR character is in here assert.strictEqual( replaceEmoji("

It's shapes™️ ... continued

", replacer), "

It's shapes™️ ... continued

" ) }) it('does not replace emoji inside HTML tags', function () { const replacer = _ => `
${_}
` assert.strictEqual( replaceEmoji(`check this cool link: link`, replacer), `check this cool link: link` ) assert.strictEqual( replaceEmoji( `link and link`, replacer ), `link and link` ) assert.strictEqual( replaceEmoji( `link and ${mindBlown}`, replacer ), `link and
${mindBlown}
` ) assert.strictEqual( replaceEmoji( `link and ${mindBlown} and ` + `link`, replacer ), `link and
${mindBlown}
and ` + `link` ) }) it('removes emoji', function () { const replacer = _ => '' assert.strictEqual( replaceEmoji(`woot ${mindBlown}`, replacer), 'woot ' ) assert.strictEqual( replaceEmoji(`woot ${mindBlown} woot`, replacer), 'woot woot' ) assert.strictEqual( replaceEmoji(`woot ${mindBlown}${elephant}`, replacer), 'woot ' ) assert.strictEqual( replaceEmoji(`woot ${mindBlown}${elephant} woot`, replacer), 'woot woot' ) }) it('can handle a dangling left angle bracket for some reason', function () { const replacer = _ => `
${_}
` assert.strictEqual( replaceEmoji(`woot ${mindBlown} <`, replacer), `woot
${mindBlown}
<` ) assert.strictEqual( replaceEmoji(`woot ${mindBlown} ${mindBlown}