Compare commits
1 Commits
84e5c0c341
...
7c828a55db
Author | SHA1 | Date |
---|---|---|
Davide Polonio | 7c828a55db |
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue