Skip to content

Commit

Permalink
Conversions for package & revision types
Browse files Browse the repository at this point in the history
  • Loading branch information
jssblck committed Oct 10, 2024
1 parent 31c4cfc commit 37caa06
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ impl From<&str> for Package {
}
}

impl From<&Package> for Package {
fn from(value: &Package) -> Self {
value.clone()
}
}

impl std::fmt::Display for Package {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
Expand Down Expand Up @@ -318,6 +324,12 @@ impl From<&str> for Revision {
}
}

impl From<&Revision> for Revision {
fn from(value: &Revision) -> Self {
value.clone()
}
}

impl std::fmt::Display for Revision {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Expand Down
12 changes: 12 additions & 0 deletions src/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,18 @@ mod tests {

use super::*;

#[test]
fn from_existing() {
let first = locator!(Git, "github.com/foo/bar");
let second = Locator::builder()
.fetcher(first.fetcher())
.maybe_org_id(first.org_id())
.package(first.package())
.maybe_revision(first.revision().as_ref())
.build();
assert_eq!(first, second);
}

#[test]
fn optional_fields() {
let with_options = Locator::builder()
Expand Down
11 changes: 11 additions & 0 deletions src/locator_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,17 @@ mod tests {

use super::*;

#[test]
fn from_existing() {
let first = package!(Git, "github.com/foo/bar");
let second = PackageLocator::builder()
.fetcher(first.fetcher())
.maybe_org_id(first.org_id())
.package(first.package())
.build();
assert_eq!(first, second);
}

#[test]
fn optional_fields() {
let with_options = PackageLocator::builder()
Expand Down
12 changes: 12 additions & 0 deletions src/locator_strict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,18 @@ mod tests {

use super::*;

#[test]
fn from_existing() {
let first = strict!(Git, "github.com/foo/bar", "abcd");
let second = StrictLocator::builder()
.fetcher(first.fetcher())
.maybe_org_id(first.org_id())
.package(first.package())
.revision(first.revision())
.build();
assert_eq!(first, second);
}

#[test]
fn optional_fields() {
let with_options = StrictLocator::builder()
Expand Down

0 comments on commit 37caa06

Please sign in to comment.