Template-Toolkit

 view release on metacpan or  search on metacpan

t/truncate_cer.t  view on Meta::CPAN

        name   => 'mixed suffix: "...…" counts as 4 chars (3 dots + 1 entity)',
        input  => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
        tmpl   => '[% text | truncate(10, "...…") %]',
        expect => 'ABCDEF...…',
    },

    #--------------------------------------------------------------------
    # Entity in input text — should not be split
    #--------------------------------------------------------------------
    {
        name   => 'entity in input text not split mid-reference',
        input  => 'AB&CDEFGHIJ',
        tmpl   => '[% text | truncate(5, "...") %]',
        # visual: A B & C D E F G H I J = 11 visual chars
        # truncate to 5 visual: 2 text + "..." = 5? No: 5 - 3 = 2 visual chars of text
        # visual chars: A, B → "AB..."
        expect => 'AB...',
    },
    {
        name   => 'entity in input text counted as 1 visual char',
        input  => 'A&B<C>DEFGHIJKLMNO',



( run in 1.255 second using v1.01-cache-2.11-cpan-71847e10f99 )