1use Test2::Tools::Tiny;
2use Term::Table::LineBreak;
3use strict;
4use warnings;
5use utf8;
6
7use Test2::API qw/test2_stack/;
8test2_stack->top->format->encoding('utf8');
9
10tests with_unicode_linebreak => sub {
11    my $one = Term::Table::LineBreak->new(string => 'aaaa婧bbbb');
12    $one->break(3);
13    is_deeply(
14        [ map { $one->next } 1 .. 5 ],
15        [
16            'aaa',
17            'a婧',
18            'bbb',
19            'b  ',
20            undef
21        ],
22        "Got all parts"
23    );
24
25    $one = Term::Table::LineBreak->new(string => 'a婧bb');
26    $one->break(2);
27    is_deeply(
28        [ map { $one->next } 1 .. 4 ],
29        [
30            'a ',
31            '婧',
32            'bb',
33            undef
34        ],
35        "Padded the problem"
36    );
37
38} if $INC{'Unicode/LineBreak.pm'};
39
40tests without_unicode_linebreak => sub {
41    my @parts;
42    {
43        local %INC = %INC;
44        delete $INC{'Unicode/GCString.pm'};
45        my $one = Term::Table::LineBreak->new(string => 'aaaa婧bbbb');
46        $one->break(3);
47        @parts = map { $one->next } 1 .. 5;
48    }
49
50    todo "Can't handle unicode properly without Unicode::GCString" => sub {
51        is_deeply(
52            \@parts,
53            [
54                'aaa',
55                'a婧',
56                'bbb',
57                'b  ',
58                undef
59            ],
60            "Got all parts"
61        );
62    };
63
64    my $one = Term::Table::LineBreak->new(string => 'aaabbbx');
65    $one->break(2);
66    is_deeply(
67        [ map { $one->next } 1 .. 5 ],
68        [
69            'aa',
70            'ab',
71            'bb',
72            'x ',
73            undef
74        ],
75        "Padded the problem"
76    );
77};
78
79done_testing;
80