[ { "name": "text that fits is returned unchanged", "args": ["Hello world", 20, "…"], "expect": "Hello world" }, { "name": "text exactly at the limit is returned unchanged, no ellipsis", "args": ["Hello world", 11, "…"], "expect": "Hello world" }, { "name": "one over the limit backs up to the previous word", "args": ["Hello world", 10, "…"], "expect": "Hello…" }, { "name": "a cut that lands before a space keeps the whole word", "args": ["Hello world again", 12, "…"], "expect": "Hello world…" }, { "name": "the ellipsis counts towards the limit", "args": ["Hello world again", 14, "..."], "expect": "Hello world..." }, { "name": "a trailing comma is dropped before the ellipsis", "args": ["Hello, world", 10, "..."], "expect": "Hello..." }, { "name": "one long word is cut hard rather than lost", "args": ["Supercalifragilistic", 10, "…"], "expect": "Supercali…" }, { "name": "accented letters count once each", "args": ["Crème brûlée à la carte", 14, "…"], "expect": "Crème brûlée…" }, { "name": "emoji count as one code point, not two UTF-16 units", "args": ["😀😀😀 abc", 5, "…"], "expect": "😀😀😀…" }, { "name": "a line break is a word boundary", "args": ["Line one\nLine two", 10, "…"], "expect": "Line one…" }, { "name": "a no-break space is a word boundary too", "args": ["Mr\u00a0Smithson", 9, "…"], "expect": "Mr…" }, { "name": "an empty ellipsis gives a plain cut", "args": ["Hello world", 5, ""], "expect": "Hello" }, { "name": "room for only the ellipsis", "args": ["Hello world", 1, "…"], "expect": "…" }, { "name": "the empty string fits any limit", "args": ["", 5, "…"], "expect": "" }, { "name": "zero length with no ellipsis is the empty string", "args": ["Hello", 0, ""], "expect": "" }, { "name": "a combining accent can be split from its letter: a documented limit", "args": ["café", 4, ""], "expect": "cafe" }, { "name": "a limit shorter than the ellipsis is an error", "args": ["Hello world", 2, "..."], "expectError": "maxLength must be at least the length of the ellipsis" }, { "name": "a negative limit is an error", "args": ["Hello world", -1, ""], "expectError": "maxLength must be 0 or greater" } ]