chore: 收口 Batch C 证据与设计口径
This commit is contained in:
@@ -744,4 +744,72 @@ mod tests {
|
||||
assert_eq!(first["props"]["src"].as_str(), Some("assets/photo.jpg"));
|
||||
assert_eq!(first["props"]["alt"].as_str(), Some("示例图片"));
|
||||
}
|
||||
|
||||
/// 固定空引用块行为:`>` 在 GFM AST 中产生 BlockQuote 节点,
|
||||
/// collect_inline_children 返回空 vec → 输出 type=quote content=[]。
|
||||
#[test]
|
||||
fn markdown_empty_blockquote_parse() {
|
||||
let blocks = markdown_to_blocks("> \n\n>");
|
||||
let array = blocks.as_array().expect("blocks");
|
||||
assert!(!array.is_empty(), "应至少产生一个引用块");
|
||||
for block in array.iter() {
|
||||
if block["type"].as_str() == Some("quote") {
|
||||
let content = block["content"].as_array().expect("quote content");
|
||||
assert!(
|
||||
content.is_empty(),
|
||||
"空引用块 content 应为空,实际 {:?}",
|
||||
content
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 固定空表格单元格行为:comrak 解析空单元格为空的 tiptap paragraph,
|
||||
/// content 字段为 []。
|
||||
#[test]
|
||||
fn markdown_table_empty_cells_parse() {
|
||||
let blocks = markdown_to_blocks("| 左 | |\n| --- | --- |\n| | 右 |\n");
|
||||
let array = blocks.as_array().expect("blocks");
|
||||
let table = array
|
||||
.iter()
|
||||
.find(|b| b["type"].as_str() == Some("table"))
|
||||
.expect("should have table block");
|
||||
let tiptap_table = table["props"]["tiptapTable"]
|
||||
.as_object()
|
||||
.expect("tiptapTable object");
|
||||
let content_rows = tiptap_table["content"]
|
||||
.as_array()
|
||||
.expect("table content rows");
|
||||
// 表头行:两个单元格
|
||||
let header_row = &content_rows[0]["content"].as_array().expect("header row cells");
|
||||
assert_eq!(header_row.len(), 2);
|
||||
// 表头第一个单元格(非空)
|
||||
let h1_cell = &header_row[0]["content"].as_array().expect("header cell paragraphs");
|
||||
assert!(!h1_cell.is_empty(), "表头第一个单元格不应为空");
|
||||
// 表头第二个单元格(空):单元格的 content 为 [{type:"paragraph", content:[]}]
|
||||
// 段落层的 content 应为空数组
|
||||
let h2_par_content = &header_row[1]["content"][0]["content"];
|
||||
let h2_inline = h2_par_content.as_array().expect("header cell para content");
|
||||
assert!(
|
||||
h2_inline.is_empty(),
|
||||
"空表头单元格的 paragraph content 应为空,实际值: {}",
|
||||
serde_json::to_string_pretty(h2_par_content).unwrap()
|
||||
);
|
||||
|
||||
// 数据行
|
||||
let data_row = &content_rows[1]["content"].as_array().expect("data row cells");
|
||||
assert_eq!(data_row.len(), 2);
|
||||
// 数据行第一个单元格(空):段落层的 content 应为空数组
|
||||
let d1_par_content = &data_row[0]["content"][0]["content"];
|
||||
let d1_inline = d1_par_content.as_array().expect("data cell para content");
|
||||
assert!(
|
||||
d1_inline.is_empty(),
|
||||
"空数据单元格的 paragraph content 应为空,实际值: {}",
|
||||
serde_json::to_string_pretty(d1_par_content).unwrap()
|
||||
);
|
||||
// 数据行第二个单元格(非空):段落层的 content 不应为空
|
||||
let d2_par_content = &data_row[1]["content"][0]["content"];
|
||||
let d2_inline = d2_par_content.as_array().expect("data cell para content");
|
||||
assert!(!d2_inline.is_empty(), "非空数据单元格不应为空");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user