seshat/
lib.rs

1//! An integrated Unicode library
2
3pub mod unicode;
4
5pub mod collections;
6
7#[cfg(test)]
8mod tests {
9    use super::unicode::{CodePoint, UnicodeVersion};
10    // use super::unicode::ToCodePoint;
11    use super::unicode::Ucd;
12    use super::unicode::Normalization;
13    use super::unicode::props::*;
14    use super::unicode::UNICODE_VERSION;
15
16    #[test]
17    fn code_point_to_string() {
18        let cp_string = CodePoint::new(0xAC00).unwrap().to_string();
19        assert_eq!("U+AC00", cp_string);
20    }
21
22    #[test]
23    fn code_point_gc() {
24        let cp = CodePoint::new(0xAC00).unwrap();
25        match cp.gc() {
26            Gc::Lo => (),
27            _ => panic!("Not Lo"),
28        }
29    }
30
31    #[test]
32    fn code_point_na() {
33        let c = '🦀';
34        if c.na() != "CRAB" {
35            panic!("Not \"CRAB\"");
36        }
37    }
38
39    #[test]
40    fn str_nfd() {
41        let s = "각";
42        assert_eq!(s.to_nfd(), "\u{1100}\u{1161}\u{11A8}");
43    }
44
45    #[test]
46    fn version_check() {
47        let ver = UnicodeVersion {
48            major: 16,
49            minor: 0,
50            update: 0,
51        };
52        assert_eq!(ver, UNICODE_VERSION);
53    }
54
55    //==============================
56    // Tests for private functions
57    //==============================
58    #[test]
59    fn test_starter() {
60        let cp1 = 0x00A0;
61        assert_eq!(crate::unicode::normalization::starter(cp1), true);
62        let cp2 = 0x0344;
63        assert_eq!(crate::unicode::normalization::starter(cp2), false);
64    }
65
66    #[test]
67    fn test_singleton() {
68        let cp = 0x00A0;
69        assert_eq!(crate::unicode::normalization::singleton_decomposition(cp), false);
70        let cp2 = 0x0300;
71        assert_eq!(crate::unicode::normalization::singleton_decomposition(cp2), false);
72        let cp3 = 0x2126;
73        assert_eq!(crate::unicode::normalization::singleton_decomposition(cp3), true);
74    }
75
76    #[test]
77    fn test_non_starter_decomposition() {
78        let cp1 = 0x0344;
79        assert_eq!(crate::unicode::normalization::non_starter_decomposition(cp1), true);
80        let cp2 = 0x0F73;
81        assert_eq!(crate::unicode::normalization::non_starter_decomposition(cp2), true);
82    }
83
84    #[test]
85    fn test_rdm() {
86        let s1 = "\u{003B}";
87        let composed = crate::unicode::ucd::dm::rdm(s1);
88        assert_eq!(composed, 0x037E);
89
90        let s2 = "\u{1100}\u{1161}";
91        let composed = crate::unicode::ucd::dm::rdm(s2);
92        assert_eq!(composed, 0xAC00);
93    }
94
95    #[test]
96    fn test_nfc() {
97        let s1 = "\u{0065}\u{0301}";
98        let composed = crate::unicode::normalization::nfc(s1);
99        assert_eq!(composed, vec!['é']);
100
101        let s2 = "\u{1100}\u{1161}";
102        let composed = crate::unicode::normalization::nfc(s2);
103        assert_eq!(composed, vec!['가']);
104    }
105}