File: most-recent-email.t

package info (click to toggle)
libconfig-model-dpkg-perl 3.014
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,200 kB
  • sloc: perl: 8,255; python: 242; makefile: 77; javascript: 16; sh: 1
file content (42 lines) | stat: -rw-r--r-- 1,365 bytes parent folder | download
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
use 5.20.0;
use strict;
use warnings;
use utf8;
use open ':std', ':encoding(utf8)';

use Test::More;
use Test::Differences;
use Test::Synopsis::Expectation;
use Software::Copyright::Statement;
use Path::Tiny;

use feature qw/postderef signatures/;
no warnings qw/experimental::postderef experimental::signatures/;

require_ok('Dpkg::Copyright::Grant::ByFile::MostRecentEmail');

sub check ($inv, $input, $year = 0, $email = '') {
    $inv->update_email_if_more_recent(new_st($input));
    is($inv->email, $email, "check email $email");
    is($inv->year, $year, "check year $year");
}

sub new_st($str) {
    return Software::Copyright::Statement->new($str);
}

subtest "add email" => sub {
    my $inv = Dpkg::Copyright::Grant::ByFile::MostRecentEmail->new();

    check($inv, '2013 Marcel');
    check($inv, 'Marcel <bogus@e.com>', 0 => 'bogus@e.com');
    check($inv, '2013 Marcel <marcel@example.com>', 2013 => 'marcel@example.com'  );
    check($inv, '2012 Marcel <oldmarcel@example.com>', 2013 => 'marcel@example.com'  );
    check($inv, '2010-2014 Marcel <newmarcel@example.com>', 2014 => 'newmarcel@example.com'  );

    # this is the corner case that may cause trouble: same year, 2 email addreses
    # we arbitrarily don't update in this case.
    check($inv, '2014 Marcel <new2marcel@example.com>', 2014 => 'newmarcel@example.com'  );
};

done_testing;