From 40c2b5377ba9118ddfc0261da83baa165e45b853 Mon Sep 17 00:00:00 2001 From: mnovak Date: Tue, 17 Nov 2026 19:35:02 +0100 Subject: [PATCH] [lang] Tests: fixtures read the same with LF or CRLF line endings --- crates/liber-lang/tests/align.rs | 9 +++++---- crates/liber-lang/tests/lemma.rs | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/liber-lang/tests/align.rs b/crates/liber-lang/tests/align.rs index 42995c3..f07f80e 100644 --- a/crates/liber-lang/tests/align.rs +++ b/crates/liber-lang/tests/align.rs @@ -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 { + 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![(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]; diff --git a/crates/liber-lang/tests/lemma.rs b/crates/liber-lang/tests/lemma.rs index 4b4016d..0548a23 100644 --- a/crates/liber-lang/tests/lemma.rs +++ b/crates/liber-lang/tests/lemma.rs @@ -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("formlemma");