mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 17:27:19 +00:00
CP6.13: craft-libs#495 review — an oversized pack licence is skipped alone; a score (3 : 1) keeps its spaces in hr, it, pl, pt and ru; ' ,,' (a typed quote) is left to the quote rule in pl and ru; pt narration after a dialogue dash is no new sentence
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FypgCX8LsYYE8fsj4byBm2
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
fdb52ec3c6
commit
be52680c9c
@@ -98,7 +98,7 @@ fn spaces(text: &str, v: &mut Vec<Issue>) {
|
||||
// ` ...` 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 {
|
||||
|
||||
@@ -196,7 +196,7 @@ fn spaces(text: &str, v: &mut Vec<Issue>) {
|
||||
// ` ...` 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 {
|
||||
|
||||
@@ -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<locale>`.
|
||||
fn many_packs(root: &std::path::Path, n: usize) -> Vec<ProofLang> {
|
||||
(0..n)
|
||||
|
||||
@@ -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()?;
|
||||
|
||||
@@ -288,13 +288,16 @@ fn spaces(text: &str, v: &mut Vec<Issue>) {
|
||||
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 {
|
||||
|
||||
@@ -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<Issue>) {
|
||||
// ` ...` 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,");
|
||||
|
||||
@@ -483,13 +483,16 @@ fn spaces(text: &str, v: &mut Vec<Issue>) {
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user