~ubuntu-branches/ubuntu/jaunty/libdatetime-format-w3cdtf-perl/jaunty

« back to all changes in this revision

Viewing changes to t/01parse.t

  • Committer: Bazaar Package Importer
  • Author(s): Jaldhar H. Vyas
  • Date: 2006-01-18 22:49:29 UTC
  • Revision ID: james.westby@ubuntu.com-20060118224929-steoea8mgorewddu
Tags: upstream-0.04
ImportĀ upstreamĀ versionĀ 0.04

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -w
 
2
use Test::More tests => 17;
 
3
use strict;
 
4
use vars qw( $class );
 
5
 
 
6
BEGIN {
 
7
    $class = 'DateTime::Format::W3CDTF';
 
8
    use_ok $class;
 
9
}
 
10
 
 
11
my @tests = (
 
12
    '2003-02-10T15:23:45'       => '2003-02-10T15:23:45',
 
13
    '1997-04-11T09:34'          => '1997-04-11T09:34:00',
 
14
    '2002-05-12'                => '2002-05-12T00:00:00',
 
15
    '1985-06'                   => '1985-06-01T00:00:00',
 
16
    '1988'                      => '1988-01-01T00:00:00',
 
17
  #  '2001-02-30'               => '2001-03-02T00:00:00',
 
18
    '2005-03-10T20:14:34+09:30' => '2005-03-10T10:44:34',
 
19
    '2000-06-12T14:12:33Z'      => '2000-06-12T14:12:33',
 
20
    '1994-11-05T08:15:30-05:00' => '1994-11-05T13:15:30',
 
21
);
 
22
 
 
23
while (@tests)
 
24
{
 
25
    my ($given, $expected) = splice @tests, 0, 2;
 
26
    my $dt = $class->parse_datetime( $given )->set_time_zone( 'UTC' );
 
27
    my $form = $dt->iso8601;
 
28
    is( $form => $expected, "Parsing of $given => $expected." );
 
29
}
 
30
 
 
31
my @noparse = (
 
32
    'fnord',
 
33
    '2003.03.10',
 
34
    '2003-02-10X15:45:56',
 
35
    '2005-03-10T20:14:34+09',
 
36
    '2003-04-15T14',
 
37
    '2000-06-12T4:12:33Z',
 
38
    '15:45',
 
39
    '06:34:18',
 
40
);
 
41
 
 
42
for (@noparse)
 
43
{
 
44
    my $dt = eval { $class->parse_datetime( $_ ) };
 
45
    ok( $@ && !( defined $dt && $dt->isa('DateTime') ), "Correctly didn't parse '$_'" );
 
46
}