From be52680c9c4f7777ccb119d4b3014edc05fcb458 Mon Sep 17 00:00:00 2001 From: Martin Ball Date: Mon, 2 Nov 2026 00:27:37 +0000 Subject: [PATCH] =?UTF-8?q?CP6.13:=20craft-libs#495=20review=20=E2=80=94?= =?UTF-8?q?=20an=20oversized=20pack=20licence=20is=20skipped=20alone;=20a?= =?UTF-8?q?=20score=20(3=20:=201)=20keeps=20its=20spaces=20in=20hr,=20it,?= =?UTF-8?q?=20pl,=20pt=20and=20ru;=20'=20,,'=20(a=20typed=20quote)=20is=20?= =?UTF-8?q?left=20to=20the=20quote=20rule=20in=20pl=20and=20ru;=20pt=20nar?= =?UTF-8?q?ration=20after=20a=20dialogue=20dash=20is=20no=20new=20sentence?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01FypgCX8LsYYE8fsj4byBm2 --- crates/proof/src/hr/grammar.rs | 2 +- crates/proof/src/it/grammar.rs | 2 +- crates/proof/src/lib.rs | 46 ++++++++++++++++++++++++++++++++++ crates/proof/src/packs.rs | 4 +-- crates/proof/src/pl/grammar.rs | 7 ++++-- crates/proof/src/pt/grammar.rs | 9 +++++-- crates/proof/src/ru/grammar.rs | 7 ++++-- 7 files changed, 67 insertions(+), 10 deletions(-) diff --git a/crates/proof/src/hr/grammar.rs b/crates/proof/src/hr/grammar.rs index 517c56235..2605ae88d 100644 --- a/crates/proof/src/hr/grammar.rs +++ b/crates/proof/src/hr/grammar.rs @@ -98,7 +98,7 @@ fn spaces(text: &str, v: &mut Vec) { // ` ...` is an ellipsis, ` .5` a number. '.' => !matches!(after, Some('.')) && !after.is_some_and(|a| a.is_ascii_digit()), // ` :)`, ` :-)`, ` :D` and similar are emoticons; ` ?!` is still a stray space. - ':' | '!' | '?' => after.is_none_or(|a| a.is_whitespace() || matches!(a, '"' | '”' | '’' | '!' | '?')), + ':' | '!' | '?' => !crate::score_colon(text, i) && after.is_none_or(|a| a.is_whitespace() || matches!(a, '"' | '”' | '’' | '!' | '?')), _ => false, }; if flag { diff --git a/crates/proof/src/it/grammar.rs b/crates/proof/src/it/grammar.rs index a6ed02f35..57c62e287 100644 --- a/crates/proof/src/it/grammar.rs +++ b/crates/proof/src/it/grammar.rs @@ -196,7 +196,7 @@ fn spaces(text: &str, v: &mut Vec) { // ` ...` is an ellipsis, ` .5` a number. '.' => !matches!(after, Some('.')) && !after.is_some_and(|a| a.is_ascii_digit()), // ` :)`, ` :-)`, ` :D` and similar are emoticons; ` ?!` is still a stray space. - ':' | '!' | '?' => after.is_none_or(|a| a.is_whitespace() || matches!(a, '"' | '”' | '’' | '!' | '?')), + ':' | '!' | '?' => !crate::score_colon(text, i) && after.is_none_or(|a| a.is_whitespace() || matches!(a, '"' | '”' | '’' | '!' | '?')), _ => false, }; if flag { diff --git a/crates/proof/src/lib.rs b/crates/proof/src/lib.rs index 21229a478..5b58768cc 100644 --- a/crates/proof/src/lib.rs +++ b/crates/proof/src/lib.rs @@ -675,6 +675,13 @@ pub(crate) fn accepted_by_options(word: &str, opts: &Options) -> bool { || in_user_dictionary(&w.to_lowercase()) } +/// Is the space at byte `space` of `text` the first of a score or ratio's `3 : 1`, which keeps +/// its spaces (the grammar rules' space-before-punctuation check)? +pub(crate) fn score_colon(text: &str, space: usize) -> bool { + text.get(..space).and_then(|t| t.chars().next_back()).is_some_and(|c| c.is_ascii_digit()) + && text.get(space..).is_some_and(|t| t.starts_with(" : ") && t.get(3..).and_then(|r| r.chars().next()).is_some_and(|c| c.is_ascii_digit())) +} + /// [`is_correct`] with the File › Options › Proofing choices: English with no dialect, so a word /// any English spells so is right (`color` and `colour`; American English's dictionary when it /// isn't SCOWL: [`english_source`]), without the dialect policy. @@ -1930,6 +1937,45 @@ mod tests { let _ = std::fs::remove_dir_all(&root); } + /// craft-libs#485 review: a licence file that is too big is skipped alone; the pack's other + /// licences and the next pack's are still shown. + #[test] + fn an_oversized_licence_skips_only_itself() { + crate::hold_dictionary_tests(); + set_dictionaries_folder(Some(shared_test_folder())); + let root = std::env::temp_dir().join(format!("wc-proof-licence-skip-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&root); + for l in ["qa", "qb"] { + let dir = write_pack(&root, l, &[]); + std::fs::write(dir.join("LICENCES").join("A-HUGE"), vec![b'x'; (4 << 20) + 1]).unwrap(); + std::fs::write(dir.join("LICENCES").join("COPYING"), format!("licence {l}")).unwrap(); + } + packs::set_packs_dir(Some(root.clone())); + let texts = packs::licence_texts(); + let shown: Vec<&str> = texts.iter().filter(|(t, _)| t.contains("(q")).map(|(_, x)| x.as_str()).collect(); + assert_eq!(shown, ["licence qa", "licence qb"]); + packs::set_packs_dir(None); + set_dictionaries_folder(Some(shared_test_folder())); + let _ = std::fs::remove_dir_all(&root); + } + + /// craft-libs#483 and #488 reviews: a score keeps its spaces (`3 : 1`) in every language's + /// space-before-punctuation rule, and in Polish and Russian ` ,,` (a typed opening quote) is + /// left to the doubled-punctuation rule alone. + #[test] + fn scores_and_typed_quotes_keep_their_spaces() { + let space_marks = |text: &str, lang| check_grammar_in(text, lang).into_iter().filter(|i| text.get(i.start..i.start + 1) == Some(" ")).count(); + for lang in [ProofLang::Ru, ProofLang::Pl, ProofLang::Hr, ProofLang::It, ProofLang::Pt] { + assert_eq!(space_marks("Wynik 3 : 1 dzisiaj.", lang), 0, "{lang:?}"); + assert_eq!(space_marks("Wynik 3 : dzisiaj.", lang), 1, "{lang:?}: not a score"); + } + for (text, lang) in [("Powiedział ,,tak” wczoraj.", ProofLang::Pl), ("Он сказал ,,да” вчера.", ProofLang::Ru)] { + let issues = check_grammar_in(text, lang); + assert_eq!(space_marks(text, lang), 0, "{issues:?}"); + assert!(issues.iter().any(|i| text.get(i.start..i.end) == Some(",,")), "the quote rule still marks it: {issues:?}"); + } + } + /// Pack languages for the cache tests: `qa`, `qb`… each knowing `word`. fn many_packs(root: &std::path::Path, n: usize) -> Vec { (0..n) diff --git a/crates/proof/src/packs.rs b/crates/proof/src/packs.rs index c4cee539a..2fb291e9b 100644 --- a/crates/proof/src/packs.rs +++ b/crates/proof/src/packs.rs @@ -389,8 +389,8 @@ fn licence_files(pack: &Path, left: &mut u64) -> Vec<(String, String)> { let path = dir.join(&n); let size = std::fs::symlink_metadata(&path).ok().filter(std::fs::Metadata::is_file)?.len(); if size > (*left).min(MAX_LICENCE) { - // Over what is left: none of the rest is read either. - *left = 0; + // Too big, or over what is left: this file is skipped, smaller ones still fit. + log::warn!("Language pack licence {} is {size} bytes; not shown", path.display()); return None; } let bytes = read_capped(&path, size.min(MAX_LICENCE)).ok()?; diff --git a/crates/proof/src/pl/grammar.rs b/crates/proof/src/pl/grammar.rs index 4289f0c7b..d514429e0 100644 --- a/crates/proof/src/pl/grammar.rs +++ b/crates/proof/src/pl/grammar.rs @@ -288,13 +288,16 @@ fn spaces(text: &str, v: &mut Vec) { let Some(p) = it.next() else { continue }; let after = it.next(); let flag = match p { - ',' => true, + // ` ,,` opens a typed quote (the doubled-punctuation rule suggests `„`). + ',' => after != Some(','), // `;)` and `;-)` are emoticons. ';' => !matches!(after, Some(')' | '(' | '-' | 'P' | 'D')), // ` ...` is an ellipsis, ` .5` a number. '.' => !matches!(after, Some('.')) && !after.is_some_and(|a| a.is_ascii_digit()), // ` :)`, ` :-)`, ` :D` and similar are emoticons; ` ?!` is still a stray space. - ':' | '!' | '?' => after.is_none_or(|a| a.is_whitespace() || matches!(a, '"' | '”' | '»' | '’' | '!' | '?')), + ':' | '!' | '?' => { + !crate::score_colon(text, i) && after.is_none_or(|a| a.is_whitespace() || matches!(a, '"' | '”' | '»' | '’' | '!' | '?')) + } _ => false, }; if flag { diff --git a/crates/proof/src/pt/grammar.rs b/crates/proof/src/pt/grammar.rs index 6b72e3226..303929de6 100644 --- a/crates/proof/src/pt/grammar.rs +++ b/crates/proof/src/pt/grammar.rs @@ -63,7 +63,9 @@ fn ends_sentence(gap: &str, prev: &str) -> bool { return false; } let rest = t.trim_start_matches(['.', '!', '?']).trim_start_matches(CLOSING); - rest.starts_with(char::is_whitespace) && rest.trim_start().chars().all(|c| OPENING.contains(&c)) + // A dialogue dash after the mark brings back the narration (`—Vai? —disse ele.`), which goes + // on in lower case. + rest.starts_with(char::is_whitespace) && !rest.contains('—') && rest.trim_start().chars().all(|c| OPENING.contains(&c)) } /// Grammar issues in a paragraph of Portuguese text, in order. @@ -115,7 +117,7 @@ fn spaces(text: &str, v: &mut Vec) { // ` ...` is an ellipsis, ` .5` a number. '.' => !matches!(after, Some('.')) && !after.is_some_and(|a| a.is_ascii_digit()), // ` :)`, ` :-)`, ` :D` and similar are emoticons; ` ?!` is still a stray space. - ':' | '!' | '?' => after.is_none_or(|a| a.is_whitespace() || matches!(a, '"' | '”' | '’' | '!' | '?')), + ':' | '!' | '?' => !crate::score_colon(text, i) && after.is_none_or(|a| a.is_whitespace() || matches!(a, '"' | '”' | '’' | '!' | '?')), _ => false, }; if flag { @@ -220,6 +222,9 @@ mod tests { clean("Zhou ficou em 5. lugar no séc. XX."); clean("Esperei... e ele apareceu."); clean("— Vai — disse ele. — Amanhã eu volto."); + // craft-libs#488 review: no space after the dash. + clean("—Vai? —disse ele."); + clean("— Vai? — disse ele."); clean("Ele disse: \"Volto amanhã\". E saiu."); // A list item may start in lower case. clean("maçãs,"); diff --git a/crates/proof/src/ru/grammar.rs b/crates/proof/src/ru/grammar.rs index 70b9a1e62..2677d047d 100644 --- a/crates/proof/src/ru/grammar.rs +++ b/crates/proof/src/ru/grammar.rs @@ -483,13 +483,16 @@ fn spaces(text: &str, v: &mut Vec) { let Some(p) = it.next() else { continue }; let after = it.next(); let flag = match p { - ',' => true, + // ` ,,` opens a typed quote (the doubled-punctuation rule suggests `„`). + ',' => after != Some(','), // `;)` and `;-)` are emoticons. ';' => !matches!(after, Some(')' | '(' | '-' | 'P' | 'D')), // ` ...` is an ellipsis, ` .5` a number. '.' => !matches!(after, Some('.')) && !after.is_some_and(|a| a.is_ascii_digit()), // ` :)`, ` :-)`, ` :D` and similar are emoticons; ` ?!` is still a stray space. - ':' | '!' | '?' => after.is_none_or(|a| a.is_whitespace() || matches!(a, '"' | '»' | '”' | '’' | '!' | '?')), + ':' | '!' | '?' => { + !crate::score_colon(text, i) && after.is_none_or(|a| a.is_whitespace() || matches!(a, '"' | '»' | '”' | '’' | '!' | '?')) + } _ => false, }; if flag {