-
Notifications
You must be signed in to change notification settings - Fork 195
/
Copy pathutil.t
116 lines (96 loc) · 2.27 KB
/
util.t
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
use strict;
use warnings;
use lib 't/lib';
use CPAN::Meta ();
use MetaCPAN::Util qw(
extract_section
generate_sid
numify_version
strip_pod
);
use Test::Fatal qw( exception );
use Test::More;
ok( generate_sid(), 'generate_sid' );
{
my %versions = (
'010' => 10,
'0.20_8' => 0.208,
'0.208_8' => 0.2088,
'0.20_88' => 0.2088,
1 => 1,
LATEST => 0,
undef => 0,
'v0.9_9' => 0.099,
'v2.1.1' => 2.001001,
'v2.0.0' => 2.0,
);
foreach my $before ( sort keys %versions ) {
is( numify_version($before), $versions{$before},
"$before => $versions{$before}" );
}
}
{
my %versions = (
'2a' => 2,
'V0.01' => 'v0.01',
'0.99_1' => '0.99_1',
'0.99.01' => 'v0.99.01',
'v1.2' => 'v1.2',
);
foreach my $before ( sort keys %versions ) {
is exception {
is( version($before), $versions{$before},
"$before => $versions{$before}" )
}, undef, "$before => $versions{$before} does not die";
}
}
is(
strip_pod('hello L<link|http://www.google.com> foo'),
'hello link foo',
'strip_pod strips http links'
);
is(
strip_pod('hello L<Module/section> foo'),
'hello section in Module foo',
'strip_pod strips internal links'
);
is(
strip_pod('for L<Dist::Zilla>'),
'for Dist::Zilla',
'strip_pod strips module links'
);
is(
strip_pod('without a leading C<$>.'),
'without a leading $.',
'strip_pod strips C<>'
);
sub version {
CPAN::Meta->new( {
name => 'foo',
license => 'unknown',
version => MetaCPAN::Util::fix_version(shift)
} )->version;
}
# extract_section tests
{
my $content = <<EOF;
=head1 NAME
Some::Thing - Test
=head1 NAMED PIPE
Some data about a named pipe
EOF
my $section = extract_section( $content, 'NAME' );
is( $section, 'Some::Thing - Test',
'NAME matched correct head1 section' );
}
# https://github.com/metacpan/metacpan-api/issues/167
{
my $content = <<EOF;
=head1 NAMED PIPE
Some description
=cut
EOF
my $section = extract_section( $content, 'NAME' );
is( $section, undef, 'NAMED did not match requested section NAME' );
}
done_testing;