From 96187965b65c81ad5c96b301e296eccf5df2d888 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Thu, 4 Feb 2021 10:40:04 +0100 Subject: [PATCH] Extract public asssert_segments() function --- src/test_cases.rs | 14 +++++++++----- src/test_data.rs | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/test_cases.rs b/src/test_cases.rs index 3cd008e..a915766 100644 --- a/src/test_cases.rs +++ b/src/test_cases.rs @@ -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::>(); - 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::>(); + assert_eq!(cmp, s); +} + /// Built-in test cases /// /// These are exposed so that you can test with different data sources. diff --git a/src/test_data.rs b/src/test_data.rs index 63a4954..bd86c1d 100644 --- a/src/test_data.rs +++ b/src/test_data.rs @@ -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 {