mirror of
https://github.com/openai/codex.git
synced 2026-11-09 20:50:33 +00:00
## What changed - Retain table identity, column alignments, cell coordinates, source byte ranges, and inline formatting in copy metadata. - Carry cell fragments through grid padding, wrapping, key/value layouts, and pipe output, including escaped pipes and empty cells. - Preserve logical source metadata when remapping wrapped lines, even without hyperlinks. ## Testing Add coverage for cell fragments across narrow and wide layouts, blank table continuations, and Markdown selection copy structure and visible transformations. GitOrigin-RevId: 8422f224cffe2e74813394f0623b9167bdd4ac59
69 lines
2.5 KiB
Rust
69 lines
2.5 KiB
Rust
//! Exercise retained cell coordinates, inline styles, and byte ranges through each layout.
|
|
|
|
use super::*;
|
|
use pretty_assertions::assert_eq;
|
|
use std::collections::BTreeMap;
|
|
|
|
#[test]
|
|
fn table_layouts_preserve_cell_fragments() {
|
|
for (markdown, expected) in [
|
|
(
|
|
"| **alpha head** | B |\n|---|---|\n| **one two three four** | `value` |\n| | last |",
|
|
BTreeMap::from([
|
|
((0, 0), "**alpha head**"),
|
|
((0, 1), "B"),
|
|
((1, 0), "**one two three four**"),
|
|
((1, 1), "`value`"),
|
|
((2, 0), ""),
|
|
((2, 1), "last"),
|
|
]),
|
|
),
|
|
(
|
|
"| **alpha head** | `a\\|b` |\n|---|---|",
|
|
BTreeMap::from([((0, 0), "**alpha head**"), ((0, 1), "`a|b`")]),
|
|
),
|
|
] {
|
|
for width in [4, 12, 80] {
|
|
let lines = crate::markdown_render::render_markdown_lines_with_width_and_cwd(
|
|
markdown,
|
|
Some(width),
|
|
/*cwd*/ None,
|
|
);
|
|
let mut seen = BTreeMap::new();
|
|
let mut identity = None;
|
|
for source in lines.into_iter().filter_map(|line| line.source) {
|
|
let Some(table) = source.copy.as_ref().and_then(|copy| copy.table.as_ref()) else {
|
|
continue;
|
|
};
|
|
let identity = identity.get_or_insert_with(|| Arc::clone(&table.table));
|
|
assert!(Arc::ptr_eq(identity, &table.table));
|
|
for fragment in &table.fragments {
|
|
let cell = &fragment.source;
|
|
assert_eq!(
|
|
&source.text[fragment.output.clone()],
|
|
&cell.text[cell.range.clone()],
|
|
"width {width}, cell ({}, {})",
|
|
fragment.row,
|
|
fragment.column,
|
|
);
|
|
let markdown = cell.copy.as_ref().unwrap().render(
|
|
&cell.text,
|
|
0..cell.text.len(),
|
|
/*depth*/ 0,
|
|
);
|
|
let key = (fragment.row, fragment.column);
|
|
assert_eq!(markdown, expected[&key]);
|
|
seen.insert(key, markdown);
|
|
}
|
|
}
|
|
assert_eq!(
|
|
seen,
|
|
expected
|
|
.iter()
|
|
.map(|(key, value)| (*key, value.to_string()))
|
|
.collect()
|
|
);
|
|
}
|
|
}
|
|
}
|