Basic-Coercion-XS
view release on metacpan or search on metacpan
t/01-test.t view on Meta::CPAN
$type = StrToArray(by => ',');
$arrayref = $type->("a,b,c");
is_deeply($arrayref, [qw(a b c)], 'split by comma');
$type = StrToArray(by => '\\d+');
$arrayref = $type->("foo123bar456baz");
is_deeply($arrayref, [qw(foo bar baz)], 'split by digit sequence');
$type = StrToArray();
$arrayref = $type->("α β\tγ");
is_deeply($arrayref, [qw(α β γ)], 'split unicode by whitespace');
$type = StrToArray(by => qr/,/);
$arrayref = $type->("a,b,c");
is_deeply($arrayref, [qw(a b c)], 'split by comma - compiled');
ok(1);
done_testing();
t/03-StrToArray.t view on Meta::CPAN
$type = StrToHash(by => ':');
$hashref = $type->("a:1:b:2:c:3");
is_deeply($hashref, { a => 1, b => 2, c => 3 }, 'split by colon into hash');
$type = StrToHash();
$hashref = $type->("a 1 b 2 c 3");
ok(ref($hashref) eq 'HASH', 'returns a hashref even with odd elements');
$type = StrToHash();
$hashref = $type->("α β γ δ");
is_deeply($hashref, { "α" => "β", "γ" => "δ" }, 'unicode keys and values');
eval { $type->("a b c") };
like($@, qr/StrToHash requires an even number of elements in hash assignment/, 'undef input croaks');
done_testing;
( run in 0.579 second using v1.01-cache-2.11-cpan-88abd93f124 )