yeslogic_ucd_parse/extracted/
derived_joining_type.rs1use 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)]
15pub struct DerivedJoiningType {
16 pub codepoints: Codepoints,
18 pub joining_type: String,
20}
21
22impl UcdFile for DerivedJoiningType {
23 fn relative_file_path() -> &'static Path {
24 Path::new("extracted/DerivedJoiningType.txt")
25 }
26}
27
28impl UcdFileByCodepoint for DerivedJoiningType {
29 fn codepoints(&self) -> CodepointIter {
30 self.codepoints.into_iter()
31 }
32}
33
34impl std::str::FromStr for DerivedJoiningType {
35 type Err = Error;
36
37 fn from_str(line: &str) -> Result<DerivedJoiningType, Error> {
38 let (codepoints, joining_type) = parse_codepoint_association(line)?;
39 Ok(DerivedJoiningType {
40 codepoints,
41 joining_type: joining_type.to_string(),
42 })
43 }
44}
45
46#[cfg(test)]
47mod tests {
48 use super::DerivedJoiningType;
49
50 #[test]
51 fn parse_single() {
52 let line = "0628 ; D # Lo ARABIC LETTER BEH\n";
53 let row: DerivedJoiningType = line.parse().unwrap();
54 assert_eq!(row.codepoints, 0x0628);
55 assert_eq!(row.joining_type, "D");
56 }
57
58 #[test]
59 fn parse_range() {
60 let line = "1133B..1133C ; T # Mn [2] COMBINING BINDU BELOW..GRANTHA SIGN NUKTA\n";
61 let row: DerivedJoiningType = line.parse().unwrap();
62 assert_eq!(row.codepoints, (0x1133B, 0x1133C));
63 assert_eq!(row.joining_type, "T");
64 }
65}