use unic_char_property::TotalCharProperty;
char_property! {
pub enum SentenceBreak {
abbr => "SB";
long => "Sentence_Break";
human => "Sentence Break";
CR {
abbr => CR,
long => CR,
human => "Carriage Return",
}
LF {
abbr => LF,
long => LF,
human => "Line Feed",
}
Extend {
abbr => Extend,
long => Extend,
human => "Extend",
}
Sep {
abbr => SE,
long => Sep,
human => "Separator",
}
Format {
abbr => FO,
long => Format,
human => "Format",
}
Sp {
abbr => SP,
long => Sp,
human => "Space",
}
Lower {
abbr => LO,
long => Lower,
human => "Lowercase",
}
Upper {
abbr => UP,
long => Upper,
human => "Uppercase",
}
OLetter {
abbr => LE,
long => OLetter,
human => "Other Letter",
}
Numeric {
abbr => NU,
long => Numeric,
human => "Numeric",
}
ATerm {
abbr => AT,
long => ATerm,
human => "ATerm",
}
SContinue {
abbr => SC,
long => SContinue,
human => "Sentence Continue",
}
STerm {
abbr => ST,
long => STerm,
human => "Sentence Terminal",
}
Close {
abbr => CL,
long => Close,
human => "Close",
}
Other {
abbr => XX,
long => Other,
human => "Other",
}
}
pub mod abbr_names for abbr;
pub mod long_names for long;
}
impl TotalCharProperty for SentenceBreak {
fn of(ch: char) -> Self {
Self::of(ch)
}
}
impl Default for SentenceBreak {
fn default() -> Self {
SentenceBreak::Other
}
}
mod data {
use super::long_names as SB;
use unic_char_property::tables::CharDataTable;
pub const SENTENCE_BREAK_TABLE: CharDataTable<super::SentenceBreak> =
include!("../tables/sentence_break.rsv");
}
impl SentenceBreak {
pub fn of(ch: char) -> SentenceBreak {
data::SENTENCE_BREAK_TABLE.find_or_default(ch)
}
}
#[cfg(test)]
mod tests {
use super::SentenceBreak as SB;
use unic_char_property::EnumeratedCharProperty;
#[test]
fn test_ascii() {
assert_eq!(SB::of('\u{0000}'), SB::Other);
assert_eq!(SB::of('\u{0040}'), SB::Other);
assert_eq!(SB::of('\u{0041}'), SB::Upper);
assert_eq!(SB::of('\u{0062}'), SB::Lower);
assert_eq!(SB::of('\u{007F}'), SB::Other);
}
#[test]
fn test_bmp() {
assert_eq!(SB::of('\u{0590}'), SB::Other);
assert_eq!(SB::of('\u{05D0}'), SB::OLetter);
assert_eq!(SB::of('\u{05D1}'), SB::OLetter);
assert_eq!(SB::of('\u{05FF}'), SB::Other);
assert_eq!(SB::of('\u{0600}'), SB::Format);
assert_eq!(SB::of('\u{0627}'), SB::OLetter);
assert_eq!(SB::of('\u{07BF}'), SB::Other);
assert_eq!(SB::of('\u{07C0}'), SB::Numeric);
assert_eq!(SB::of('\u{085F}'), SB::Other);
assert_eq!(SB::of('\u{0860}'), SB::OLetter);
assert_eq!(SB::of('\u{0870}'), SB::Other);
assert_eq!(SB::of('\u{089F}'), SB::Other);
assert_eq!(SB::of('\u{08A0}'), SB::OLetter);
assert_eq!(SB::of('\u{089F}'), SB::Other);
assert_eq!(SB::of('\u{08FF}'), SB::Extend);
assert_eq!(SB::of('\u{20A0}'), SB::Other);
assert_eq!(SB::of('\u{20CF}'), SB::Other);
assert_eq!(SB::of('\u{FB1D}'), SB::OLetter);
assert_eq!(SB::of('\u{FB4F}'), SB::OLetter);
assert_eq!(SB::of('\u{FB50}'), SB::OLetter);
assert_eq!(SB::of('\u{FDCF}'), SB::Other);
assert_eq!(SB::of('\u{FDF0}'), SB::OLetter);
assert_eq!(SB::of('\u{FDFF}'), SB::Other);
assert_eq!(SB::of('\u{FE70}'), SB::OLetter);
assert_eq!(SB::of('\u{FEFE}'), SB::Other);
assert_eq!(SB::of('\u{FEFF}'), SB::Format);
assert_eq!(SB::of('\u{FDD0}'), SB::Other);
assert_eq!(SB::of('\u{FDD1}'), SB::Other);
assert_eq!(SB::of('\u{FDEE}'), SB::Other);
assert_eq!(SB::of('\u{FDEF}'), SB::Other);
assert_eq!(SB::of('\u{FFFE}'), SB::Other);
assert_eq!(SB::of('\u{FFFF}'), SB::Other);
}
#[test]
fn test_smp() {
assert_eq!(SB::of('\u{10800}'), SB::OLetter);
assert_eq!(SB::of('\u{10FFF}'), SB::Other);
assert_eq!(SB::of('\u{1E800}'), SB::OLetter);
assert_eq!(SB::of('\u{1EDFF}'), SB::Other);
assert_eq!(SB::of('\u{1EE00}'), SB::OLetter);
assert_eq!(SB::of('\u{1EEFF}'), SB::Other);
assert_eq!(SB::of('\u{1EF00}'), SB::Other);
assert_eq!(SB::of('\u{1EFFF}'), SB::Other);
}
#[test]
fn test_unassigned_planes() {
assert_eq!(SB::of('\u{30000}'), SB::Other);
assert_eq!(SB::of('\u{40000}'), SB::Other);
assert_eq!(SB::of('\u{50000}'), SB::Other);
assert_eq!(SB::of('\u{60000}'), SB::Other);
assert_eq!(SB::of('\u{70000}'), SB::Other);
assert_eq!(SB::of('\u{80000}'), SB::Other);
assert_eq!(SB::of('\u{90000}'), SB::Other);
assert_eq!(SB::of('\u{a0000}'), SB::Other);
}
#[test]
fn test_abbr_name() {
assert_eq!(SB::CR.abbr_name(), "CR");
}
#[test]
fn test_long_name() {
assert_eq!(SB::CR.long_name(), "CR");
}
#[test]
fn test_human_name() {
assert_eq!(SB::CR.human_name(), "Carriage Return");
}
}