The server counted code points while the Library's JavaScript counts UTF-16 units, so a first line of emoji kept 80 emoji on cards but showed 40 in the Library. Both now cut at 80 UTF-16 units and drop a character that would straddle the limit instead of leaving half a surrogate pair.
16 lines
840 B
JavaScript
16 lines
840 B
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
|
|
const { libraryTitle } = await import('../../web/js/workspace/library.mjs').catch(() => ({}));
|
|
|
|
test('library title counts UTF-16 units and never splits a surrogate pair', () => {
|
|
assert.equal(typeof libraryTitle, 'function', 'libraryTitle is exported');
|
|
assert.equal(libraryTitle(' short line \nsecond'), 'short line');
|
|
assert.equal(libraryTitle('a'.repeat(80)), 'a'.repeat(80));
|
|
assert.equal(libraryTitle('a'.repeat(81)), `${'a'.repeat(80)}…`);
|
|
// 80 emoji are 160 UTF-16 units: 40 fit.
|
|
assert.equal(libraryTitle('😀'.repeat(80)), `${'😀'.repeat(40)}…`);
|
|
// 79 units then an emoji: the emoji would straddle the limit, so it is dropped whole.
|
|
assert.equal(libraryTitle(`${'a'.repeat(79)}😀b`), `${'a'.repeat(79)}…`);
|
|
});
|