Compare commits

..

1 Commits

Author SHA1 Message Date
Davide Polonio 7c828a55db feat: improve formatting output
* duration is now in human readable format
* list of artists is now capped at 140 chars max
2021-11-13 17:27:28 +01:00
1 changed files with 15 additions and 0 deletions

View File

@ -2,6 +2,10 @@ use std::ops::Add;
use std::time::Duration; use std::time::Duration;
pub(crate) fn truncate_with_dots(to_truncate: String, new_size: usize) -> String { pub(crate) fn truncate_with_dots(to_truncate: String, new_size: usize) -> String {
if to_truncate.len() < new_size {
return to_truncate;
}
let mut new_string = to_truncate.clone(); let mut new_string = to_truncate.clone();
let dots = "..."; let dots = "...";
if new_size as isize - 3 > 0 { if new_size as isize - 3 > 0 {
@ -58,6 +62,17 @@ mod test {
) )
} }
#[test]
fn should_not_truncate_if_string_is_not_long_enough() {
let example_string = "short string";
let expected_string = "short string";
assert_eq!(
expected_string,
truncate_with_dots(example_string.to_string(), 1000)
);
}
#[test] #[test]
fn should_print_correct_duration_into_human_readable_format() { fn should_print_correct_duration_into_human_readable_format() {
let duration: Duration = Duration::new(124, 0); let duration: Duration = Duration::new(124, 0);