Header tests

issue1
Alex Bethel 2021-11-27 21:37:30 -07:00
parent 71c9249916
commit f6112f70df
1 changed files with 95 additions and 0 deletions

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