Header tests

This commit is contained in:
Alex Bethel 2021-11-27 21:37:30 -07:00
parent 18b1cc9d7f
commit df27e0af25

View file

@ -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);
}
}