]> git.donarmstrong.com Git - debbugs.git/blob - t/02_version_dpkg.t
change convert_to_utf8 to attempt to fix doubly encoded things
[debbugs.git] / t / 02_version_dpkg.t
1 # -*- mode: cperl;-*-
2
3 use Test::More;
4
5 use warnings;
6 use strict;
7
8 use utf8;
9 use Encode;
10
11 # Default cmp '>'
12 my @versions = ({a      => '1.0-1',
13                  b      => '2.0-2',
14                  result => -1,
15                  relation => 'lt',
16                 },
17                 {a      => '2.2~rc-4',
18                  b      => '2.2-1',
19                  result => -1,
20                  relation => 'lt',
21                 },
22                 {a      => '2.2-1',
23                  b      => '2.2~rc-4',
24                  result => 1,
25                  relation => 'gt',
26                 },
27                 {a      => '1.0000-1',
28                  b      => '1.0-1',
29                  result => 0,
30                  relation => 'eq',
31                 },
32                 # q(1.1-20080727-1),q(1.1-20080316-1)
33                 {a      => '1.1-20080727-1',
34                  b      => '1.1-20080316-1',
35                  result => 1,
36                  relation => 'gt',
37                 },
38                 {a      => '1.1-20080316-1',
39                  b      => '1.1-20080727-1',
40                  result => -1,
41                  relation => 'lt',
42                 },
43                 {a      => '1foo-',
44                  b      => '1foo',
45                  result => 0,
46                  relation => 'eq',
47                 },
48                 {a      => '1foo-',
49                  b      => '1foo+',
50                  result => -1,
51                  relation => 'lt',
52                 },
53                );
54
55 plan tests => @versions * 2 + 1;
56
57 sub dpkg_vercmp{
58      my ($a,$b,$cmp) = @_;
59      $cmp = 'gt' if not defined $cmp;
60      return system('dpkg','--compare-versions',$a,$cmp,$b) == 0;
61 }
62
63
64 use_ok('Debbugs::Versions::Dpkg');
65
66 for my $version_cmp (@versions) {
67      ok(Debbugs::Versions::Dpkg::vercmp($$version_cmp{a},$$version_cmp{b}) == $$version_cmp{result},
68         "Version $$version_cmp{a} $$version_cmp{relation} $$version_cmp{b} ok");
69      ok(dpkg_vercmp($$version_cmp{a},$$version_cmp{b},$$version_cmp{relation}),
70         "Dpkg concures: Version $$version_cmp{a} $$version_cmp{relation} $$version_cmp{b}");
71 }
72