Skip to content

Commit

Permalink
impl Into String for Package
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszKielar committed Sep 7, 2020
1 parent 546889d commit 1ed3ec5
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ impl From<Metadata> for Package {
}
}

impl Into<String> for Package {
fn into(self) -> String {
match &self.installer {
Installer::Pip => return format!("{}=={}", self.name, self.version),
Installer::Conda => return format!("{}={}", self.name, self.version),
}
}
}

pub fn print_package(package: &Package) {
let tree = package_to_lines(package).join("\n");
println!("{}", tree)
Expand Down Expand Up @@ -149,4 +158,28 @@ mod tests {
};
assert_eq!(Package::from(metadata), expected_package)
}

#[test]
fn test_into_string_conda() {
let p: String = Package::new(
String::from("conda1"),
String::from("0.0.1"),
vec![],
Installer::Conda,
)
.into();
assert_eq!(p, String::from("conda1=0.0.1"))
}

#[test]
fn test_into_string_pip() {
let p: String = Package::new(
String::from("pip1"),
String::from("0.0.1"),
vec![],
Installer::Pip,
)
.into();
assert_eq!(p, String::from("pip1==0.0.1"))
}
}

0 comments on commit 1ed3ec5

Please sign in to comment.