yet another symlink bug spotted by Henk P. Penning
[rersyncrecent.git] / t / 01-util.t
blob42b92a141080643babb0bc4c2e1cbefffa7d5e9b
1 use Test::More;
2 my $tests;
3 BEGIN { $tests = 0 }
4 use lib "lib";
5 use File::Rsync::Mirror::Recentfile;
6 use File::Rsync::Mirror::Recentfile::FakeBigFloat qw(_increase_a_bit _bigfloatlt);
9     BEGIN { $tests += 5 }
10     my $rf = File::Rsync::Mirror::Recentfile->new;
11     for my $x ([-12, undef],
12                [0, 0],
13                [undef, undef],
14                [(12)x2],
15                [(12000000000000)x2],
16               ) {
17         my $ret = eval { $rf->interval_secs(defined $x->[0] ? $x->[0] . "s" : ()); };
18         is $ret, $x->[1];
19     }
23     BEGIN { $tests += 5 }
24     my $rf = File::Rsync::Mirror::Recentfile->new;
25     for my $x (["12s" => 12],
26                ["12m" => 720],
27                ["2h"  => 7200],
28                ["1d"  => 86400],
29                ["4Q"  => 31104000],
30               ) {
31         my $ret = $rf->interval_secs ( $x->[0] );
32         is $ret, $x->[1];
33     }
37     my @x;
38     BEGIN {
39         @x = (
40               ["1" => "2"],
41               ["1" => undef],
42               ["0.99999999900000080543804870103485882282257080078125",
43                "0.9999999990000010274826536260661669075489044189453125"],
45 # the following is an interesting example because I saw this in the debugger:
46 #   DB<104> x "123456789123456789.2" <=> "123456789123456790"
47 # 0  1
49               ["123456789123456789","123456789123456790"],
50              );
51         for (@x) {
52             if (defined $_->[1]) {
53                 $tests += 2;
54             } else {
55                 $tests++;
56             }
57         }
58     }
59     for my $x (@x) {
60         my $ret = _increase_a_bit ( $x->[0], $x->[1] );
61         ok _bigfloatlt($x->[0], $ret), "L: $x->[0] < $ret";
62         if (defined $x->[1]) {
63             ok _bigfloatlt($ret, $x->[1]), "R: $ret < $x->[1]";
64         }
65     }
69     my @x;
70     BEGIN {
71         @x = split /\n/, <<EOT;
72 ge 1195248431   997872011
73 ge 1195248431.1 997872011
74 ge 1195248431   997872011.1
75 ge 1195248431.1 997872011.1
76 gt 1195248431   997872011
77 gt 1195248431.1 997872011
78 gt 1195248431   997872011.1
79 gt 1195248431.1 997872011.1
80 ge 1234567891195248431   123456789997872011
81 ge 1234567891195248431.1 123456789997872011
82 ge 1234567891195248431   123456789997872011.1
83 ge 1234567891195248431.1 123456789997872011.1
84 gt 1234567891195248431   123456789997872011
85 gt 1234567891195248431.1 123456789997872011
86 gt 1234567891195248431   123456789997872011.1
87 gt 1234567891195248431.1 123456789997872011.1
88 EOT
89         $tests += @x;
90     }
91     for my $line (@x) {
92         my($func,@arg) = split " ", $line;
93         $func = \&{"File::Rsync::Mirror::Recentfile::FakeBigFloat::_bigfloat$func"};
94         ok $func->(@arg), "$line";
95     }
98 BEGIN { plan tests => $tests }
100 # Local Variables:
101 # mode: cperl
102 # cperl-indent-level: 4
103 # End: