changes from jrockway with some additional docs
[gitmo/MooseX-Types-Path-Class.git] / t / 01.basic.t
CommitLineData
fd56ddb6 1
2use warnings FATAL => 'all';
3use strict;
4
c96c867e 5{
6
7 package Foo;
8 use Moose;
9 use MooseX::Types::Path::Class;
10
11 has 'dir' => (
12 is => 'ro',
13 isa => 'Path::Class::Dir',
14 required => 1,
15 coerce => 1,
16 );
17
18 has 'file' => (
19 is => 'ro',
20 isa => 'Path::Class::File',
21 required => 1,
22 coerce => 1,
23 );
24}
25
26{
27
28 package Bar;
29 use Moose;
30 use MooseX::Types::Path::Class qw( Dir File );
31
32 has 'dir' => (
33 is => 'ro',
34 isa => Dir,
35 required => 1,
36 coerce => 1,
37 );
38
39 has 'file' => (
40 is => 'ro',
41 isa => File,
42 required => 1,
43 coerce => 1,
44 );
45}
fd56ddb6 46
47package main;
48
49use Test::More;
9194adce 50use Path::Class;
6d4d954d 51plan tests => 10;
fd56ddb6 52
9194adce 53my $dir = dir('', 'tmp');
54my $file = file('', 'tmp', 'foo');
55
fd56ddb6 56my $check = sub {
57 my $o = shift;
58 isa_ok( $o->dir, 'Path::Class::Dir' );
9194adce 59 cmp_ok( $o->dir, 'eq', "$dir", "dir is $dir" );
fd56ddb6 60 isa_ok( $o->file, 'Path::Class::File' );
9194adce 61 cmp_ok( $o->file, 'eq', "$file", "file is $file" );
fd56ddb6 62};
63
64for my $class (qw(Foo Bar)) {
6d4d954d 65 my $o = $class->new( dir => "$dir", file => [ '', 'tmp', 'foo' ] );
fd56ddb6 66 isa_ok( $o, $class );
67 $check->($o);
68}
69