~ubuntu-branches/ubuntu/utopic/libdatetime-format-mail-perl/utopic-proposed

« back to all changes in this revision

Viewing changes to t/fixyears.t

  • Committer: Bazaar Package Importer
  • Author(s): Jaldhar H. Vyas
  • Date: 2006-01-18 22:33:15 UTC
  • Revision ID: james.westby@ubuntu.com-20060118223315-cxvvqmhd8baiuwoo
Tags: upstream-0.2901
ImportĀ upstreamĀ versionĀ 0.2901

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
use strict;
 
2
use Test::More tests => 27;
 
3
use vars qw( $class );
 
4
BEGIN {
 
5
    $class = 'DateTime::Format::Mail';
 
6
    use_ok $class;
 
7
}
 
8
 
 
9
sub run_our_tests
 
10
{
 
11
    my ($fn, $testsuite) = @_;
 
12
    for my $label (sort keys %$testsuite)
 
13
    {
 
14
        my $tests = $testsuite->{$label};
 
15
        for my $input (sort keys %$tests)
 
16
        {
 
17
            my $expected = $tests->{$input};
 
18
            is $fn->( $input ) => $expected => "$label ($input)";
 
19
        }
 
20
    }
 
21
}
 
22
 
 
23
# Test defaults
 
24
 
 
25
{
 
26
    my $fn = sub {
 
27
        $class->fix_year( @_ );
 
28
    };
 
29
 
 
30
    my %testsuite = (
 
31
        'valid' => {
 
32
            '1900' => '1900',
 
33
            '2000' => '2000',
 
34
            '2900' => '2900',
 
35
        },
 
36
        'low' => {
 
37
            '10' => '2010',
 
38
            '40' => '2040',
 
39
        },
 
40
        'high' => {
 
41
            '70' => '1970',
 
42
            '90' => '1990',
 
43
        },
 
44
        default => {
 
45
            '49' => '2049',
 
46
            '50' => '1950',
 
47
        },
 
48
    );
 
49
    run_our_tests( $fn => \%testsuite );
 
50
}
 
51
 
 
52
# Test customs
 
53
 
 
54
{
 
55
    my $parser = $class->new();
 
56
    isa_ok( $parser => $class );
 
57
    is( $parser->year_cutoff => 49, "Default is default." );
 
58
    $parser->set_year_cutoff( 20 );
 
59
    is( $parser->year_cutoff => 20, "Default overriden." );
 
60
}
 
61
 
 
62
{
 
63
    my $parser = $class->new( year_cutoff => 20 );
 
64
    my $fn = sub {
 
65
        $parser->fix_year( @_ );
 
66
    };
 
67
 
 
68
    my %testsuite = (
 
69
        'valid' => {
 
70
            '1900' => '1900',
 
71
            '2000' => '2000',
 
72
            '2900' => '2900',
 
73
        },
 
74
        'low' => {
 
75
            '10' => '2010',
 
76
        },
 
77
        'high' => {
 
78
            '40' => '1940',
 
79
            '70' => '1970',
 
80
            '90' => '1990',
 
81
        },
 
82
    );
 
83
    run_our_tests( $fn => \%testsuite );
 
84
}
 
85
 
 
86
# Test bad arguments
 
87
{
 
88
    my $parser = $class->new();
 
89
    isa_ok( $parser => $class );
 
90
    is( $parser->year_cutoff => 49, "Default is default." );
 
91
    eval { $parser->set_year_cutoff( ) };
 
92
    ok( $@, "Error with no args" );
 
93
    eval { $parser->set_year_cutoff( 20, 40) };
 
94
    ok( $@, "Error with two args" );
 
95
    eval { $parser->set_year_cutoff( undef ) };
 
96
    ok( $@, "Error with undef arg" );
 
97
    eval { $parser->set_year_cutoff( 100 ) };
 
98
    ok( $@, "Error with arg too big" );
 
99
    eval { $parser->set_year_cutoff( -1 ) };
 
100
    ok( $@, "Error with arg negative" );
 
101
}