Skip to content

Commit

Permalink
Add tests for author.rs (o2sh#700)
Browse files Browse the repository at this point in the history
Signed-off-by: gallottino <[email protected]>
Co-authored-by: Oniryu95  <[email protected]>
  • Loading branch information
gallottino and Oniryu95 committed Oct 18, 2022
1 parent cc7a59c commit c97f175
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions src/info/repo/author.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,80 @@ mod test {

assert_eq!(author.to_string(), "75% John Doe 1500");
}

#[test]
fn test_author_info_title() {
let author = Author::new(
"John Doe".into(),
"[email protected]".into(),
1500,
2000,
true,
);

let author2 = Author::new(
"Roberto Berto".into(),
"[email protected]".into(),
240,
300,
false,
);

let authors_info = AuthorsInfo {
info_color: DynColors::Rgb(255, 0, 0),
authors: vec![author.clone()],
};

let authors_info_2 = AuthorsInfo {
info_color: DynColors::Rgb(255, 0, 0),
authors: vec![author2, author],
};

assert_eq!(authors_info.title(), "Author");
assert_eq!(authors_info_2.title(), "Authors");
}

#[test]
fn test_author_info_value() {
let author = Author::new(
"John Doe".into(),
"[email protected]".into(),
1500,
2000,
true,
);

let author2 = Author::new(
"Roberto Berto".into(),
"[email protected]".into(),
240,
300,
false,
);

let authors_info = AuthorsInfo {
info_color: DynColors::Rgb(255, 0, 0),
authors: vec![author.clone()],
};
let authors_info_2 = AuthorsInfo {
info_color: DynColors::Rgb(255, 0, 0),
authors: vec![author, author2],
};

println!("{}", authors_info);
println!("{}", authors_info_2);

assert_eq!(
authors_info.value(),
"\u{1b}[38;2;255;0;0m75% John Doe <[email protected]> 1500\u{1b}[39m"
);

let pad = authors_info_2.title().len() + 2;
let mut pad_str = String::from("");
let perc = (240 as f32 * 100. / 300 as f32).round() as usize;
for i in 0..pad {
pad_str.push_str(" ");
}
assert_eq!(authors_info_2.value(), format!("\u{1b}[38;2;255;0;0m75% John Doe <[email protected]> 1500\u{1b}[39m\n{}\u{1b}[38;2;255;0;0m{}% Roberto Berto 240\u{1b}[39m", pad_str, perc))
}
}

0 comments on commit c97f175

Please sign in to comment.