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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
use strict;
use warnings;
use Test::More 0.96;
use File::Temp 0.18;
use File::pushd qw/tempd/;
use Path::Tiny;
use Types::Path::Tiny -types;
my $tf = File::Temp->new;
my $td = File::Temp->newdir;
my @cases = (
# Path
{
label => "coerce string to Path",
type => Path,
input => "./foo",
},
{
label => "coerce object to Path",
type => Path,
input => $tf,
},
{
label => "coerce array ref to Path",
type => Path,
input => [qw/foo bar/],
},
# AbsPath
{
label => "coerce string to AbsPath",
type => AbsPath,
input => "./foo",
},
{
label => "coerce Path to AbsPath",
type => AbsPath,
input => path($tf),
},
{
label => "coerce object to AbsPath",
type => AbsPath,
input => $tf,
},
{
label => "coerce array ref to AbsPath",
type => AbsPath,
input => [qw/foo bar/],
},
# File
{
label => "coerce string to File",
type => File,
input => "$tf",
},
{
label => "coerce object to File",
type => File,
input => $tf,
},
{
label => "coerce array ref to File",
type => File,
input => [$tf],
},
# Dir
{
label => "coerce string to Dir",
type => Dir,
input => "$td",
},
{
label => "coerce object to Dir",
type => Dir,
input => $td,
},
{
label => "coerce array ref to Dir",
type => Dir,
input => [$td],
},
# AbsFile
{
label => "coerce string to AbsFile",
type => AbsFile,
input => "$tf",
},
{
label => "coerce object to AbsFile",
type => AbsFile,
input => $tf,
},
{
label => "coerce array ref to AbsFile",
type => AbsFile,
input => [$tf],
},
# AbsDir
{
label => "coerce string to AbsDir",
type => AbsDir,
input => "$td",
},
{
label => "coerce object to AbsDir",
type => AbsDir,
input => $td,
},
{
label => "coerce array ref to AbsDir",
type => AbsDir,
input => [$td],
},
);
for my $c (@cases) {
subtest $c->{label} => sub {
my $wd = tempd;
my $type = $c->{type};
my $input = $c->{input};
my $expected = path( ref $input eq 'ARRAY' ? @$input : $input );
$expected = $expected->absolute if $type =~ /^Abs/;
my $output = eval { $type->assert_coerce( $input ); };
is( $@, '', "object created without exception" );
isa_ok( $output, "Path::Tiny", '$output' );
is( $output, $expected, '$output is as expected' );
};
}
done_testing;
#
# This file is part of Types-Path-Tiny
#
# This software is Copyright (c) 2013 by David Golden.
#
# This is free software, licensed under:
#
# The Apache License, Version 2.0, January 2004
#
|