use crate::work::{self, Work};
use crate::{RenderDiagnostic, RenderOptions, render_html};
const DEPTH: usize = 64;
fn nested_lists(depth: usize) -> String {
format!(
"<!doctype html><body>{}Deepest{}",
"<ol><li>".repeat(depth),
"</li></ol>".repeat(depth)
)
}
fn rendering_work(kind: Work, depth: usize) -> usize {
let (output, units) = work::measured(kind, || {
render_html(&nested_lists(depth), &RenderOptions::default())
.unwrap_or_else(|error| panic!("lists nested {depth} deep must render: {error}"))
});
let limits: Vec<_> = output
.diagnostics
.iter()
.filter(|diagnostic| matches!(diagnostic, RenderDiagnostic::FormattingLimit { .. }))
.collect();
assert!(
limits.is_empty(),
"lists nested {depth} deep fit every formatting limit: {limits:?}"
);
units
}
#[test]
fn counters_of_nested_lists_take_work_linear_in_their_depth() {
work::assert_linear("counters of nested lists", DEPTH, |depth| {
rendering_work(Work::CounterStep, depth)
});
}
#[test]
fn formatting_finds_scroll_containers_and_block_children_without_walking_open_boxes() {
work::assert_linear("formatting frames of nested lists", DEPTH, |depth| {
rendering_work(Work::OpenFrame, depth)
});
}
#[test]
fn style_evaluation_finds_dependency_cycles_without_walking_open_nodes() {
work::assert_linear("evaluation nodes of nested lists", DEPTH, |depth| {
rendering_work(Work::ActiveNode, depth)
});
}