1use std::path::Path;
2
3use crate::{
4 common::{
5 parse_codepoint_association, CodepointIter, Codepoints, UcdFile,
6 UcdFileByCodepoint,
7 },
8 error::Error,
9};
10
11#[derive(Clone, Debug, Default, Eq, PartialEq)]
13pub struct Age {
14 pub codepoints: Codepoints,
16 pub age: String,
18}
19
20impl UcdFile for Age {
21 fn relative_file_path() -> &'static Path {
22 Path::new("DerivedAge.txt")
23 }
24}
25
26impl UcdFileByCodepoint for Age {
27 fn codepoints(&self) -> CodepointIter {
28 self.codepoints.into_iter()
29 }
30}
31
32impl std::str::FromStr for Age {
33 type Err = Error;
34
35 fn from_str(line: &str) -> Result<Age, Error> {
36 let (codepoints, script) = parse_codepoint_association(line)?;
37 Ok(Age { codepoints, age: script.to_string() })
38 }
39}
40
41#[cfg(test)]
42mod tests {
43 use super::Age;
44
45 #[test]
46 fn parse_single() {
47 let line = "2BD2 ; 10.0 # GROUP MARK\n";
48 let row: Age = line.parse().unwrap();
49 assert_eq!(row.codepoints, 0x2BD2);
50 assert_eq!(row.age, "10.0");
51 }
52
53 #[test]
54 fn parse_range() {
55 let line = "11D0B..11D36 ; 10.0 # [44] MASARAM GONDI LETTER AU..MASARAM GONDI VOWEL SIGN VOCALIC R\n";
56 let row: Age = line.parse().unwrap();
57 assert_eq!(row.codepoints, (0x11D0B, 0x11D36));
58 assert_eq!(row.age, "10.0");
59 }
60}