gedcom_rs/types/
note.rs

1/// Parse a Note structure
2// use super::Line;
3use crate::parse;
4
5#[derive(Debug, Default, PartialEq, Clone)]
6pub struct Note {
7    /// The note
8    pub note: Option<String>,
9}
10
11impl Note {
12    pub fn parse(mut buffer: &str) -> (&str, Option<Note>) {
13        let mut note = Note { note: None };
14
15        note.note = parse::get_tag_value(&mut buffer).unwrap();
16
17        (buffer, Some(note))
18    }
19}
20
21#[cfg(test)]
22mod tests {
23    use super::Note;
24
25    #[test]
26    fn parse_note() {
27        // 1 NOTE This file demonstrates all tags that are allowed in GEDCOM 5.5. Here are some comments about the HEADER record
28        // 2 CONC and comments about where to look for information on the other 9 types of GEDCOM records. Most other records will
29        // 2 CONC have their own notes that describe what to look for in that record and what to hope the importing software will find.
30        // 2 CONT
31        // 2 CONT Many applications will fail to import these notes. The notes are therefore also provided with the files as a plain-text
32        // 2 CONC "Read-Me" file.
33
34        let data = vec![
35            "1 NOTE This is the first line of a note.",
36            "2 CONT This is the second line of a note.",
37            "2 CONC This is also on the second line.",
38            "2 CONT This line should be the last line.",
39        ];
40
41        let (_, note) = Note::parse(data.join("\n").as_str());
42        let n = note.unwrap().note.unwrap();
43
44        assert!(n.starts_with("This is the first line of a note.\n"));
45        assert!(n.ends_with("the last line."));
46        assert!(n == "This is the first line of a note.\nThis is the second line of a note. This is also on the second line.\nThis line should be the last line.");
47    }
48}