#![allow(clippy::expect_used, clippy::indexing_slicing, reason = "tests assert by panicking")]
use ratatui::style::{Color, Modifier};
use super::code::BAR;
use super::*;
use crate::highlight::Role;
#[test]
fn rendered_text_strips_markup_and_joins_blocks_without_separator() {
let doc = Document::parse("Ship the **login page**\nby Friday.\n\nNext para.\n".to_owned());
let layout = DocLayout::build(&doc, 80);
let whole = 0..doc.source.len();
assert_eq!(layout.rendered_in_range(&doc.source, &whole), "Ship the login page by Friday.Next para.");
let bold = doc.source.find("**login").expect("present");
let bold_range = bold..bold + "**login page**".len();
assert_eq!(layout.rendered_in_range(&doc.source, &bold_range), "login page");
}
#[test]
fn every_cell_of_a_long_table_maps_to_its_source() {
let doc = Document::parse(
"| Item | Status | Next step |\n|---|---|---|\n\
| A. Four changes from 3/7 (release checklist handoff, the 3/4 planning call, the 3/6 search demo, \
the 3/4-3/7 progress review and rollout advice) | Scope partly confirmed; never added to the \
draft | 1.0d design + 1.0d build + 1.0d review + 2.5d rollout = **5.5d** |\n\
| B. 3/14 cache troubleshooting and the `api.example.com` proxy | Owner and priority not set | Your call |\n\
| C. 3/19-20 export access in the admin panel (read and write) | Agreed at 1.0d, done once it's \
tested; it's live, but QA hasn't finished acceptance testing | Close it now, or wait for the next sprint |\n\
| D. 3/21 lookup and report tools in the CLI; 3/23 plugin consolidation | Marked \"not confirmed\" | Your call |\n"
.to_owned(),
);
let layout = DocLayout::build(&doc, 100);
let table = layout.blocks.iter().find(|b| b.kind == BlockKind::Table).expect("a table");
let mut cells = 0;
for row in &table.rows {
let text: String = row.line.spans.iter().map(|s| s.content.as_ref()).collect();
for (ch, offset) in text.chars().zip(&row.cells) {
if ch.is_alphanumeric() {
let source = offset.and_then(|o| doc.source.get(o..));
assert!(source.is_some_and(|s| s.starts_with(ch)), "{ch:?} is unmapped in {text:?}");
cells += 1;
}
}
}
assert!(cells > 300, "only {cells} cells checked");
}
fn rows(layout: &DocLayout, block: usize) -> Vec<String> {
layout.blocks[block].rows.iter().map(|r| r.line.to_string()).collect()
}
fn screen(layout: &DocLayout) -> Vec<String> {
(0..layout.total_rows).map(|r| layout.row(r).map_or(String::new(), |row| row.line.to_string())).collect()
}
#[test]
fn items_of_a_list_sit_row_after_row_and_keep_their_numbers() {
let doc = Document::parse_into("1. a\n1. b\n1. c\n\n- d\n\n- e\n".to_owned(), crate::doc::Blocks::SPLIT);
let layout = DocLayout::build(&doc, 40);
assert_eq!(layout.blocks.len(), 5);
assert_eq!(screen(&layout), ["1. a", "2. b", "3. c", "", "∙ d", "∙ e"]);
}
fn drawn(layout: &DocLayout) -> Vec<(Line<'static>, Vec<Option<usize>>)> {
(0..layout.total_rows)
.map(|r| match layout.row(r) {
Some(row) => (layout.drawn_line(r).expect("a row").into_owned(), row.cells.clone()),
None => (Line::default(), Vec::new()),
})
.collect()
}
#[test]
fn split_lists_and_definition_lists_draw_row_for_row_as_whole_ones() {
let documents = [
"Intro\n\n- a\n- b\n- c\n\nAfter\n",
"Intro\n\n- a\n\n- b\n\n- c\n\nAfter\n",
"- a first item long enough to wrap\n\n and its second paragraph\n- b\n\n- c\n",
"- a\n ```rs\n let x = 1;\n ```\n- b\n",
"- a\n\n ```\n x\n ```\n\n- b\n\nAfter\n",
"- a\n- b\n ```rust\n let n = 42;\n ```\n\nAfter\n",
"- a\n\n | x | y |\n |---|---|\n | 1 | 2 |\n- b\n",
"- a\n\n <div>block</div>\n\n- b\n",
"- a\n - a1\n - a11\n - a2\n- b\n 1. b1\n 2. b2\n",
"1. one\n1. two\n1. three\n\nText.\n\n9. nine\n10. ten\n11. eleven, wrapped at a narrow width\n",
"- [ ] open\n- [x] done\n - [ ] sub\n\n1. [x] first\n2. [ ] second\n",
"Intro\n\nTerm\n: def one\n\nTerm2\n: def two, long enough to wrap at a narrow width\n: another\n",
"> - a\n> - b\n>\n> para\n\n- after the quote\n- and more\n",
"- a\n > q\n > r\n\n- b\n",
"- a\n | x | y |\n |---|---|\n | 1 | 2 |\n\n- b\n",
"- a\n <div>block</div>\n\n- b\n",
"- a\n ```\n x\n ```\n\n- b\n",
"- a\n - n1\n - n2\n\n- b\n",
"- a\n > q\n > r\n- b\n",
"- a\n | x | y |\n |---|---|\n | 1 | 2 |\n- b\n",
"- a\n <div>block</div>\n- b\n",
"- a\n ```\n x\n ```\n- b\n",
"- a\n - n1\n - n2\n- b\n",
"- a\n > q\n- b\n\n second paragraph of b\n",
"- a\n\n- b\n > q\n",
"* a\n > q\n\n* b\n\nText.\n\n+ a\n > q\n\n+ b\n",
"1. a\n > q\n\n2. b\n\nText.\n\n3) a\n ```\n x\n ```\n\n4) b\n",
"1. a\n1. b\n > q\n\n1. c\n",
" - a\n > q\n\n - b\n > r\n",
"Term\n: a\n\nTerm2\n: b\n\nAfter\n",
];
for source in documents {
let split = Document::parse_into(source.to_owned(), crate::doc::Blocks::default());
let whole = Document::parse_into(source.to_owned(), crate::doc::Blocks::WHOLE);
assert!(split.blocks.len() > whole.blocks.len(), "{source:?} is not split");
for width in [40, 12] {
let (split, whole) = (DocLayout::build(&split, width), DocLayout::build(&whole, width));
assert_eq!(drawn(&split), drawn(&whole), "{source:?} at {width} columns");
}
}
}
#[test]
fn an_indented_loose_list_draws_its_items_whole_as_it_does_split() {
let source = " - a\n > q\n\n - b\n > r";
let item = source.find("- b").expect("b")..source.len();
let mut seen = Vec::new();
for blocks in [crate::doc::Blocks::WHOLE, crate::doc::Blocks::SPLIT] {
let doc = Document::parse_into(source.to_owned(), blocks);
let layout = DocLayout::build(&doc, 40);
let ranges: Vec<_> = doc.blocks.iter().map(|b| b.range.clone()).collect();
let text = layout.rendered_in_range(source, &item);
seen.push((screen(&layout), text, ranges));
}
let lines = |screen: &[String]| screen.iter().filter(|r| !r.is_empty()).cloned().collect::<Vec<_>>();
assert_eq!(lines(&seen[0].0), lines(&seen[1].0), "{seen:?}");
assert!(seen[0].0.contains(&"∙ b".to_owned()), "{seen:?}");
assert_eq!((seen[0].1.as_str(), seen[1].1.as_str()), ("b r", "b r"), "{seen:?}");
}
#[test]
fn tab_indented_and_empty_items_of_a_loose_list_draw_their_bullets() {
for (source, bullets) in [
("- x\n\n\t- a\n\n\t- b", &["∙ x", "◦ a", "◦ b"][..]),
(" -\n\n - b\n\n -\n", &["∙", "∙ b", "∙"][..]),
] {
for blocks in [crate::doc::Blocks::WHOLE, crate::doc::Blocks::SPLIT] {
let doc = Document::parse_into(source.to_owned(), blocks);
let drawn = screen(&DocLayout::build(&doc, 40));
let rows: Vec<_> = drawn.iter().map(|r| r.trim()).filter(|r| !r.is_empty()).collect();
assert_eq!(rows, bullets, "{source:?} cut {blocks:?}: {drawn:?}");
}
}
}
#[test]
fn a_link_defined_at_the_end_of_a_definition_draws_as_a_link() {
let source = "Term\n: see [x][r]\n\n [r]: http://x\n\nAfter";
for blocks in [crate::doc::Blocks::WHOLE, crate::doc::Blocks::SPLIT] {
let doc = Document::parse_into(source.to_owned(), blocks);
let layout = DocLayout::build(&doc, 40);
let text = layout.rendered_in_range(source, &(0..source.len()));
assert!(text.starts_with("Term see x ") && !text.contains('['), "{blocks:?}: {text:?}");
}
}
#[test]
fn blocks_never_overlap_and_each_draws_only_its_own_source() {
let documents = [
"Term\n: a\n\nTerm2\n: b\n\nAfter",
"Term\n: a\n\nAfter\n",
"A\n: a\nB\n: b\n\nAfter\n\nMore\n",
"Term\n: see [x][r]\n\n [r]: http://x\n\nAfter",
"Term\n:\n\nAfter",
"Term\n: a\n\n >\n\nAfter",
"Term\n: a\n\n - b\n -\n\nAfter",
"- x\n\n\t- a\n\n\t- b",
" -\n\n - b\n\n -\n",
"Intro\n\nTerm\n: one\n: two\n\nOther\n: three\n\n> q\n",
" - a\n > q\n\n - b\n > r",
"Intro\n\n- a\n- b\n- c\n\nAfter\n",
"- a\n\n ```\n x\n ```\n\n- b\n\nAfter\n",
"> - a\n> - b\n>\n> para\n\n- after the quote\n- and more\n",
"1. a\n > q\n\n2. b\n\nText.\n\n3) a\n ```\n x\n ```\n\n4) b\n",
"# Title\n\nText.\n\n## Section\n\n---\n\n### Sub\n",
TABLE,
NESTED,
RUST,
];
for source in documents {
for blocks in [crate::doc::Blocks::WHOLE, crate::doc::Blocks::SPLIT] {
let doc = Document::parse_into(source.to_owned(), blocks);
let ranges: Vec<_> = doc.blocks.iter().map(|b| b.range.clone()).collect();
let ordered = ranges.windows(2).all(|pair| pair[0].end <= pair[1].start);
assert!(ordered, "{source:?} cut {blocks:?}: {ranges:?}");
let layout = DocLayout::build(&doc, 30);
assert_eq!(layout.blocks.len(), doc.blocks.len(), "{source:?}");
for (range, drawn) in ranges.iter().zip(&layout.blocks) {
let cells = drawn.rows.iter().flat_map(|row| row.cells.iter().flatten());
let outside: Vec<_> = cells.filter(|o| !range.contains(o)).collect();
assert!(outside.is_empty(), "{source:?} cut {blocks:?}: {range:?} draws {outside:?}");
}
}
}
}
const TABLE: &str = "Before.\n\n| Item | Status of the work |\n|---|---|\n| a | done and shipped |\n\
| | |\n| b long name | waiting on review from the team |\n\nAfter.\n";
fn table_rows() -> crate::doc::Blocks {
crate::doc::Blocks { tables: crate::doc::Cut::Split, ..crate::doc::Blocks::default() }
}
#[test]
fn a_table_cut_into_rows_draws_as_it_does_whole() {
let split = Document::parse_into(TABLE.to_owned(), table_rows());
let whole = Document::parse_into(TABLE.to_owned(), crate::doc::Blocks::default());
assert_eq!(split.blocks.len(), 6);
let mut reflowed = DocLayout::build(&split, 80);
for width in [80, 30, 20, 8] {
let (cut, one) = (DocLayout::build(&split, width), DocLayout::build(&whole, width));
assert_eq!(drawn(&cut), drawn(&one), "at {width}");
reflowed.reflow(width);
assert_eq!(drawn(&reflowed), drawn(&one), "reflowed to {width}");
let all = 0..TABLE.len();
assert_eq!(cut.rendered_in_range(&split.source, &all), one.rendered_in_range(&whole.source, &all));
}
let layout = DocLayout::build(&split, 30);
let header = rows(&layout, 1);
assert!(header.first().is_some_and(|r| r.starts_with('┌')), "{header:?}");
assert!(header.last().is_some_and(|r| r.starts_with('├')), "{header:?}");
let last = rows(&layout, 4);
assert!(last.last().is_some_and(|r| r.starts_with('└')), "{last:?}");
let wide = DocLayout::build(&split, 80);
assert_eq!(rows(&wide, 3).len(), 1, "a row of empty cells still has its row");
}
#[test]
fn odd_tables_cut_into_rows_draw_as_they_do_whole() {
for source in [
"| a | b |\n|---|---|\n| x | y |\n| c | |\n",
"| a | b | c |\n|---|---|---|\n| x |\n| 1 | 2 | 3 | 4 |\n",
"| a | b |\n|---|---|\n| `x \\| y` | 漢字の長いセル |\nno | pipes\n",
"a | b\n---|---\nx | y\nz | w\n",
] {
let split = Document::parse_into(source.to_owned(), table_rows());
let whole = Document::parse_into(source.to_owned(), crate::doc::Blocks::default());
assert!(split.blocks.len() > 1, "{source:?}");
for width in 8..=40 {
let (cut, one) = (DocLayout::build(&split, width), DocLayout::build(&whole, width));
assert_eq!(drawn(&cut), drawn(&one), "{source:?} at {width}");
}
}
}
#[test]
fn a_long_table_cut_into_rows_lays_out_as_one_across_the_first_screens() {
let mut source = "| n | word |\n|---|---|\n".to_owned();
for n in 0..FIRST_ROWS + 100 {
source.push_str(&["| ", &n.to_string(), " | ", &"w".repeat(n % 7 + 1), " |\n"].concat());
}
let split = Document::parse_into(source.clone(), table_rows());
let mut started = DocLayout::start(&split, 12);
started.finish();
assert_eq!(started.blocks.len(), FIRST_ROWS + 101);
let whole = DocLayout::build(&Document::parse_into(source, crate::doc::Blocks::default()), 12);
assert_eq!(drawn(&started), drawn(&whole));
}
const RUST: &str = "Intro.\n\n```rust\nfn main() {\n let n = 42; // answer\n}\n```\n\nAfter.\n";
#[test]
fn a_code_block_drops_its_fences_and_draws_a_bar_and_its_language() {
let doc = Document::parse(RUST.to_owned());
let layout = DocLayout::build(&doc, 40);
assert_eq!(
rows(&layout, 1),
[
format!("{BAR} fn main() {{{}rust", " ".repeat(40 - 2 - 11 - 4)),
format!("{BAR} let n = 42; // answer"),
format!("{BAR} }}"),
]
);
for row in &layout.blocks[1].rows {
assert_eq!(row.cells[..2], [None, None]);
let text: String = row.line.to_string();
for (ch, cell) in text.chars().zip(&row.cells).skip(2) {
if let Some(offset) = cell {
assert!(doc.source[*offset..].starts_with(ch), "{ch:?} in {text:?}");
}
}
}
let label = layout.blocks[1].rows[0].cells.iter().rev().take(4);
assert!(label.into_iter().all(Option::is_none));
}
#[test]
fn the_text_under_a_whole_code_block_is_its_code_not_its_fences() {
let doc = Document::parse(RUST.to_owned());
let layout = DocLayout::build(&doc, 40);
let block = doc.blocks[1].range.clone();
let code = "fn main() {\n let n = 42; // answer\n}";
assert_eq!(layout.rendered_in_range(&doc.source, &block), code);
let cells = layout.blocks[1].rows.iter().flat_map(|r| r.cells.iter().flatten());
let (lo, hi) = cells.fold((usize::MAX, 0), |(lo, hi), &o| (lo.min(o), hi.max(o)));
assert_eq!(&doc.source[lo..=hi], code);
}
#[test]
fn a_known_language_is_coloured_only_when_drawn_and_names_keep_the_terminal_colour() {
let doc = Document::parse(RUST.to_owned());
let layout = DocLayout::build(&doc, 40);
let first = layout.blocks[1].first_row;
let colour = |row: usize, text: &str| {
let line = layout.drawn_line(row).expect("a row");
line.spans.iter().find(|s| s.content.contains(text)).map(|s| s.style.patch(Style::default()))
};
assert_eq!(colour(first, "fn").and_then(|s| s.fg), Role::Keyword.style().fg);
assert_eq!(colour(first, "main").and_then(|s| s.fg), Role::Function.style().fg);
assert_eq!(colour(first + 1, "42").and_then(|s| s.fg), Role::Number.style().fg);
let comment = colour(first + 1, "answer").expect("comment");
assert_eq!(comment.fg, Role::Comment.style().fg);
assert!(comment.add_modifier.contains(Modifier::ITALIC));
assert_eq!(colour(first + 1, "n").and_then(|s| s.fg), Some(Color::Reset));
assert_eq!(colour(first, &BAR.to_string()).and_then(|s| s.fg), Some(palette().code_comment));
assert!(layout.blocks[1].rows[0].line.spans.iter().all(|s| s.style.fg != Role::Keyword.style().fg));
}
#[test]
fn an_unknown_language_keeps_the_one_code_colour_and_its_label() {
let doc = Document::parse("```klingon\nqapla' batlh\n```\n".to_owned());
let layout = DocLayout::build(&doc, 40);
assert_eq!(rows(&layout, 0), [format!("{BAR} qapla' batlh{}klingon", " ".repeat(40 - 2 - 12 - 7))]);
let line = layout.drawn_line(0).expect("a row");
assert_eq!(*line, layout.blocks[0].rows[0].line, "drawn as laid out");
assert_eq!(line.style.fg, Some(palette().code));
}
#[test]
fn a_narrow_column_drops_the_label_and_wraps_long_code_beside_the_bar() {
let doc = Document::parse(RUST.to_owned());
let layout = DocLayout::build(&doc, 14);
assert_eq!(
rows(&layout, 1),
[
format!("{BAR} fn main() {{"),
format!("{BAR} let n ="),
format!("{BAR} 42; // answe"),
format!("{BAR} r"),
format!("{BAR} }}"),
]
);
assert!(layout.blocks.iter().flat_map(|b| &b.rows).all(|r| r.cells.len() <= 14));
let block = doc.blocks[1].range.clone();
assert_eq!(layout.rendered_in_range(&doc.source, &block), "fn main() {\n let n = 42; // answer\n}");
let first = layout.blocks[1].first_row;
let line = layout.drawn_line(first + 2).expect("a row");
let number = line.spans.iter().find(|s| s.content.contains("42")).expect("42");
assert_eq!(number.style.fg, Role::Number.style().fg);
}
#[test]
fn a_title_has_a_rule_under_it_and_sections_get_room_above() {
let doc = Document::parse("# Title\n\nText.\n\n## Section\n\n### Sub\n".to_owned());
let layout = DocLayout::build(&doc, 20);
assert_eq!(rows(&layout, 0), ["Title".to_owned(), TITLE_RULE.to_string().repeat(20)]);
assert_eq!(layout.blocks[0].rows[1].cells, vec![None; 20], "the rule has no source");
let starts: Vec<usize> = layout.blocks.iter().map(|b| b.first_row).collect();
assert_eq!(starts, [0, 3, 6, 8]);
let row = &layout.blocks[0].rows[0].line;
let title = row.style.patch(row.spans[0].style);
assert!(title.add_modifier.contains(Modifier::BOLD) && title.fg == Some(palette().heading));
}
#[test]
fn a_definition_list_indents_its_definitions_under_their_terms() {
for blocks in [crate::doc::Blocks::default(), crate::doc::Blocks::WHOLE] {
let doc = Document::parse_into(
"Term\n: A definition long enough to wrap onto a second row.\n\nOther\n: Short.\n".to_owned(),
blocks,
);
assert_eq!(doc.blocks[0].kind, BlockKind::DefinitionList);
let layout = DocLayout::build(&doc, 30);
assert_eq!(
screen(&layout),
["Term", " A definition long enough", " to wrap onto a second row.", "Other", " Short."]
);
for row in 1..3 {
assert_eq!(layout.row(row).expect("a row").cells[..4], [None; 4], "the indent has no source");
}
let whole = 0..doc.source.len();
assert_eq!(
layout.rendered_in_range(&doc.source, &whole),
"Term A definition long enough to wrap onto a second row. Other Short."
);
let term = &layout.row(0).expect("the term").line;
assert!(term.spans.iter().all(|s| term.style.patch(s.style).add_modifier.contains(Modifier::BOLD)));
}
}
#[test]
fn the_bar_and_the_title_rule_are_one_column_wide_even_in_cjk_terminals() {
use unicode_width::UnicodeWidthChar as _;
for glyph in [BAR, TITLE_RULE] {
assert_eq!(glyph.width_cjk(), Some(1), "{glyph:?}");
}
}
fn all_rows(layout: &DocLayout) -> Vec<(usize, String, Vec<Option<usize>>)> {
layout
.blocks
.iter()
.flat_map(|b| b.rows.iter().map(|r| (b.first_row, r.line.to_string(), r.cells.clone())))
.collect()
}
#[test]
fn a_long_document_lays_out_its_first_screens_first_and_the_rest_matches_a_full_build() {
let section = "# Part\n\n## Step\n\nSome **bold** words that wrap at a narrow width, and more.\n\n\
- one\n- two\n\n| a | b |\n|---|---|\n| x | y |\n\n```\ncode\n```\n\n```rust\nlet n = 42;\n```\n\n\
Term\n: Its definition.\n\n---\n\n";
let doc = Document::parse(section.repeat(400));
let mut lazy = DocLayout::start(&doc, 70);
assert!(!lazy.is_complete());
assert!(lazy.blocks.len() < doc.blocks.len() / 10, "laid out {} blocks up front", lazy.blocks.len());
assert!(lazy.total_rows >= FIRST_ROWS);
lazy.reflow(50);
lazy.finish();
assert!(lazy.is_complete());
let full = DocLayout::build(&doc, 50);
assert_eq!(lazy.blocks.len(), doc.blocks.len());
assert_eq!(lazy.total_rows, full.total_rows);
assert!(all_rows(&lazy) == all_rows(&full), "rows differ from a full build");
}
#[test]
fn polling_reports_the_background_blocks_once() {
let doc = Document::parse("## Step\n\nSome words.\n\n".repeat(2000));
let mut lazy = DocLayout::start(&doc, 70);
let started = std::time::Instant::now();
while !lazy.poll() {
assert!(started.elapsed() < std::time::Duration::from_secs(20), "the layout never finished");
std::thread::sleep(std::time::Duration::from_millis(5));
}
assert!(lazy.is_complete());
assert_eq!(lazy.blocks.len(), doc.blocks.len());
assert!(!lazy.poll());
}
#[test]
fn code_laid_out_in_the_background_is_coloured_when_drawn() {
let section =
"Some words before the code, enough to make a long document.\n\n```rust\nlet n = 42;\n```\n\n";
let doc = Document::parse(section.repeat(1000));
let mut layout = DocLayout::start(&doc, 60);
let first = layout.blocks.len();
layout.finish();
let last = layout.blocks.len() - 1;
assert!(last > first, "the last block came from the background");
let row = layout.blocks[last].first_row;
let line = layout.drawn_line(row).expect("the code row");
let keyword = line.spans.iter().find(|span| span.content == "let").expect("let is a span of its own");
assert_eq!(keyword.style.fg, Role::Keyword.style().fg);
}
const NESTED: &str = "- Step one:\n\n ```rust\n let n = 42; // answer\n ```\n- Step two\n\n\
> Quoted:\n>\n> ```klingon\n> qapla' batlh\n> ```\n";
#[test]
fn code_inside_a_list_or_quote_gets_the_bar_and_colours_without_fences() {
for blocks in [crate::doc::Blocks::default(), crate::doc::Blocks::WHOLE] {
let doc = Document::parse_into(NESTED.to_owned(), blocks);
let layout = DocLayout::build(&doc, 40);
assert_eq!(
screen(&layout),
[
"∙ Step one:".to_owned(),
String::new(),
format!(" {BAR} let n = 42; // answer"),
String::new(),
"∙ Step two".to_owned(),
String::new(),
"╎ Quoted:".to_owned(),
"╎".to_owned(),
format!("╎ {BAR} qapla' batlh"),
]
);
let code_row = 2;
let line = layout.drawn_line(code_row).expect("the code row");
let style_of = |text: &str| line.spans.iter().find(|s| s.content.contains(text)).map(|s| s.style.fg);
assert_eq!(style_of("let"), Some(Role::Keyword.style().fg));
assert_eq!(style_of("42"), Some(Role::Number.style().fg));
assert_eq!(style_of(&BAR.to_string()), Some(Some(palette().code_comment)));
let bullet = layout.drawn_line(0).expect("bullet row");
assert_eq!(bullet.as_ref(), &layout.row(0).expect("bullet row").line);
let quote_row = 8;
assert_eq!(
layout.drawn_line(quote_row).expect("quote row").as_ref(),
&layout.row(quote_row).expect("row").line
);
let start = doc.source.find("let n").expect("code");
let end = doc.source.find("answer").expect("comment") + "answer".len();
assert_eq!(layout.rendered_in_range(&doc.source, &(start..end)), "let n = 42; // answer");
let row = layout.row(code_row).expect("the code row");
let first = row.cells.iter().flatten().next().copied();
assert_eq!(first, Some(start), "the bar maps to nothing, the code to its bytes");
}
}