mod common;
use common::{settle, window};
use std::time::{Duration, Instant};
use taut::{Markdown, Role, Ui};
fn shown(ui: &mut common::Window, doc: &Markdown) {
settle(ui, |ui: &mut Ui| {
ui.column().grow().open();
ui.markdown(doc);
ui.close();
});
}
#[test]
fn an_empty_item_of_a_list_is_as_high_as_its_mark() {
let mut ui = window(1.0);
ui.set_screen_reader(true);
shown(&mut ui, &Markdown::parse("Some words\n\n1."));
let rect_of = |role: Role| ui.visible_access_nodes().iter().find(|node| node.role == role).map(|node| node.rect);
let (document, words) = (rect_of(Role::Document).unwrap(), rect_of(Role::Paragraph).unwrap());
assert!(rect_of(Role::List).is_some(), "the list was not told of");
assert!(document.h >= words.h * 2.0, "the document is {} high, its first paragraph {}: the list after it has no height", document.h, words.h);
}
#[test]
fn a_list_of_empty_items_after_a_long_paragraph_is_drawn_the_same_in_strips_and_whole() {
let text = format!("{}\n\n` {}\n1. 0.", "0".repeat(72), "0".repeat(211));
let doc = Markdown::parse(&text);
let mut ui = window(1.0);
shown(&mut ui, &doc);
}
#[test]
fn lists_nested_thousands_deep_are_read_and_laid_out_in_time() {
let text = format!("{}x\n", "- ".repeat(8_000));
let clock = Instant::now();
let doc = Markdown::parse(&text);
let mut ui = window(1.0);
shown(&mut ui, &doc);
let took = clock.elapsed();
assert!(took < Duration::from_secs(1), "8,000 lists in lists took {took:?} to read and lay out");
}