1use std::path::Path;
2
3use crate::{
4 common::{parse_break_test, UcdFile},
5 error::Error,
6};
7
8/// A single row in the `auxiliary/LineBreakTest.txt` file.
9///
10/// This file defines tests for the line break algorithm.
11#[derive(Clone, Debug, Default, Eq, PartialEq)]
12pub struct LineBreakTest {
13 /// Each string is a UTF-8 encoded group of codepoints that make up a
14 /// single line.
15 pub lines: Vec<String>,
16 /// A human readable description of this test.
17 pub comment: String,
18}
19
20impl UcdFile for LineBreakTest {
21 fn relative_file_path() -> &'static Path {
22 Path::new("auxiliary/LineBreakTest.txt")
23 }
24}
25
26impl std::str::FromStr for LineBreakTest {
27 type Err = Error;
28
29 fn from_str(line: &str) -> Result<LineBreakTest, Error> {
30 let (groups: Vec, comment: String) = parse_break_test(line)?;
31 Ok(LineBreakTest { lines: groups, comment })
32 }
33}
34
35#[cfg(test)]
36mod tests {
37 use super::LineBreakTest;
38
39 #[test]
40 fn parse_test() {
41 let line = "× 1F1F7 × 1F1FA ÷ 1F1F8 × 1F1EA ÷ # × [0.3] REGIONAL INDICATOR SYMBOL LETTER R (RI) × [30.11] REGIONAL INDICATOR SYMBOL LETTER U (RI) ÷ [30.13] REGIONAL INDICATOR SYMBOL LETTER S (RI) × [30.11] REGIONAL INDICATOR SYMBOL LETTER E (RI) ÷ [0.3]";
42
43 let row: LineBreakTest = line.parse().unwrap();
44 assert_eq!(
45 row.lines,
46 vec!["\u{1F1F7}\u{1F1FA}", "\u{1F1F8}\u{1F1EA}",]
47 );
48 assert!(row.comment.ends_with("(RI) ÷ [0.3]"));
49 }
50}
51