use icu_segmenter::options::LineBreakOptions;
use icu_segmenter::options::LineBreakStrictness;
use icu_segmenter::options::LineBreakWordOption;
use icu_segmenter::*;
include!("helpers.rs.raw");
#[track_caller]
fn break_all(s: &str, expected: &[&str]) {
let mut options = LineBreakOptions::default();
options.strictness = Some(LineBreakStrictness::Strict);
options.word_option = Some(LineBreakWordOption::BreakAll);
options.content_locale = None;
check_line(s, expected, LineSegmenter::new_dictionary(options));
check_line(s, expected, {
let mut s = LineSegmenter::new_17_for_non_complex_scripts(options);
s.load_dictionary();
s
});
check_line(s, expected, {
let mut s = LineSegmenter::new_neo_for_non_complex_scripts(options);
s.load_dictionary();
s
});
}
#[track_caller]
fn keep_all(s: &str, expected: &[&str]) {
let mut options = LineBreakOptions::default();
options.strictness = Some(LineBreakStrictness::Strict);
options.word_option = Some(LineBreakWordOption::KeepAll);
options.content_locale = None;
check_line(s, expected, LineSegmenter::new_dictionary(options));
check_line(s, expected, {
let mut s = LineSegmenter::new_17_for_non_complex_scripts(options);
s.load_dictionary();
s
});
check_line(s, expected, {
let mut s = LineSegmenter::new_neo_for_non_complex_scripts(options);
s.load_dictionary();
s
});
}
#[track_caller]
fn normal(s: &str, expected: &[&str]) {
let mut options = LineBreakOptions::default();
options.strictness = Some(LineBreakStrictness::Strict);
options.word_option = Some(LineBreakWordOption::Normal);
options.content_locale = None;
check_line(s, expected, LineSegmenter::new_dictionary(options));
check_line(s, expected, {
let mut s = LineSegmenter::new_17_for_non_complex_scripts(options);
s.load_dictionary();
s
});
check_line(s, expected, {
let mut s = LineSegmenter::new_neo_for_non_complex_scripts(options);
s.load_dictionary();
s
});
}
#[test]
fn wordbreak_breakall() {
break_all("日本語", &["日", "本", "語"]);
break_all("latin", &["l", "a", "t", "i", "n"]);
break_all("한글읾", &["한", "글", "읾"]);
break_all(
"ภาษาไทยภาษาไทย",
&[
"ภ", "า", "ษ", "า", "ไ", "ท", "ย", "ภ", "า", "ษ", "า", "ไ", "ท", "ย",
],
);
break_all(
"التدويل نشاط التدويل",
&[
"ا", "ل", "ت", "د", "و", "ي", "ل ", "ن", "ش", "ا", "ط ", "ا", "ل", "ت", "د", "و", "ي",
"ل",
],
);
break_all(
"हिन्दी हिन्दी हिन्दी",
&["हि", "न्", "दी ", "हि", "न्", "दी ", "हि", "न्", "दी"],
);
break_all("💖💔", &["💖", "💔"]);
break_all(r#"XX XX\\\"#, &["X", "X ", "X", "X", "\\", "\\", "\\"]);
break_all("XX XXX///", &["X", "X ", "X", "X", "X///"]);
break_all("X.", &["X."]);
break_all("フォ", &["フ", "ォ"]);
}
#[test]
fn wordbreak_keepall() {
keep_all("latin", &["latin"]);
keep_all("日本語", &["日本語"]);
keep_all("한글이", &["한글이"]);
keep_all("字 字", &["字 ", "字"]);
keep_all("字、字", &["字、", "字"]);
keep_all("しょう。", &["しょう。"]);
keep_all("애기판다", &["애기판다"]);
keep_all("และและ", &["และ", "และ"]);
}
#[test]
fn wordbreak_normal_th() {
normal("ภาษาไทยภาษาไทย", &["ภาษา", "ไทย", "ภาษา", "ไทย"]);
}
#[test]
fn wordbreak_normal_km() {
normal("ភាសាខ្មែរភាសាខ្មែរភាសាខ្មែរ", &["ភាសាខ្មែរ", "ភាសាខ្មែរ", "ភាសាខ្មែរ"]);
}
#[test]
fn wordbreak_normal_lo() {
normal(
"ພາສາລາວພາສາລາວພາສາລາວ",
&["ພາສາ", "ລາວ", "ພາສາ", "ລາວ", "ພາສາ", "ລາວ"],
);
}