1use std::path::Path;
2use std::str::FromStr;
3
4use crate::common::{
5 parse_codepoint_association, CodepointIter, Codepoints, UcdFile,
6 UcdFileByCodepoint,
7};
8use crate::error::Error;
9
10/// A single row in the `extracted/DerivedJoiningGroup.txt` file.
11///
12/// This file gives the derived values of the Joining_Group property.
13#[derive(Clone, Debug, Default, Eq, PartialEq)]
14pub struct DerivedJoiningGroup {
15 /// The codepoint or codepoint range for this entry.
16 pub codepoints: Codepoints,
17 /// The derived Joining_Group of the codepoints in this entry.
18 pub joining_group: String,
19}
20
21impl UcdFile for DerivedJoiningGroup {
22 fn relative_file_path() -> &'static Path {
23 Path::new("extracted/DerivedJoiningGroup.txt")
24 }
25}
26
27impl UcdFileByCodepoint for DerivedJoiningGroup {
28 fn codepoints(&self) -> CodepointIter {
29 self.codepoints.into_iter()
30 }
31}
32
33impl FromStr for DerivedJoiningGroup {
34 type Err = Error;
35
36 fn from_str(line: &str) -> Result<DerivedJoiningGroup, Error> {
37 let (codepoints: Codepoints, joining_group: &str) = parse_codepoint_association(line)?;
38 Ok(DerivedJoiningGroup {
39 codepoints,
40 joining_group: joining_group.to_string(),
41 })
42 }
43}
44
45#[cfg(test)]
46mod tests {
47 use super::DerivedJoiningGroup;
48
49 #[test]
50 fn parse_single() {
51 let line = "0710 ; Alaph # Lo SYRIAC LETTER ALAPH\n";
52 let row: DerivedJoiningGroup = line.parse().unwrap();
53 assert_eq!(row.codepoints, 0x0710);
54 assert_eq!(row.joining_group, "Alaph");
55 }
56
57 #[test]
58 fn parse_range() {
59 let line = "0633..0634 ; Seen # Lo [2] ARABIC LETTER SEEN..ARABIC LETTER SHEEN\n";
60 let row: DerivedJoiningGroup = line.parse().unwrap();
61 assert_eq!(row.codepoints, (0x0633, 0x0634));
62 assert_eq!(row.joining_group, "Seen");
63 }
64}
65