diff --git a/crates/ledger-gui/tests/assistants.rs b/crates/ledger-gui/tests/assistants.rs index 0e14ef99..72f2eb05 100644 --- a/crates/ledger-gui/tests/assistants.rs +++ b/crates/ledger-gui/tests/assistants.rs @@ -888,6 +888,34 @@ fn describe(shape: &egui::epaint::Shape) -> String { } } +/// `text` with every decimal number cut to two places: the last digits of +/// a `sin` or a `cos` differ between one platform's maths library and +/// another's, and a hundredth of a point is not a picture that changed. +fn rounded(text: &str) -> String { + let is_num = |c: char| c.is_ascii_digit() || matches!(c, '.' | '-' | 'e' | 'E' | '+'); + let (mut out, mut word) = (String::new(), String::new()); + let flush = |out: &mut String, word: &mut String| { + match word.parse::() { + Ok(v) if word.contains('.') => { + let r = format!("{v:.2}"); + out.push_str(if r == "-0.00" { "0.00" } else { &r }); + } + _ => out.push_str(word), + } + word.clear(); + }; + for c in text.chars() { + if is_num(c) { + word.push(c); + } else { + flush(&mut out, &mut word); + out.push(c); + } + } + flush(&mut out, &mut word); + out +} + /// A hash of every shape the window paints where it can be seen. fn shapes_of(h: &Harness<'_, App>) -> u64 { let screen = h.ctx.content_rect(); @@ -898,7 +926,7 @@ fn shapes_of(h: &Harness<'_, App>) -> u64 { .iter() .filter(|s| s.clip_rect.intersects(screen)) { - let line = format!("{:?} {}", s.clip_rect, describe(&s.shape)); + let line = rounded(&format!("{:?} {}", s.clip_rect, describe(&s.shape))); for b in line.bytes() { hash ^= b as u64; hash = hash.wrapping_mul(0x100_0000_01b3); @@ -953,16 +981,23 @@ fn three_states(dark: bool, front: usize, size: egui::Vec2) -> (World, Harness<' ]); let (root, fallback) = (w.root.clone(), w.source("alpha")); let for_app: Arc = owner.clone(); - let mut h = Harness::builder().with_size(size).build_eframe(move |cc| { - let mut app = App::start_with_owner( - &cc.egui_ctx, - &|k| kept.get(k).cloned(), - Start::Restore { root, fallback }, - Some(for_app), - ); - app.set_now(now()); - app - }); + // The clock stands still (a step takes no time): the turning arc, the + // spinners and every "a moment ago" are drawn from the frame time, and + // how many frames this window runs before a picture (`until` waits for + // threads, so it differs from machine to machine) must not move them. + let mut h = Harness::builder() + .with_size(size) + .with_step_dt(0.0) + .build_eframe(move |cc| { + let mut app = App::start_with_owner( + &cc.egui_ctx, + &|k| kept.get(k).cloned(), + Start::Restore { root, fallback }, + Some(for_app), + ); + app.set_now(now()); + app + }); let o: Arc = owner; for i in 0..3 { h.state_mut().view_mut(i).unwrap().set_owner(o.clone()); @@ -984,6 +1019,14 @@ fn the_state_marks_the_top_bar_and_the_pages_look_as_blessed() { // alpha in front: working; the tabs show all three marks. let (_w, mut h) = three_states(dark, 0, size); picture(&h, &format!("assist_working_{mode}")); + // The arc must not depend on when the picture is taken. + let before = shapes_of(&h); + h.run_steps(7); + assert_eq!( + shapes_of(&h), + before, + "the working picture moved with the frame count ({mode})" + ); h.state_mut().activate(1); h.run_steps(4); picture(&h, &format!("assist_none_{mode}")); diff --git a/crates/ledger-gui/tests/snapshots/assist_ask_dark.shapes b/crates/ledger-gui/tests/snapshots/assist_ask_dark.shapes index 26bbef66..1dc0b13e 100644 --- a/crates/ledger-gui/tests/snapshots/assist_ask_dark.shapes +++ b/crates/ledger-gui/tests/snapshots/assist_ask_dark.shapes @@ -1 +1 @@ -d4672239e98f338e +457ba24c523665a9 diff --git a/crates/ledger-gui/tests/snapshots/assist_ask_light.shapes b/crates/ledger-gui/tests/snapshots/assist_ask_light.shapes index 6b64c70b..b912b1ab 100644 --- a/crates/ledger-gui/tests/snapshots/assist_ask_light.shapes +++ b/crates/ledger-gui/tests/snapshots/assist_ask_light.shapes @@ -1 +1 @@ -47a1f842b40cdf15 +00576927816d03c7 diff --git a/crates/ledger-gui/tests/snapshots/assist_connect_page_dark.shapes b/crates/ledger-gui/tests/snapshots/assist_connect_page_dark.shapes index e58c6ce9..5f835848 100644 --- a/crates/ledger-gui/tests/snapshots/assist_connect_page_dark.shapes +++ b/crates/ledger-gui/tests/snapshots/assist_connect_page_dark.shapes @@ -1 +1 @@ -2abd53e6457106f8 +b2f05e2383abc93a diff --git a/crates/ledger-gui/tests/snapshots/assist_connect_page_light.shapes b/crates/ledger-gui/tests/snapshots/assist_connect_page_light.shapes index 26abeaee..41d591e8 100644 --- a/crates/ledger-gui/tests/snapshots/assist_connect_page_light.shapes +++ b/crates/ledger-gui/tests/snapshots/assist_connect_page_light.shapes @@ -1 +1 @@ -b990ac9586df492a +982cea77ed6d057f diff --git a/crates/ledger-gui/tests/snapshots/assist_connected_dark.shapes b/crates/ledger-gui/tests/snapshots/assist_connected_dark.shapes index 60526284..0c3c390a 100644 --- a/crates/ledger-gui/tests/snapshots/assist_connected_dark.shapes +++ b/crates/ledger-gui/tests/snapshots/assist_connected_dark.shapes @@ -1 +1 @@ -6642f21a3644e1f4 +a215dd5ae53fd265 diff --git a/crates/ledger-gui/tests/snapshots/assist_connected_light.shapes b/crates/ledger-gui/tests/snapshots/assist_connected_light.shapes index 11080e00..ab95e6cb 100644 --- a/crates/ledger-gui/tests/snapshots/assist_connected_light.shapes +++ b/crates/ledger-gui/tests/snapshots/assist_connected_light.shapes @@ -1 +1 @@ -e425621386ec002f +372299fa5492c223 diff --git a/crates/ledger-gui/tests/snapshots/assist_none_dark.shapes b/crates/ledger-gui/tests/snapshots/assist_none_dark.shapes index aead0299..fc9d6fea 100644 --- a/crates/ledger-gui/tests/snapshots/assist_none_dark.shapes +++ b/crates/ledger-gui/tests/snapshots/assist_none_dark.shapes @@ -1 +1 @@ -79ee857f24de8131 +7360c06435be4c53 diff --git a/crates/ledger-gui/tests/snapshots/assist_none_light.shapes b/crates/ledger-gui/tests/snapshots/assist_none_light.shapes index 235d24dd..d024e902 100644 --- a/crates/ledger-gui/tests/snapshots/assist_none_light.shapes +++ b/crates/ledger-gui/tests/snapshots/assist_none_light.shapes @@ -1 +1 @@ -d236cd60218a8061 +44d1be4a12ea3910 diff --git a/crates/ledger-gui/tests/snapshots/assist_working_dark.shapes b/crates/ledger-gui/tests/snapshots/assist_working_dark.shapes index 9f937324..4b02e58f 100644 --- a/crates/ledger-gui/tests/snapshots/assist_working_dark.shapes +++ b/crates/ledger-gui/tests/snapshots/assist_working_dark.shapes @@ -1 +1 @@ -8d565039aff8c64c +7f408ec78501d5ee diff --git a/crates/ledger-gui/tests/snapshots/assist_working_light.shapes b/crates/ledger-gui/tests/snapshots/assist_working_light.shapes index 35adc9df..3e346abd 100644 --- a/crates/ledger-gui/tests/snapshots/assist_working_light.shapes +++ b/crates/ledger-gui/tests/snapshots/assist_working_light.shapes @@ -1 +1 @@ -7014f0d713dbc1d8 +ca114f7e49a3e40d