The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
use strict;
use lib qw(lib ../lib);
use Template::Test;
use Template::Plugin::TruncateByWord;

test_expect(\*DATA);


__DATA__

-- test --
[% USE TruncateByWord 'big5' -%]
[% 'abcdefg' | truncate_by_word(4) %]
-- expect --
abcd

-- test --
[% USE TruncateByWord 'big5' -%]
[% '°ê»Ú½s½X½X' | truncate_by_word(3) %]
-- expect --
°ê»Ú½s

-- test --
[% USE TruncateByWord 'big5' -%]
[% '°ê»Úa½s½Xb½Xcdefg' | truncate_by_word(3) %]
-- expect --
°ê»Úa

-- test --
[% USE TruncateByWord 'big5' -%]
[% '°ê»Úa½s½Xb½Xcdefg' | truncate_by_word %]
-- expect --
°ê»Úa½s½Xb½Xcdefg

-- test --
[% USE TruncateByWord 'big5' -%]
[% '°ê»Úa½s½Xb½Xcdefg' | truncate_by_word(5,'...') %]
-- expect --
°ê»Úa½s½X...

-- test --
[% USE TruncateByWord 'big5' -%]
[% '°ê»Úa½s½Xb½Xcdefg' | truncate_by_word(36,'...') %]
-- expect --
°ê»Úa½s½Xb½Xcdefg

-- test --
[% USE TruncateByWord('big5', name='my_truncate') -%]
[% '°ê»Úa½s½Xb½Xcdefg' | my_truncate(3) %]
-- expect --
°ê»Úa

-- test --
[% USE TruncateByWord 'big5' name='my_truncate' -%]
[% FILTER my_truncate(5,'..') -%]
°ê»Úa½s½Xb½Xcdefg
[% END %]
-- expect --
°ê»Úa½s½X..

-- test --
[% USE TruncateByWord enc='big5' name='my_truncate' -%]
[% FILTER my_truncate(5,'..') -%]
°ê»Úa½s½Xb½Xcdefg
[% END %]
-- expect --
°ê»Úa½s½X..