summaryrefslogtreecommitdiffstats
path: root/scripts/t/Dpkg_Source_Format.t
blob: 5a2785ea5d8544ccb7861c0602c2d3baaf2b5230 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/perl
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

use strict;
use warnings;

use Test::More tests => 14;

BEGIN {
    use_ok('Dpkg::Source::Format');
}

my $format = Dpkg::Source::Format->new();
my @format_parts;
my $format_string;

$format->set('4.3 (variant)');
@format_parts = $format->get();
is_deeply(\@format_parts, [ qw(4 3 variant) ], 'decomposition of format');
$format_string = $format->get();
ok($format_string eq '4.3 (variant)', 'function stringification of format');
$format_string = "$format";
ok($format_string eq '4.3 (variant)', 'operator stringification of format');

$format->set('5.5');
$format_string = $format->get();
ok($format_string eq '5.5', 'missing variant');

$format->set('6');
$format_string = $format->get();
ok($format_string eq '6.0', 'implied minor');

my %format_bogus = (
    'a' => 'require numerical major',
    '7.a'=> 'require numerical minor',
    '.5' => 'require non-empty major',
    '7.' => 'require non-empty minor',
    '7.0 ()' => 'require non-empty variant',
    '7.0 (  )' => 'require non-space variant',
    '7.0 (VARIANT)' => 'require lower-case variant',
    '7.6.5' => 'excess version part',
);

foreach my $format_bogus (sort keys %format_bogus) {
    eval {
        $format->set($format_bogus);
    };
    ok($@, $format_bogus{$format_bogus});
};

# TODO: Add actual test cases.

1;