6 use Test::More tests => 26;
10 use_ok 'MooseX::Types::DateTimeX';
15 String Coercion; Check that we can properly coerce a string.
19 Make sure all the utility stuff works as expected
23 This module defines the following tests.
27 Create a L<Moose> class that is using the L<MooseX::Types::DateTimeX> types.
32 package MooseX::Types::DateTimeX::CoercionTest;
35 use MooseX::Types::DateTimeX qw(DateTime);
37 has 'date' => (is=>'rw', isa=>DateTime, coerce=>1);
40 ok my $class = MooseX::Types::DateTimeX::CoercionTest->new
41 => 'Created a good class';
44 =head2 ParseDateTime Capabilities
46 parse some dates and make sure the system can actually find something.
50 ok $class->date('2/13/1969 noon')
51 => "coerced a DateTime from '2/13/1969 noon'";
53 is $class->date, '1969-02-13T11:00:00'
54 => 'got correct date';
56 ok $class->date('2/13/1969')
57 => "coerced a DateTime from '2/13/1969'";
59 is $class->date, '1969-02-13T00:00:00'
60 => 'got correct date';
62 ok $class->date('2/13/1969 America/New_York')
63 => "coerced a DateTime from '2/13/1969 America/New_York'";
65 isa_ok $class->date->time_zone => 'DateTime::TimeZone::America::New_York'
66 => 'Got Correct America/New_York TimeZone';
68 is $class->date, '1969-02-13T00:00:00'
69 => 'got correct date';
71 ok $class->date('jan 1 2006')
72 =>"coerced a DateTime from 'jan 1 2006'";
74 is $class->date, '2006-01-01T00:00:00'
75 => 'got correct date';
80 Stuff like "yesterday". We can make sure they returned something but we have
81 no way to make sure the values are really correct. Manual testing suggests
82 they work well enough, given the inherent ambiguity we are dealing with.
86 ok $class->date('now')
87 => "coerced a DateTime from 'now'";
89 ok $class->date('yesterday')
90 => "coerced a DateTime from 'yesterday'";
93 ok $class->date('tomorrow')
94 => "coerced a DateTime from 'tomorrow'";
97 ok $class->date('last week')
98 => "coerced a DateTime from 'last week'";
101 =head2 check inherited constraints
103 Just a few tests to make sure the object, hash, etc coercions and type checks
108 ok my $datetime = DateTime->now()
109 => 'Create a datetime object for testing';
111 ok my $anyobject = bless({}, 'Bogus::Does::Not::Exist')
112 => 'Created a random object for proving the object constraint';
114 ok $class->date($datetime)
115 => 'Passed Object type constraint test.';
117 isa_ok $class->date => 'DateTime'
118 => 'Got a good DateTime Object';
120 dies_ok { $class->date($anyobject) } 'Does not allow the bad object';
122 ok $class->date(1000)
123 => 'Passed Num coercion test.';
125 isa_ok $class->date => 'DateTime'
126 => 'Got a good DateTime Object';
128 is $class->date => '1970-01-01T00:16:40'
129 => 'Got correct DateTime';
131 ok $class->date({year=>2000,month=>1,day=>10})
132 => 'Passed HashRef coercion test.';
134 isa_ok $class->date => 'DateTime'
135 => 'Got a good DateTime Object';
137 is $class->date => '2000-01-10T00:00:00'
138 => 'Got correct DateTime';
143 John Napiorkowski E<lt>jjn1056 at yahoo.comE<gt>
147 Copyright (c) 2008 John Napiorkowski. All rights reserved
148 This program is free software; you can redistribute
149 it and/or modify it under the same terms as Perl itself.