File: 02_code.t

package info (click to toggle)
libtext-csv-encoded-perl 0.25-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 288 kB
  • sloc: perl: 434; makefile: 2
file content (34 lines) | stat: -rw-r--r-- 1,477 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

use strict;
use utf8;


my $csv = Text::CSV::Encoded->new();

my @tests = ( #  encoding           CSV                         Perl Str    Re-CSV
    [ [ unicode => undef      ] => "ü",                         "ü",        "ü"                                 ],
    [ [ latin1  => undef      ] => "\xfc",                      "\xfc",     "\xfc"                              ],
    [ [ latin1  => 'latin1'   ] => "\xfc",                      "\xfc",     "\xfc"                              ],
    [ [ utf8    => undef      ] => "\xc3\xbc",                  "\xc3\xbc", qq|"\xc3\xbc"|                      ],
    [ [ unicode => 'utf8'     ] => "\xc3\xbc",                  "ü",        "\xc3\xbc"                          ],
    [ [ unicode => undef      ] => 'あ,い',                     'あ,い',    '"あ","い"'                         ],
    [ [ unicode => 'utf8'     ] => "\xE3\x81\x82,\xE3\x81\x84", 'あ,い',    qq|"\xE3\x81\x82","\xE3\x81\x84"|   ],
    [ [ unicode => 'shiftjis' ] => "\x82\xA0,\x82\xA2",         'あ,い',    qq|"\x82\xA0","\x82\xA2"|           ],
);


for my $t ( @tests ) {
    my ( $name, $code ) = @{ $t->[0] };

    $name .= " (<=$code)" if $code;

    my $columns = $code ? $csv->decode( $code, $t->[1] ) : $csv->decode( $t->[1] );

    is( join( ',', @$columns ),     $t->[2], $name . ' decode' );

    my $string = $code ? $csv->encode( $code, $columns ) : $csv->encode( $columns );

    is( $string, $t->[3], $name . ' encode' );
}

1;