Extract public asssert_segments() function
This commit is contained in:
parent
45e569379c
commit
96187965b6
|
@ -1,15 +1,19 @@
|
|||
use crate::Segmenter;
|
||||
|
||||
/// 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() {
|
||||
let mut out = Vec::new();
|
||||
segmenter.segment(&test.join(""), &mut out);
|
||||
let cmp = out.iter().map(|s| &*s).collect::<Vec<_>>();
|
||||
assert_eq!(cmp, test);
|
||||
assert_segments(segmenter, 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
|
||||
///
|
||||
/// These are exposed so that you can test with different data sources.
|
||||
|
|
|
@ -9,7 +9,7 @@ use super::Segmenter;
|
|||
|
||||
#[test]
|
||||
fn test_data() {
|
||||
crate::test_cases::run(segmenter());
|
||||
crate::test_cases::run(&segmenter());
|
||||
}
|
||||
|
||||
pub fn segmenter() -> Segmenter {
|
||||
|
|
Loading…
Reference in New Issue