From 7abc1cfa1093cd8370fa911ec784b4106dbc1210 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Wed, 14 Oct 2026 02:14:23 +0700 Subject: [PATCH] Scatter overflow test: data that far off the plot is refused, not drawn (#1707) --- crates/engine/src/cmd/graph.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/engine/src/cmd/graph.rs b/crates/engine/src/cmd/graph.rs index 929504aa..94c95080 100644 --- a/crates/engine/src/cmd/graph.rs +++ b/crates/engine/src/cmd/graph.rs @@ -2048,15 +2048,17 @@ mod tests { fn a_scatter_x_axis_that_overflows_does_not_hang() { let mut s = Session::new(); s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap(); - // Finite x values whose rounded axis end is infinite: this used to add ticks forever. + // Finite x values whose rounded axis end is infinite: this used to add ticks forever. Now the + // command returns: points that far off the plot can't be drawn, which is an error. let csv = ",y1,x1\nP,1,1.7e308\nQ,2,1.5e308"; + let refused = |r: crate::Result| assert!(r.unwrap_err().to_string().contains("exceed the canvas")); + refused(s.execute("graph.create", &json!({"type": "scatter", "x": 100, "y": 100, "width": 300, "height": 200, "csv": csv}))); + // The same data through Graph Data, on an ordinary scatter graph: it stays as it was. let axes = |s: &Session, id: NodeId| group(s.doc().unwrap().doc.node(id).unwrap(), "Axes").children().unwrap().len(); - let id = make(&mut s, "scatter", csv); - assert!(axes(&s, id) < 100, "{}", axes(&s, id)); - // The same data through Graph Data, on an ordinary scatter graph. let id = make(&mut s, "scatter", ",y1,x1\nP,1,10\nQ,2,20"); - s.execute("graph.setData", &json!({"id": id.0, "csv": csv})).unwrap(); - assert!(axes(&s, id) < 100, "{}", axes(&s, id)); + let before = axes(&s, id); + refused(s.execute("graph.setData", &json!({"id": id.0, "csv": csv}))); + assert_eq!(axes(&s, id), before); } #[test]