Skip to content

Adding test coverage to src/info/info_field.rs #810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/info/info_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,40 @@ pub enum InfoType {
Size,
License,
}

#[cfg(test)]
mod test {
use super::*;

struct InfoFieldImpl(&'static str);

impl InfoField for InfoFieldImpl {
const TYPE: InfoType = InfoType::Project;

fn value(&self) -> String {
self.0.into()
}

fn title(&self) -> String {
String::from("title")
}
}

#[test]
fn test_info_field_get() {
let info = InfoFieldImpl("test");
assert_eq!(info.get(&[]), Some(String::from("test")));
}

#[test]
fn test_info_field_get_none_when_type_disabled() {
let info = InfoFieldImpl("test");
assert_eq!(info.get(&[InfoType::Project]), None);
}

#[test]
fn test_info_field_get_none_when_value_is_empty() {
let info = InfoFieldImpl("");
assert_eq!(info.get(&[]), None);
}
}