mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-08 19:42:12 +00:00
craft-proof es — a run of spaces is one Espacio doble issue over the whole run (#496 review)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
15d3c0d370
commit
bd3db196a5
1 file changed
+23
-3
@@ -75,11 +75,21 @@ fn spaces(text: &str, lang: ProofLang, v: &mut Vec<Issue>) {
|
||||
v.push(issue(i, i + 1 + p.len_utf8(), "Espacio antes de un signo de puntuación".into(), vec![p.to_string()], lang));
|
||||
}
|
||||
}
|
||||
for (i, _) in text.match_indices(" ") {
|
||||
if i > 0 && text.get(..i).is_some_and(|t| t.ends_with(' ')) {
|
||||
// Each run of two or more spaces once, over the whole run.
|
||||
let bytes = text.as_bytes();
|
||||
let mut i = 0;
|
||||
while i < bytes.len() {
|
||||
if bytes.get(i) != Some(&b' ') {
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
v.push(issue(i, i + 2, "Espacio doble".into(), vec![" ".into()], lang));
|
||||
let start = i;
|
||||
while bytes.get(i) == Some(&b' ') {
|
||||
i += 1;
|
||||
}
|
||||
if i - start >= 2 {
|
||||
v.push(issue(start, i, "Espacio doble".into(), vec![" ".into()], lang));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,6 +204,16 @@ mod tests {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// craft-libs#496 review: a run of spaces is one issue over the whole run.
|
||||
#[test]
|
||||
fn a_run_of_spaces_is_reported_whole() {
|
||||
for (text, run) in [("casa roja", " "), ("casa roja", " "), ("casa roja", " "), ("casa roja", " ")] {
|
||||
let m: Vec<_> = messages(text).into_iter().filter(|(_, msg)| msg == "Espacio doble").collect();
|
||||
assert_eq!(m, [(run.to_string(), "Espacio doble".to_string())], "{text}");
|
||||
}
|
||||
assert!(messages("casa roja").is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn repeated_words_and_spaces_have_spanish_messages() {
|
||||
let text = "Es es la casa , dijo.";
|
||||
|
||||
Reference in new issue
Block a user