What
get_percentage_width subtracts a 3-column padding from a u16 with plain -, so a table pane narrower than 3 columns panics in debug builds (attempt to subtract with overflow) and silently wraps in release builds. I hit it by opening a track table and pressing } until the sidebar fills the screen. I'd also like tests for this function and its neighbor truncate_text, which has none.
Where to look
get_percentage_width, truncate_text and the mod tests at the bottom of src/tui/ui/util.rs
Possible solution
- The fix is one call:
width.saturating_sub(padding).
- Write the failing test first:
get_percentage_width(2, 0.5) panics under cargo test today.
- Good cases: widths 0 to 3 give 0,
(103, 0.5) gives 50, and truncate_text("abcdef", 4) gives "abc…" (one … char, not three dots). For "héllo wörld" with max 5, check .chars().count(), not .len().
- Name tests as behavior sentences with no
test_ prefix or _test suffix (the two existing tests predate that rule).
- Each new
#[test] raises test_attribute_total in tools/gates.count by one. If the number is off, cargo test fails in src/gates.rs and prints the right one.
Done when
- New tests for both functions pass.
cargo fmt --all -- --check, cargo clippy --no-default-features --features telemetry,tui -- -D warnings and cargo test --no-default-features --features telemetry,tui pass.
What
get_percentage_widthsubtracts a 3-column padding from au16with plain-, so a table pane narrower than 3 columns panics in debug builds (attempt to subtract with overflow) and silently wraps in release builds. I hit it by opening a track table and pressing}until the sidebar fills the screen. I'd also like tests for this function and its neighbortruncate_text, which has none.Where to look
get_percentage_width,truncate_textand themod testsat the bottom ofsrc/tui/ui/util.rsPossible solution
width.saturating_sub(padding).get_percentage_width(2, 0.5)panics undercargo testtoday.(103, 0.5)gives 50, andtruncate_text("abcdef", 4)gives"abc…"(one…char, not three dots). For"héllo wörld"with max 5, check.chars().count(), not.len().test_prefix or_testsuffix (the two existing tests predate that rule).#[test]raisestest_attribute_totalintools/gates.countby one. If the number is off,cargo testfails insrc/gates.rsand prints the right one.Done when
cargo fmt --all -- --check,cargo clippy --no-default-features --features telemetry,tui -- -D warningsandcargo test --no-default-features --features telemetry,tuipass.