diff --git a/src/lib.rs b/src/lib.rs index 4c6e617..a7fbe1e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -197,4 +197,99 @@ New paragraph", assert_eq!(doc, doc_ref); } + + /// Test "#" headers and their interactions with paragraphs. + #[test] + fn headers() { + let doc = parse( + "\ +Paragraph 1 +# Header 1 +Paragraph 2 +## Subheader 1 +Paragraph 3 + +## Subheader 2 + +Paragraph 4", + ); + let doc_ref = Document(vec![ + Node::Paragraph(vec![StyledText { + italic: false, + bold: false, + underline: false, + color: None, + text: "Paragraph 1".to_string(), + }]), + Node::Header(Header { + label: "Header 1".to_string(), + level: 1, + }), + Node::Paragraph(vec![StyledText { + italic: false, + bold: false, + underline: false, + color: None, + text: "Paragraph 2".to_string(), + }]), + Node::Header(Header { + label: "Subheader 1".to_string(), + level: 2, + }), + Node::Paragraph(vec![StyledText { + italic: false, + bold: false, + underline: false, + color: None, + text: "Paragraph 3".to_string(), + }]), + Node::Header(Header { + label: "Subheader 2".to_string(), + level: 2, + }), + Node::Paragraph(vec![StyledText { + italic: false, + bold: false, + underline: false, + color: None, + text: "Paragraph 4".to_string(), + }]), + ]); + + assert_eq!(doc, doc_ref); + } + + /// Test headers with underlines. + #[test] + fn alt_headers() { + let doc = parse( + "\ +Text +Header +------ +More text", + ); + let doc_ref = Document(vec![ + Node::Paragraph(vec![StyledText { + italic: false, + bold: false, + underline: false, + color: None, + text: "Text".to_string(), + }]), + Node::Header(Header { + label: "Header".to_string(), + level: 1, + }), + Node::Paragraph(vec![StyledText { + italic: false, + bold: false, + underline: false, + color: None, + text: "More text".to_string(), + }]), + ]); + + assert_eq!(doc, doc_ref); + } }