use super::*;
static TURN: Mutex<()> = Mutex::new(());
#[test]
fn the_longest_gap_of_a_step_is_kept() {
let _turn = TURN.lock().unwrap_or_else(std::sync::PoisonError::into_inner);
drain();
note("git add", Duration::from_millis(30), false);
note("git add", Duration::from_millis(90), false);
note("git add", Duration::from_millis(60), false);
assert_eq!(drain(), vec![(String::from("git add"), Duration::from_millis(90))]);
}
#[test]
fn an_ended_step_is_kept_apart_from_a_healthy_one() {
let _turn = TURN.lock().unwrap_or_else(std::sync::PoisonError::into_inner);
drain();
note("git add", Duration::from_millis(10), false);
note("git add", Duration::from_millis(500), true);
let figures = drain();
assert_eq!(figures.len(), 2, "{figures:?}");
assert_eq!(longest_healthy(figures.as_slice()), "10.000", "only the healthy step counts");
}
#[test]
fn draining_forgets() {
let _turn = TURN.lock().unwrap_or_else(std::sync::PoisonError::into_inner);
drain();
note("pnpm", Duration::from_millis(5), false);
assert_eq!(drain().len(), 1);
assert!(drain().is_empty());
}
#[test]
fn the_json_is_one_object() {
let figures = vec![(String::from("git \"x\""), Duration::from_micros(1500)), (String::from("pnpm"), Duration::from_millis(2))];
assert_eq!(object_json(figures.as_slice()), "{\"git \\\"x\\\"\":1.500,\"pnpm\":2.000}");
assert_eq!(object_json(&[]), "{}");
assert_eq!(longest_healthy(&[]), "0.000");
}