[lang] Tests: fixtures read the same with LF or CRLF line endings
This commit is contained in:
@@ -7,8 +7,9 @@
|
|||||||
|
|
||||||
use liber_lang::align::{Bead, align, score, sentence_pairs};
|
use liber_lang::align::{Bead, align, score, sentence_pairs};
|
||||||
|
|
||||||
fn paragraphs(text: &str) -> Vec<&str> {
|
/// Paragraphs, whatever line endings the checkout gave the fixture.
|
||||||
text.split("\n\n").map(str::trim).filter(|p| !p.is_empty()).collect()
|
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 {
|
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 de = paragraphs(include_str!("fixtures/align_de.txt"));
|
||||||
let en = paragraphs(include_str!("fixtures/align_en.txt"));
|
let en = paragraphs(include_str!("fixtures/align_en.txt"));
|
||||||
// The last paragraph: two German sentences, three English (the second split in two).
|
// 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();
|
let shape: Vec<(usize, usize)> = pairs.iter().map(|(a, b)| (a.len(), b.len())).collect();
|
||||||
assert_eq!(shape, vec![(1, 1), (1, 2)], "{pairs:?}");
|
assert_eq!(shape, vec![(1, 1), (1, 2)], "{pairs:?}");
|
||||||
// A one-to-one paragraph: three and three.
|
// 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)]);
|
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.
|
// Ranges are UTF-16 offsets into the paragraph: the first German sentence is the reader's text.
|
||||||
let (a, _) = &pairs[0];
|
let (a, _) = &pairs[0];
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ fn fixture(lang: Lang) -> Vec<(String, String)> {
|
|||||||
Lang::La => include_str!("fixtures/lemma_la.tsv"),
|
Lang::La => include_str!("fixtures/lemma_la.tsv"),
|
||||||
};
|
};
|
||||||
text.lines()
|
text.lines()
|
||||||
|
.map(|l| l.trim_end_matches('\r'))
|
||||||
.filter(|l| !l.is_empty() && !l.starts_with('#'))
|
.filter(|l| !l.is_empty() && !l.starts_with('#'))
|
||||||
.map(|l| {
|
.map(|l| {
|
||||||
let (f, le) = l.split_once('\t').expect("form<TAB>lemma");
|
let (f, le) = l.split_once('\t').expect("form<TAB>lemma");
|
||||||
|
|||||||
Reference in New Issue
Block a user