Skip to content

Commit

Permalink
add Version.parse() support
Browse files Browse the repository at this point in the history
  • Loading branch information
radhermit committed Dec 15, 2023
1 parent a31a929 commit 9a69be6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/Pkgcraft/Version.pm
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ package Pkgcraft::Version {
return;
}

sub parse {
my $str = shift // die "missing version string";
my $ptr = C::pkgcraft_version_parse($str);
return (defined $ptr)
}

sub revision {
my $self = shift;
my $ptr = C::pkgcraft_version_revision($self->{_ptr});
Expand Down
1 change: 1 addition & 0 deletions lib/_pkgcraft_c.pm
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ $ffi->attach('pkgcraft_version_intersects' => ['version_t', 'version_t'] => 'boo
$ffi->attach('pkgcraft_version_new' => ['string'] => 'version_t');
$ffi->attach('pkgcraft_version_revision' => ['version_t'] => 'revision_t');
$ffi->attach('pkgcraft_version_str' => ['version_t'] => 'c_str');
$ffi->attach('pkgcraft_version_parse' => ['string'] => 'opaque');

# revision support
$ffi->attach('pkgcraft_revision_cmp' => ['revision_t', 'revision_t'] => 'int');
Expand Down
6 changes: 6 additions & 0 deletions t/Pkgcraft/Version.t
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ ok(dies { Pkgcraft::Version->new("-2") });
ok(dies { $ver == "1-r2" });
ok(dies { Pkgcraft::Version->new(">1-r2") == ">1-r2" });

# valid
foreach my $str (@{$VERSION_DATA->{"valid"}}) {
ok(Pkgcraft::Version->new($str))
ok(Pkgcraft::Version->valid($str))
}

# version comparisons
foreach my $str (@{$VERSION_DATA->{"compares"}}) {
my ($s1, $op, $s2) = split ' ', $str;
Expand Down

0 comments on commit 9a69be6

Please sign in to comment.