No longer need a macro for testing

This commit is contained in:
Dirkjan Ochtman 2020-12-07 11:55:27 +01:00
parent 912e6477e3
commit f26793379b
1 changed files with 21 additions and 23 deletions

View File

@ -4,28 +4,19 @@ use once_cell::sync::Lazy;
use word_segmenters::Segmenter;
macro_rules! assert_segments {
($list:expr) => {
let mut out = Vec::new();
SEGMENTER.segment(&$list.join(""), &mut out);
let cmp = out.iter().map(|s| &*s).collect::<Vec<_>>();
assert_eq!(cmp, $list);
};
}
#[test]
fn test_segment_0() {
assert_segments!(&["choose", "spain"]);
assert_segments(&["choose", "spain"]);
}
#[test]
fn test_segment_1() {
assert_segments!(&["this", "is", "a", "test"]);
assert_segments(&["this", "is", "a", "test"]);
}
#[test]
fn test_segment_2() {
assert_segments!(&[
assert_segments(&[
"when",
"in",
"the",
@ -41,32 +32,32 @@ fn test_segment_2() {
#[test]
fn test_segment_3() {
assert_segments!(&["who", "represents"]);
assert_segments(&["who", "represents"]);
}
#[test]
fn test_segment_4() {
assert_segments!(&["experts", "exchange"]);
assert_segments(&["experts", "exchange"]);
}
#[test]
fn test_segment_5() {
assert_segments!(&["speed", "of", "art"]);
assert_segments(&["speed", "of", "art"]);
}
#[test]
fn test_segment_6() {
assert_segments!(&["now", "is", "the", "time", "for", "all", "good"]);
assert_segments(&["now", "is", "the", "time", "for", "all", "good"]);
}
#[test]
fn test_segment_7() {
assert_segments!(&["it", "is", "a", "truth", "universally", "acknowledged"]);
assert_segments(&["it", "is", "a", "truth", "universally", "acknowledged"]);
}
#[test]
fn test_segment_8() {
assert_segments!(&[
assert_segments(&[
"it", "was", "a", "bright", "cold", "day", "in", "april", "and", "the", "clocks", "were",
"striking", "thirteen",
]);
@ -74,7 +65,7 @@ fn test_segment_8() {
#[test]
fn test_segment_9() {
assert_segments!(&[
assert_segments(&[
"it",
"was",
"the",
@ -104,7 +95,7 @@ fn test_segment_9() {
#[test]
fn test_segment_10() {
assert_segments!(&[
assert_segments(&[
"as",
"gregor",
"samsa",
@ -130,18 +121,18 @@ fn test_segment_10() {
#[test]
fn test_segment_11() {
assert_segments!(vec![
assert_segments(&[
"in", "a", "hole", "in", "the", "ground", "there", "lived", "a", "hobbit", "not", "a",
"nasty", "dirty", "wet", "hole", "filled", "with", "the", "ends", "of", "worms", "and",
"an", "oozy", "smell", "nor", "yet", "a", "dry", "bare", "sandy", "hole", "with",
"nothing", "in", "it", "to", "sit", "down", "on", "or", "to", "eat", "it", "was", "a",
"hobbit", "hole", "and", "that", "means", "comfort"
"hobbit", "hole", "and", "that", "means", "comfort",
]);
}
#[test]
fn test_segment_12() {
assert_segments!(&[
assert_segments(&[
"far",
"out",
"in",
@ -170,4 +161,11 @@ fn test_segment_12() {
]);
}
fn assert_segments(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);
}
static SEGMENTER: Lazy<Segmenter> = Lazy::new(word_segmenters::test_data::segmenter);