Skip to content
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

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

Merged
merged 2 commits into from
Oct 7, 2022
Merged
Changes from 1 commit
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
47 changes: 47 additions & 0 deletions src/info/info_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,50 @@ pub enum InfoType {
Size,
License,
}

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

struct InfoFieldImpl {
pub val: String,
}
alessandroasm marked this conversation as resolved.
Show resolved Hide resolved
impl InfoField for InfoFieldImpl {
const TYPE: InfoType = InfoType::Project;

fn value(&self) -> String {
self.val.clone()
}
alessandroasm marked this conversation as resolved.
Show resolved Hide resolved

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

#[test]
fn test_info_field_get() {
let info = InfoFieldImpl {
val: String::from("test"),
};
alessandroasm marked this conversation as resolved.
Show resolved Hide resolved

assert_eq!(info.get(&[]), Some(String::from("test")));
}

#[test]
fn test_info_field_get_none_when_type_disabled() {
let info = InfoFieldImpl {
val: String::from("test"),
};
alessandroasm marked this conversation as resolved.
Show resolved Hide resolved

assert_eq!(info.get(&[InfoType::Project]), None);
}

#[test]
fn test_info_field_get_none_when_value_is_empty() {
let info = InfoFieldImpl {
val: String::from(""),
};
alessandroasm marked this conversation as resolved.
Show resolved Hide resolved

assert_eq!(info.get(&[]), None);
}
}