File: 10-encode.t

package info (click to toggle)
liburi-packageurl-perl 2.22-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 276 kB
  • sloc: perl: 1,447; sh: 45; makefile: 2
file content (85 lines) | stat: -rw-r--r-- 2,790 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!perl -T

use strict;
use warnings;

use Test::More;

use URI::PackageURL qw(encode_purl);


my @TESTS = (
    {purl => 'pkg:cpan/Perl::Version@1.013', type => 'cpan', name => 'Perl::Version', version => '1.013'},
    {
        purl      => 'pkg:cpan/DROLSKY/DateTime@1.55',
        type      => 'cpan',
        namespace => 'DROLSKY',
        name      => 'DateTime',
        version   => '1.55'
    },
    {purl => 'pkg:cpan/DateTime@1.55',      type => 'cpan', name      => 'DateTime', version => '1.55'},
    {purl => 'pkg:cpan/GDT/URI-PackageURL', type => 'cpan', namespace => 'GDT',      name    => 'URI-PackageURL',},
    {purl => 'pkg:cpan/LWP::UserAgent',     type => 'cpan', name      => 'LWP::UserAgent'},
    {
        purl      => 'pkg:cpan/OALDERS/libwww-perl@6.76',
        type      => 'cpan',
        namespace => 'OALDERS',
        name      => 'libwww-perl',
        version   => '6.76'
    },
    {purl => 'pkg:cpan/URI', type => 'cpan', name => 'URI'},
    {
        purl       => 'pkg:generic/100%25/100%25@100%25?repository_url=https://example.com/100%2525/#100%25',
        type       => 'generic',
        namespace  => '100%',
        name       => '100%',
        version    => '100%',
        qualifiers => {'repository_url' => 'https://example.com/100%25/'},
        subpath    => '100%',
    },
    {purl => 'pkg:brew/openssl%401.1@1.1.1w', type => 'brew', name => 'openssl@1.1', version => '1.1.1w'},
    {purl => 'pkg:cpan/Storable@0.6%402',     type => 'cpan', name => 'Storable',    version => '0.6@2'},
    {
        purl    => 'pkg:cpan/Storable@0.5%403-bin-1-MacOS',
        type    => 'cpan',
        name    => 'Storable',
        version => '0.5@3-bin-1-MacOS'
    },
);


foreach my $test (@TESTS) {

    my $expected_purl = $test->{purl};

    subtest "$expected_purl" => sub {

        my $got_purl_1 = encode_purl(
            type       => $test->{type},
            namespace  => $test->{namespace},
            name       => $test->{name},
            version    => $test->{version},
            qualifiers => $test->{qualifiers},
            subpath    => $test->{subpath},
        );

        my $got_purl_2 = URI::PackageURL->new(
            type       => $test->{type},
            namespace  => $test->{namespace},
            name       => $test->{name},
            version    => $test->{version},
            qualifiers => $test->{qualifiers},
            subpath    => $test->{subpath},
        );

        my $got_purl_3 = URI::PackageURL->from_string($expected_purl)->to_string;

        is($got_purl_1, $expected_purl, "encode_purl --> $got_purl_1");
        is($got_purl_2, $expected_purl, "URI::PackageURL --> $got_purl_2");
        is($got_purl_3, $expected_purl, "decode+encode --> $got_purl_3");

    };

}

done_testing();