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