From f2601137ab0d98f76a18808cb1fee7db82d419c4 Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Sun, 18 Oct 2026 14:09:37 +0200 Subject: [PATCH] Resolve the "ft" unit suffix to Feet in Unit::named Found while testing crates/doc/src/lib.rs:274 (Unit::named) Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 --- crates/doc/src/lib.rs | 7 ++++++- crates/doc/src/tests_units.rs | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/doc/src/lib.rs b/crates/doc/src/lib.rs index 3eeb13f7a..1e50fabe7 100644 --- a/crates/doc/src/lib.rs +++ b/crates/doc/src/lib.rs @@ -274,7 +274,12 @@ impl Unit { pub fn named(name: &str) -> Option { let letters = |s: &'static str| s.chars().filter(char::is_ascii_alphanumeric).map(|c| c.to_ascii_lowercase()); let given = || name.chars().filter(char::is_ascii_alphanumeric).map(|c| c.to_ascii_lowercase()); - Unit::ALL.into_iter().find(|u| letters(u.label()).eq(given()) || u.suffix().chars().eq(given())) + // Feet and Feet & Inches share the suffix `ft`: it names the plain unit, so Feet & Inches + // is left to its label and key. + Unit::ALL + .into_iter() + .find(|u| letters(u.label()).eq(given())) + .or_else(|| Unit::ALL.into_iter().filter(|u| *u != Unit::FeetInches).find(|u| u.suffix().chars().eq(given()))) } /// A point value as the canvas measurement labels show it: two decimals and the suffix /// (`12.50 mm`). diff --git a/crates/doc/src/tests_units.rs b/crates/doc/src/tests_units.rs index b09ed5a50..a5dbe9fb3 100644 --- a/crates/doc/src/tests_units.rs +++ b/crates/doc/src/tests_units.rs @@ -98,6 +98,13 @@ fn units_are_named_by_label_key_or_suffix() { assert_eq!(Unit::named(""), None); } +#[test] +fn a_shared_suffix_names_the_plain_unit() { + assert_eq!(Unit::named(Unit::Feet.suffix()), Some(Unit::Feet)); + assert_eq!(Unit::named("FT"), Some(Unit::Feet)); + assert_eq!(Unit::named(Unit::FeetInches.label()), Some(Unit::FeetInches)); +} + #[test] fn readouts_show_two_decimals() { assert_eq!(Unit::Points.readout(15.0), "15.00 pt");