epic-s6ts
[kivitendo-erp.git] / t / common.t
1 use strict;
2
3 use Test::More;
4
5 use lib 't';
6 use Support::TestSetup;
7
8 Support::TestSetup::login();
9
10 use SL::Common;
11
12 sub test_truncate {
13   is(Common::truncate('nothing to do', at => -1),  '...',           'truncation length < 0: at least 3');
14   is(Common::truncate('nothing to do', at => 0),   '...',           'truncation length = 0: at least 3');
15   is(Common::truncate('nothing to do', at => 1),   '...',           'truncation length = 1: at least 3');
16   is(Common::truncate('nothing to do', at => 2),   '...',           'truncation length = 2: at least 3');
17   is(Common::truncate('nothing to do', at => 3),   '...',           'truncation length = 3: at least 3');
18   is(Common::truncate('nothing to do', at => 4),   'n...',          'truncation length = 4');
19   is(Common::truncate('nothing to do', at => 9),   'nothin...',     'text length equal to truncation + 4');
20   is(Common::truncate('nothing to do', at => 10),  'nothing...',    'text length equal to truncation + 3');
21   is(Common::truncate('nothing to do', at => 11),  'nothing ...',   'text length equal to truncation + 2');
22   is(Common::truncate('nothing to do', at => 12),  'nothing t...',  'text length equal to truncation + 1');
23   is(Common::truncate('nothing to do', at => 13),  'nothing to do', 'text length equal to truncation');
24   is(Common::truncate('nothing to do', at => 14),  'nothing to do', 'text length equal to truncation - 1');
25   is(Common::truncate('nothing to do', at => 15),  'nothing to do', 'text length equal to truncation - 2');
26   is(Common::truncate('nothing to do', at => 16),  'nothing to do', 'text length equal to truncation - 3');
27   is(Common::truncate('nothing to do', at => 200), 'nothing to do', 'text length smaller than truncation');
28
29   is(Common::truncate('012345678901234567890123456789012345678901234567890123456789'), '01234567890123456789012345678901234567890123456...', 'default truncation length of 50');
30
31   # Test stripping
32   is(Common::truncate("nothing\n\rat\rall\n\n", at => 50, strip => 1), "nothing\n\rat\rall", 'strip = 1, at = 50');
33   is(Common::truncate("nothing\n\rat\rall\n\n", at => 13, strip => 1), "nothing\n\ra...",    'strip = 1, at = 13');
34
35   is(Common::truncate("nothing\n\rat\rall\n\n", at => 50, strip => 'full'), "nothing at all", 'strip = full, at = 50');
36   is(Common::truncate("nothing\n\rat\rall\n\n", at => 13, strip => 'full'), "nothing at...",  'strip = full, at = 13');
37
38   is(Common::truncate("nothing\n\rat\rall\n\n", at => 50, strip => 'newlines'), "nothing at all", 'strip = newlines, at = 50');
39   is(Common::truncate("nothing\n\rat\rall\n\n", at => 13, strip => 'newlines'), "nothing at...",  'strip = newlines, at = 13');
40
41   is(Common::truncate("nothing\n\rat\rall\n\n", at => 50, strip => 'newline'), "nothing at all", 'strip = newline, at = 50');
42   is(Common::truncate("nothing\n\rat\rall\n\n", at => 13, strip => 'newline'), "nothing at...",  'strip = newline, at = 13');
43 }
44
45 test_truncate();
46
47 done_testing;
48
49 1;