[lang] Tests: fixtures read the same with LF or CRLF line endings

This commit is contained in:
2026-11-17 19:35:02 +01:00
parent 7dca9de95c
commit 40c2b5377b
2 changed files with 6 additions and 4 deletions
+5 -4
View File
@@ -7,8 +7,9 @@
use liber_lang::align::{Bead, align, score, sentence_pairs};
fn paragraphs(text: &str) -> Vec<&str> {
text.split("\n\n").map(str::trim).filter(|p| !p.is_empty()).collect()
/// Paragraphs, whatever line endings the checkout gave the fixture.
fn paragraphs(text: &str) -> Vec<String> {
text.replace("\r\n", "\n").split("\n\n").map(str::trim).filter(|p| !p.is_empty()).map(str::to_owned).collect()
}
fn bead(a: &[usize], b: &[usize]) -> Bead {
@@ -49,11 +50,11 @@ fn sentences_of_an_aligned_paragraph() {
let de = paragraphs(include_str!("fixtures/align_de.txt"));
let en = paragraphs(include_str!("fixtures/align_en.txt"));
// The last paragraph: two German sentences, three English (the second split in two).
let pairs = sentence_pairs(de[10], en[8]);
let pairs = sentence_pairs(&de[10], &en[8]);
let shape: Vec<(usize, usize)> = pairs.iter().map(|(a, b)| (a.len(), b.len())).collect();
assert_eq!(shape, vec![(1, 1), (1, 2)], "{pairs:?}");
// A one-to-one paragraph: three and three.
let pairs = sentence_pairs(de[2], en[2]);
let pairs = sentence_pairs(&de[2], &en[2]);
assert_eq!(pairs.iter().map(|(a, b)| (a.len(), b.len())).collect::<Vec<_>>(), vec![(1, 1), (1, 1), (1, 1)]);
// Ranges are UTF-16 offsets into the paragraph: the first German sentence is the reader's text.
let (a, _) = &pairs[0];
+1
View File
@@ -11,6 +11,7 @@ fn fixture(lang: Lang) -> Vec<(String, String)> {
Lang::La => include_str!("fixtures/lemma_la.tsv"),
};
text.lines()
.map(|l| l.trim_end_matches('\r'))
.filter(|l| !l.is_empty() && !l.starts_with('#'))
.map(|l| {
let (f, le) = l.split_once('\t').expect("form<TAB>lemma");