unic_idna_mapping/
mapping.rs1#[repr(u8)]
14#[derive(Copy, Clone, Debug, PartialEq, Eq)]
15pub enum Mapping {
16 Valid,
18
19 Ignored,
21
22 Mapped(&'static str),
24
25 Deviation(&'static str),
27
28 Disallowed,
30
31 DisallowedStd3Valid,
33
34 DisallowedStd3Mapped(&'static str),
36}
37
38mod data {
39 use super::Mapping::*;
40 use unic_char_property::tables::CharDataTable;
41
42 #[cfg_attr(feature = "cargo-clippy", allow(unreadable_literal))]
43 pub const MAPPING: CharDataTable<super::Mapping> = include!("../tables/idna_mapping.rsv");
44}
45
46impl Mapping {
47 pub fn of(ch: char) -> Mapping {
49 data::MAPPING.find(ch).expect("Table is missing value")
50 }
51}
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56
57 #[test]
58 fn test_mapping() {
59 use crate::Mapping::*;
60
61 assert_eq!(Mapping::of('\u{0}'), DisallowedStd3Valid);
62 assert_eq!(Mapping::of('-'), Valid);
63 assert_eq!(Mapping::of('A'), Mapped("a"));
64 assert_eq!(Mapping::of('\u{80}'), Disallowed);
65 assert_eq!(Mapping::of('\u{a0}'), DisallowedStd3Mapped(" "));
66 assert_eq!(Mapping::of('\u{ad}'), Ignored);
67 assert_eq!(Mapping::of('\u{200c}'), Deviation(""));
68 }
69}