test: Move test_data_file() to test.h
[dpkg.git] / scripts / t / Dpkg_Source_Format.t
blob68aa04e210c4d0a84ebbcf9e2dd3b6a25420fec5
1 #!/usr/bin/perl
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 use strict;
17 use warnings;
19 use Test::More tests => 14;
21 BEGIN {
22 use_ok('Dpkg::Source::Format');
25 my $format = Dpkg::Source::Format->new();
26 my @format_parts;
27 my $format_string;
29 $format->set('4.3 (variant)');
30 @format_parts = $format->get();
31 is_deeply(\@format_parts, [ qw(4 3 variant) ], 'decomposition of format');
32 $format_string = $format->get();
33 ok($format_string eq '4.3 (variant)', 'function stringification of format');
34 $format_string = "$format";
35 ok($format_string eq '4.3 (variant)', 'operator stringification of format');
37 $format->set('5.5');
38 $format_string = $format->get();
39 ok($format_string eq '5.5', 'missing variant');
41 $format->set('6');
42 $format_string = $format->get();
43 ok($format_string eq '6.0', 'implied minor');
45 my %format_bogus = (
46 'a' => 'require numerical major',
47 '7.a' => 'require numerical minor',
48 '.5' => 'require non-empty major',
49 '7.' => 'require non-empty minor',
50 '7.0 ()' => 'require non-empty variant',
51 '7.0 ( )' => 'require non-space variant',
52 '7.0 (VARIANT)' => 'require lower-case variant',
53 '7.6.5' => 'excess version part',
56 foreach my $format_bogus (sort keys %format_bogus) {
57 eval {
58 $format->set($format_bogus);
60 ok($@, $format_bogus{$format_bogus});
63 # TODO: Add actual test cases.