Extract public asssert_segments() function

This commit is contained in:
Dirkjan Ochtman 2021-02-04 10:40:04 +01:00
parent 45e569379c
commit 96187965b6
2 changed files with 10 additions and 6 deletions

View File

@ -1,15 +1,19 @@
use crate::Segmenter; use crate::Segmenter;
/// Run a segmenter against the built-in test cases /// Run a segmenter against the built-in test cases
pub fn run(segmenter: Segmenter) { pub fn run(segmenter: &Segmenter) {
for test in TEST_CASES.iter().copied() { for test in TEST_CASES.iter().copied() {
let mut out = Vec::new(); assert_segments(segmenter, test);
segmenter.segment(&test.join(""), &mut out);
let cmp = out.iter().map(|s| &*s).collect::<Vec<_>>();
assert_eq!(cmp, test);
} }
} }
pub fn assert_segments(segmenter: &Segmenter, s: &[&str]) {
let mut out = Vec::new();
segmenter.segment(&s.join(""), &mut out);
let cmp = out.iter().map(|s| &*s).collect::<Vec<_>>();
assert_eq!(cmp, s);
}
/// Built-in test cases /// Built-in test cases
/// ///
/// These are exposed so that you can test with different data sources. /// These are exposed so that you can test with different data sources.

View File

@ -9,7 +9,7 @@ use super::Segmenter;
#[test] #[test]
fn test_data() { fn test_data() {
crate::test_cases::run(segmenter()); crate::test_cases::run(&segmenter());
} }
pub fn segmenter() -> Segmenter { pub fn segmenter() -> Segmenter {