Repository navigation
test(ui): every control can be reached, in a long language and a small window #3585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e45ee94
89bd806
3721218
fe62462
95c4229
651d5d4
d2854b3
191ec4f
6377581
feebd70
06a853b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -386,6 +386,10 @@ pub fn tr(lang: Lang, s: &str) -> &str { | |
| return t; | ||
| } | ||
| if lang == Lang::EN { | ||
| #[cfg(all(test, target_os = "linux"))] | ||
| if pseudo::on() { | ||
| return pseudo::pad(s); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Coverage gap, not a crash: the pseudo-English padding is applied only in Category: quality
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 95c4229: |
||
| } | ||
| return s; | ||
| } | ||
| plugin_tr(lang, s).unwrap_or(s) | ||
|
|
@@ -417,6 +421,10 @@ pub fn tr_raw(lang: Lang, s: &str) -> &str { | |
| return t; | ||
| } | ||
| if lang == Lang::EN { | ||
| #[cfg(all(test, target_os = "linux"))] | ||
| if pseudo::on() { | ||
| return pseudo::pad(s); | ||
| } | ||
| return s; | ||
| } | ||
| plugin_tr_raw(lang, s).unwrap_or(s) | ||
|
|
@@ -745,5 +753,16 @@ macro_rules! tl_raw { | |
|
|
||
| #[cfg(test)] | ||
| mod boundary_tests; | ||
| #[cfg(all(test, target_os = "linux"))] | ||
| pub(crate) mod pseudo; | ||
|
|
||
| /// Whether the layout tests' long English is on, on this thread; never outside them. | ||
| #[cfg(not(target_arch = "wasm32"))] | ||
| pub(crate) fn pseudo_on() -> bool { | ||
| #[cfg(all(test, target_os = "linux"))] | ||
| return pseudo::on(); | ||
| #[cfg(not(all(test, target_os = "linux")))] | ||
| false | ||
| } | ||
| #[cfg(test)] | ||
| mod tests; | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,88 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||
| //! A stand-in for a long language: English with each line about 40% longer. Layout tests draw the | ||||||||||||||||||||||||||||||||||||||||||||||||
| //! interface in it, so a label that only fits in English fails them without a translation or a | ||||||||||||||||||||||||||||||||||||||||||||||||
| //! font of its own. | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| use std::cell::{Cell, RefCell}; | ||||||||||||||||||||||||||||||||||||||||||||||||
| use std::collections::HashMap; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| thread_local! { | ||||||||||||||||||||||||||||||||||||||||||||||||
| static ON: Cell<bool> = const { Cell::new(false) }; | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// The padded text of each string drawn. Leaked, so a label can keep borrowing it. | ||||||||||||||||||||||||||||||||||||||||||||||||
| static PADDED: RefCell<HashMap<String, &'static str>> = RefCell::default(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /// Whether this thread draws English padded. | ||||||||||||||||||||||||||||||||||||||||||||||||
| pub(crate) fn on() -> bool { | ||||||||||||||||||||||||||||||||||||||||||||||||
| ON.get() | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /// Turns padding on or off for this thread. | ||||||||||||||||||||||||||||||||||||||||||||||||
| pub(crate) fn set(on: bool) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| ON.set(on); | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /// `s` padded: each line grows by 40% of its length. A line with a placeholder is left alone, | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// since what fills it isn't translated. | ||||||||||||||||||||||||||||||||||||||||||||||||
| pub(crate) fn pad(s: &str) -> &'static str { | ||||||||||||||||||||||||||||||||||||||||||||||||
| PADDED.with_borrow_mut(|seen| { | ||||||||||||||||||||||||||||||||||||||||||||||||
| if let Some(done) = seen.get(s) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| return *done; | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
| let line = |l: &str| match l.trim().is_empty() || l.contains('{') { | ||||||||||||||||||||||||||||||||||||||||||||||||
| true => l.to_string(), | ||||||||||||||||||||||||||||||||||||||||||||||||
| false => format!("{l}{}", "o".repeat((l.chars().count() * 2).div_ceil(5))), | ||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||
| let padded: &'static str = Box::leak(s.split('\n').map(line).collect::<Vec<_>>().join("\n").into_boxed_str()); | ||||||||||||||||||||||||||||||||||||||||||||||||
| seen.insert(s.to_string(), padded); | ||||||||||||||||||||||||||||||||||||||||||||||||
| padded | ||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /// `padded` with each padded string in it put back as it was: a whole label, or one built around | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// padded words, such as `▶ Run`. | ||||||||||||||||||||||||||||||||||||||||||||||||
| pub(crate) fn unpadded(padded: &str) -> String { | ||||||||||||||||||||||||||||||||||||||||||||||||
| // An accessible name joins a label's lines with a space. | ||||||||||||||||||||||||||||||||||||||||||||||||
| let mut text = padded.replace('\n', " "); | ||||||||||||||||||||||||||||||||||||||||||||||||
| PADDED.with_borrow(|seen| { | ||||||||||||||||||||||||||||||||||||||||||||||||
| let mut pairs: Vec<(String, String)> = | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Confidence: low; I didn't measure it. Category: performance
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Left for the release quality pass: it costs little at today's size. |
||||||||||||||||||||||||||||||||||||||||||||||||
| seen.iter().filter(|(s, p)| s.as_str() != **p).map(|(s, p)| (p.replace('\n', " "), s.replace('\n', " "))).collect(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| // The longest first, so a padded phrase isn't undone a word at a time. | ||||||||||||||||||||||||||||||||||||||||||||||||
| pairs.sort_by_key(|(p, _)| std::cmp::Reverse(p.len())); | ||||||||||||||||||||||||||||||||||||||||||||||||
| // A whole label first; else the padded words in it, where they aren't part of a longer word | ||||||||||||||||||||||||||||||||||||||||||||||||
| // (so `Goo` isn't undone inside `Goodbye`). | ||||||||||||||||||||||||||||||||||||||||||||||||
| if let Some((_, s)) = pairs.iter().find(|(p, _)| *p == text) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| text = s.clone(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
| for (p, s) in pairs { | ||||||||||||||||||||||||||||||||||||||||||||||||
| text = replace_words(&text, &p, &s); | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||
| text | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /// `text` with each `from` that isn't next to a letter or digit replaced by `to`. | ||||||||||||||||||||||||||||||||||||||||||||||||
| fn replace_words(text: &str, from: &str, to: &str) -> String { | ||||||||||||||||||||||||||||||||||||||||||||||||
| let word = |c: Option<char>| c.is_some_and(char::is_alphanumeric); | ||||||||||||||||||||||||||||||||||||||||||||||||
| let (mut out, mut last) = (String::new(), 0); | ||||||||||||||||||||||||||||||||||||||||||||||||
| // The letters either side come from the whole text, so a match beside a kept one still sees them. | ||||||||||||||||||||||||||||||||||||||||||||||||
| for (at, _) in text.match_indices(from) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| let (before, after) = (text[..at].chars().next_back(), text[at + from.len()..].chars().next()); | ||||||||||||||||||||||||||||||||||||||||||||||||
| out.push_str(&text[last..at]); | ||||||||||||||||||||||||||||||||||||||||||||||||
| out.push_str(if word(before) || word(after) { from } else { to }); | ||||||||||||||||||||||||||||||||||||||||||||||||
| last = at + from.len(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
| out + &text[last..] | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+65
to
+76
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Matching over the whole text keeps the context. Suggested replacement, plus a regression assert for
Suggested change
Category: bug
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 6377581, as suggested, with the |
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| #[cfg(test)] | ||||||||||||||||||||||||||||||||||||||||||||||||
| mod tests { | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// A padded word isn't undone inside a longer one. | ||||||||||||||||||||||||||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||||||||||||||||||||||||||
| fn unpadding_keeps_to_whole_words() { | ||||||||||||||||||||||||||||||||||||||||||||||||
| let (long, short) = (super::pad("Goodbye"), super::pad("Go")); | ||||||||||||||||||||||||||||||||||||||||||||||||
| assert_eq!(super::unpadded(long), "Goodbye"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| assert_eq!(super::unpadded(&format!("{short} {long}")), "Go Goodbye"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| assert_eq!(super::replace_words("GooGoo", "Goo", "Go"), "GooGoo"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sentence names only
tl!andtl_raw!as the padded routes, butt_raw,fmtandfmt_rawalso reachtr_raw, which pads since 95c4229 (t_rawcallstr_rawati18n/mod.rs:436-437). A contributor reading it would take at_raworfmtlabel as untested at 40% longer. Suggested wording for this line, which completes the sentence that starts on line 196:Category: quality
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left for the release quality pass.