use text_document::{DjotImportOptions, TABLE_ANCHOR, TextDocument, djot_to_plain_text};
fn plain(djot: &str) -> String {
let doc = TextDocument::new();
doc.set_djot(djot).unwrap().wait().unwrap();
doc.to_plain_text().unwrap()
}
#[test]
fn a_blockquote_is_not_hoisted_to_the_end() {
assert_eq!(
plain("> a0\n\na"),
"a0\na",
"the quotation is written first, so it must be read first"
);
}
#[test]
fn quotes_and_paragraphs_keep_their_interleaving() {
assert_eq!(plain("p1\n\n> q1\n\np2\n\n> q2"), "p1\nq1\np2\nq2");
assert_eq!(plain("a\n\n> a0\n\nb"), "a\na0\nb");
assert_eq!(plain("> a0\n\na\n\n> a1"), "a0\na\na1");
assert_eq!(plain("> a0\n\n> a1\n\na"), "a0\na1\na");
}
#[test]
fn a_quote_is_not_hoisted_past_a_heading_a_list_or_a_fence() {
assert_eq!(plain("> a0\n\n# h"), "a0\nh");
assert_eq!(plain("> a0\n\n- item"), "a0\nitem");
assert_eq!(plain("> a0\n\n```\ncode\n```"), "a0\ncode");
}
#[test]
fn nested_and_multi_block_quotes_stay_in_place() {
assert_eq!(
plain("> outer\n>\n> > inner\n\nafter"),
"outer\ninner\nafter"
);
assert_eq!(
plain("> p1\n>\n> p2\n\nafter"),
"p1\np2\nafter",
"a quote's own blocks stay in order AND stay before what follows the quote"
);
}
#[test]
fn a_table_stays_where_it_was_written() {
assert_eq!(
plain("intro\n\n| a | b |\n| - | - |\n| c | d |\n\nafter"),
"intro\na\nb\nc\nd\nafter"
);
}
#[test]
fn the_human_view_is_the_addressable_view_minus_its_anchors() {
for src in [
"> a0\n\na",
"p1\n\n> q1\n\np2\n\n> q2",
"intro\n\n| a | b |\n| - | - |\n| c | d |\n\nafter",
"> quoted\n\n# head\n\n- item\n\n| x |\n| - |\n| y |",
"a\n\nb\n\nc",
] {
let addressable = djot_to_plain_text(src, &DjotImportOptions::default());
let without_anchors: Vec<&str> = addressable
.split('\n')
.filter(|line| *line != TABLE_ANCHOR)
.collect();
assert_eq!(
plain(src),
without_anchors.join("\n"),
"to_plain_text() and the document's addressable text disagree about more than \
anchors, for {src:?} — the only sanctioned difference is the object anchors"
);
}
}