#[repr(u8)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Mapping {
Valid,
Ignored,
Mapped(&'static str),
Deviation(&'static str),
Disallowed,
DisallowedStd3Valid,
DisallowedStd3Mapped(&'static str),
}
mod data {
use super::Mapping::*;
use unic_char_property::tables::CharDataTable;
#[cfg_attr(feature = "cargo-clippy", allow(unreadable_literal))]
pub const MAPPING: CharDataTable<super::Mapping> = include!("../tables/idna_mapping.rsv");
}
impl Mapping {
pub fn of(ch: char) -> Mapping {
data::MAPPING.find(ch).expect("Table is missing value")
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_mapping() {
use crate::Mapping::*;
assert_eq!(Mapping::of('\u{0}'), DisallowedStd3Valid);
assert_eq!(Mapping::of('-'), Valid);
assert_eq!(Mapping::of('A'), Mapped("a"));
assert_eq!(Mapping::of('\u{80}'), Disallowed);
assert_eq!(Mapping::of('\u{a0}'), DisallowedStd3Mapped(" "));
assert_eq!(Mapping::of('\u{ad}'), Ignored);
assert_eq!(Mapping::of('\u{200c}'), Deviation(""));
}
}