Data-Recursive-Encode
view release on metacpan or search on metacpan
t/02_more.t view on Meta::CPAN
use strict;
use warnings;
use Test::More;
use Data::Recursive::Encode;
use Encode;
# utility functions
sub U($) { decode_utf8($_[0]) }
sub u($) { encode_utf8($_[0]) }
sub E($) { decode('euc-jp', $_[0]) }
sub e($) { encode('euc-jp', $_[0]) }
sub eU($) { e(U($_[0])) }
# -------------------------------------------------------------------------
subtest "decode_utf8" => sub {
my $D = sub { Data::Recursive::Encode->decode_utf8(@_) };
is_deeply([$D->('ããã'), undef], [U('ããã'), undef], 'undef');
is_deeply([$D->('ããã'), \*ok ], [U('ããã'), \*ok], 'globref');
is_deeply([$D->('ããã'), \&ok ], [U('ããã'), \&ok], 'coderef');
is_deeply([\\$D->('ããã') ], [\\U('ããã')], 'ref to ref');
done_testing;
};
# -------------------------------------------------------------------------
subtest "encode_utf8" => sub {
my $E = sub { Data::Recursive::Encode->encode_utf8(@_) };
is_deeply([$E->(U 'ããã'), undef], [('ããã'), undef], 'undef');
is_deeply([$E->(U 'ããã'), \*ok ], [('ããã'), \*ok], 'globref');
is_deeply([$E->(U 'ããã'), \&ok ], [('ããã'), \&ok], 'coderef');
is_deeply([\\$E->(U 'ããã') ], [\\('ããã')], 'ref to ref');
done_testing;
};
# -------------------------------------------------------------------------
subtest "decode" => sub {
my $D = sub { Data::Recursive::Encode->decode('euc-jp', @_) };
is_deeply([$D->(eU('ããã')), undef], [U('ããã'), undef], 'undef');
is_deeply([$D->(eU('ããã')), \*ok ], [U('ããã'), \*ok], 'globref');
is_deeply([$D->(eU('ããã')), \&ok ], [U('ããã'), \&ok], 'coderef');
is_deeply([\\$D->(eU('ããã')) ], [\\U('ããã')], 'ref to ref');
done_testing;
};
# -------------------------------------------------------------------------
subtest "encode" => sub {
my $E = sub { Data::Recursive::Encode->encode('euc-jp', @_) };
is_deeply([$E->(U 'ããã'), undef], [eU('ããã'), undef], 'undef');
is_deeply([$E->(U 'ããã'), \*ok ], [eU('ããã'), \*ok], 'globref');
is_deeply([$E->(U 'ããã'), \&ok ], [eU('ããã'), \&ok], 'coderef');
is_deeply([\\$E->(U 'ããã') ], [\\eU('ããã')], 'ref to ref');
done_testing;
};
done_testing;
( run in 0.601 second using v1.01-cache-2.11-cpan-5b529ec07f3 )