Files
gridcraft/crates/ui-egui/tests/it/nowrap_line_breaks.rs
T
aiongg a7608ada6d CI: one test binary per crate, nextest, line tables only (#2372)
* CI: dev builds keep line tables only

* CI: one integration-test binary per crate

* CI: xtask runs tests with nextest, doctests apart, --keep-going on clippy and wasm

cargo xtask test runs the workspace tests (--lib --bins --tests) with cargo-nextest when it is installed, else cargo test, then the doctests. cargo xtask ci uses the same two steps.

* CI: docs name cargo xtask test

* CI: agent guides name the moved fuzz test

* CI: tests added on main join their crate's test binary
2026-10-23 12:59:46 -04:00

41 lines
1.7 KiB
Rust

//! Line breaks with Wrap Text off (#1604): Excel ignores them and draws the whole string on one line.
use egui::Shape;
use gridcraft_engine::Session;
use serde_json::json;
type Harness = egui_kittest::Harness<'static, gridcraft_ui_egui::SheetApp>;
fn harness() -> Harness {
let mut s = Session::new();
s.new_workbook();
s.execute("cell.set", json!({"cell": "A1", "input": "Active\n\nUnits: LF 2x10\r\nBand: 60-20000 Hz"})).unwrap();
// Typing a break turns Wrap Text on; a file can still store the text with it off.
s.execute("home.formatCells", json!({"range": "A1", "style": {"align": {"wrap": false}}})).unwrap();
s.execute("cell.set", json!({"cell": "A3", "input": "Wrapped\nText"})).unwrap();
s.execute("home.formatCells", json!({"range": "A3", "style": {"align": {"wrap": true}}})).unwrap();
s.execute("selection.set", json!({"range": "H20"})).unwrap();
let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut gridcraft_ui_egui::SheetApp| {
app.logic(ui.ctx());
app.ui(ui);
},
gridcraft_ui_egui::SheetApp::new(s, Default::default()),
);
h.run_steps(4);
h
}
fn painted(h: &Harness, text: &str) -> bool {
h.output().shapes.iter().any(|s| matches!(&s.shape, Shape::Text(t) if t.galley.job.text == text))
}
#[test]
fn unwrapped_cell_draws_every_line_on_one_line() {
let h = harness();
assert!(painted(&h, "ActiveUnits: LF 2x10Band: 60-20000 Hz"), "A1 draws the whole string without its breaks");
assert!(!painted(&h, "Active"), "A1 is not cut at its first break");
// Wrap Text on keeps the breaks.
assert!(painted(&h, "Wrapped\nText"));
}