]> git.proxmox.com Git - rustc.git/blob - vendor/ucd-parse/src/age.rs
New upstream version 1.42.0+dfsg1
[rustc.git] / vendor / ucd-parse / src / age.rs
1
2 use std::path::Path;
3 use std::str::FromStr;
4
5 use common::{
6 UcdFile, UcdFileByCodepoint, Codepoints, CodepointIter,
7 parse_codepoint_association,
8 };
9 use error::Error;
10
11 /// A single row in the `DerivedAge.txt` file.
12 #[derive(Clone, Debug, Default, Eq, PartialEq)]
13 pub struct Age {
14 /// The codepoint or codepoint range for this entry.
15 pub codepoints: Codepoints,
16 /// The age assigned to the codepoints in this entry.
17 pub age: String,
18 }
19
20 impl UcdFile for Age {
21 fn relative_file_path() -> &'static Path {
22 Path::new("DerivedAge.txt")
23 }
24 }
25
26 impl UcdFileByCodepoint for Age {
27 fn codepoints(&self) -> CodepointIter {
28 self.codepoints.into_iter()
29 }
30 }
31
32 impl 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 {
38 codepoints: codepoints,
39 age: script.to_string(),
40 })
41 }
42 }
43
44 #[cfg(test)]
45 mod tests {
46 use super::Age;
47
48 #[test]
49 fn parse_single() {
50 let line = "2BD2 ; 10.0 # GROUP MARK\n";
51 let row: Age = line.parse().unwrap();
52 assert_eq!(row.codepoints, 0x2BD2);
53 assert_eq!(row.age, "10.0");
54 }
55
56 #[test]
57 fn parse_range() {
58 let line = "11D0B..11D36 ; 10.0 # [44] MASARAM GONDI LETTER AU..MASARAM GONDI VOWEL SIGN VOCALIC R\n";
59 let row: Age = line.parse().unwrap();
60 assert_eq!(row.codepoints, (0x11D0B, 0x11D36));
61 assert_eq!(row.age, "10.0");
62 }
63 }