forked from o2sh/onefetch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: gallottino <[email protected]> Co-authored-by: Oniryu95 <[email protected]>
- Loading branch information
1 parent
cc7a59c
commit c97f175
Showing
1 changed file
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)) | ||
} | ||
} |