From 4ca6f27114a5b2e1b51c6f74537cb347cfd86ec6 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 28 Nov 2026 08:21:06 +0100 Subject: [PATCH] Thing 2.0 cut 6b: tests for a zero-sided asset, alt without width, and a non-finite minimum --- crates/thing-core/tests/render.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/crates/thing-core/tests/render.rs b/crates/thing-core/tests/render.rs index b0cdcc8..f444931 100644 --- a/crates/thing-core/tests/render.rs +++ b/crates/thing-core/tests/render.rs @@ -834,9 +834,9 @@ fn a_missing_asset_is_one_placeholder_and_no_image_command() { let provider = ProviderId::new(PROVIDER); let mut state = MemState::new(); // No catalog (Absent), an entry the catalog lacks (Error), and a 0x0 entry. - state.put(&provider, &catalog(&[("empty", 0, 0)])); + state.put(&provider, &catalog(&[("empty", 0, 0), ("sliver", 0, 10)])); let mut root = vec![Node::Image(ImageNode { common: common("absent"), catalog: "nowhere".into(), asset: "x".into(), fit: ImageFit::Fill, alt: lit_text("alt") })]; - for (id, asset) in [("lacks", "nothing"), ("empty", "empty")] { + for (id, asset) in [("lacks", "nothing"), ("empty", "empty"), ("sliver", "sliver")] { root.push(image(id, asset, ImageFit::Contain)); } let out = with_state(&mut state, flat("root", plain(), root), &pixels(1.0)); @@ -847,8 +847,14 @@ fn a_missing_asset_is_one_placeholder_and_no_image_command() { RenderCommand::StrokeRect { rect: none, radius: 0.0, width: 1.0, color: color("thing.error") }, ] }; - let three: Vec<_> = (0..3).flat_map(|_| placeholder()).collect(); - assert_eq!(out.commands, three, "no catalog (Absent), a missing entry (Error) and a 0x0 entry"); + let four: Vec<_> = (0..4).flat_map(|_| placeholder()).collect(); + assert_eq!(out.commands, four, "no catalog (Absent), a missing entry (Error), a 0x0 entry and one with a zero side"); + // Where the placeholder has height but no width, the alt text has nowhere to go. + let mut state = MemState::new(); + state.put(&provider, &catalog(&[("empty", 0, 0)])); + let out = with_state(&mut state, flat("root", sized(100.0, 40.0), vec![image("pic", "empty", ImageFit::Contain)]), &pixels(1.0)); + assert_eq!(placed(&out, "pic").rect, rect(0.0, 0.0, 0.0, 40.0)); + assert!(!out.commands.iter().any(|c| matches!(c, RenderCommand::Text { .. })), "{:?}", out.commands); } #[test] @@ -878,6 +884,8 @@ fn explicit_bounds_clip_and_a_bad_bound_takes_the_data_and_is_named() { let nan = plotted(&[1.0, 3.0], PlotMark::Line, [None, None, None, Some(f64::NAN)]); assert_eq!(invalid(&nan), ["y_max"]); assert_eq!(polylines(&nan), [vec![(0.0, 150.0), (300.0, 0.0)]], "the data's own max"); + let nan_min = plotted(&[1.0, 3.0], PlotMark::Line, [Some(f64::NAN), None, Some(f64::NEG_INFINITY), None]); + assert_eq!(invalid(&nan_min), ["x_min", "y_min"]); let crossed = plotted(&[1.0, 3.0], PlotMark::Line, [None, None, Some(9.0), Some(2.0)]); assert_eq!(invalid(&crossed), ["y_min", "y_max"]); assert_eq!(polylines(&crossed), [vec![(0.0, 150.0), (300.0, 0.0)]]);