use super::super::flatten_text_body;
#[test]
fn flatten_text_body_joins_paragraphs_with_space_not_newline() {
use crate::ir::nodes::{DocNode as IrNode, InlineContent, Paragraph};
let body = vec![
IrNode::Paragraph(Paragraph {
content: vec![InlineContent::Text("First line.".into())],
}),
IrNode::Paragraph(Paragraph {
content: vec![InlineContent::Text("Second line.".into())],
}),
];
let flat = flatten_text_body(&body);
assert_eq!(flat, "First line. Second line.");
assert!(
!flat.contains('\n'),
"flattened scalar must not contain raw newlines"
);
}
#[test]
fn flatten_text_body_processes_bare_inline_doc_nodes() {
use crate::ir::nodes::{DocNode as IrNode, InlineContent};
let body = vec![
IrNode::Inline(InlineContent::Text("Hello, ".into())),
IrNode::Inline(InlineContent::Text("world.".into())),
];
assert_eq!(flatten_text_body(&body), "Hello, world.");
}
#[test]
fn flatten_text_body_recurses_through_bold_and_italic() {
use crate::ir::nodes::{DocNode as IrNode, InlineContent, Paragraph};
let body = vec![IrNode::Paragraph(Paragraph {
content: vec![
InlineContent::Italic(vec![InlineContent::Text("Important".into())]),
InlineContent::Text(" ".into()),
InlineContent::Bold(vec![
InlineContent::Text("very ".into()),
InlineContent::Italic(vec![InlineContent::Text("bold".into())]),
]),
InlineContent::Text(" Title".into()),
],
})];
assert_eq!(flatten_text_body(&body), "Important very bold Title");
}