p1-3: snapshot tests + clippy fix
Adds two snapshot tests (`nested-headings.md`, `code-and-table.md`) under crates/kb-parse-md/tests/blocks_snapshots.rs, with matching baseline JSON next to each fixture. The snapshot view projects `kb_core::Inline` to flat strings — `Inline` carries `serde(tag = "kind")` which is incompatible with newtype variants holding a primitive (`Text(String)`), so direct serialization of `ParsedBlock` would fail today. The view preserves the contract that matters for P1-3 (heading paths, source spans, payload kinds, payload text/code/table content) and will keep working once kb-core fixes the Inline schema in a later task. Also tightens `level_to_use >= 1 && <= 6` into `(1..=6).contains(&_)` to satisfy `clippy::manual_range_contains`.
This commit is contained in:
63
fixtures/markdown/code-and-table.blocks.snapshot.json
Normal file
63
fixtures/markdown/code-and-table.blocks.snapshot.json
Normal file
@@ -0,0 +1,63 @@
|
||||
{
|
||||
"blocks": [
|
||||
{
|
||||
"kind": "heading",
|
||||
"heading_path": [],
|
||||
"source_span": {
|
||||
"kind": "line",
|
||||
"start": 1,
|
||||
"end": 1
|
||||
},
|
||||
"payload": {
|
||||
"kind": "heading",
|
||||
"level": 1,
|
||||
"text": "Code And Table"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "code",
|
||||
"heading_path": [
|
||||
"Code And Table"
|
||||
],
|
||||
"source_span": {
|
||||
"kind": "line",
|
||||
"start": 3,
|
||||
"end": 7
|
||||
},
|
||||
"payload": {
|
||||
"kind": "code",
|
||||
"lang": "rust",
|
||||
"code": "fn main() {\n println!(\"hi\");\n}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "table",
|
||||
"heading_path": [
|
||||
"Code And Table"
|
||||
],
|
||||
"source_span": {
|
||||
"kind": "line",
|
||||
"start": 9,
|
||||
"end": 12
|
||||
},
|
||||
"payload": {
|
||||
"kind": "table",
|
||||
"headers": [
|
||||
"col a",
|
||||
"col b"
|
||||
],
|
||||
"rows": [
|
||||
[
|
||||
"1",
|
||||
"2"
|
||||
],
|
||||
[
|
||||
"3",
|
||||
"4"
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"warnings": []
|
||||
}
|
||||
136
fixtures/markdown/nested-headings.blocks.snapshot.json
Normal file
136
fixtures/markdown/nested-headings.blocks.snapshot.json
Normal file
@@ -0,0 +1,136 @@
|
||||
{
|
||||
"blocks": [
|
||||
{
|
||||
"kind": "heading",
|
||||
"heading_path": [],
|
||||
"source_span": {
|
||||
"kind": "line",
|
||||
"start": 1,
|
||||
"end": 1
|
||||
},
|
||||
"payload": {
|
||||
"kind": "heading",
|
||||
"level": 1,
|
||||
"text": "Top"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "paragraph",
|
||||
"heading_path": [
|
||||
"Top"
|
||||
],
|
||||
"source_span": {
|
||||
"kind": "line",
|
||||
"start": 3,
|
||||
"end": 3
|
||||
},
|
||||
"payload": {
|
||||
"kind": "paragraph",
|
||||
"text": "intro",
|
||||
"inlines_flat": "intro"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "heading",
|
||||
"heading_path": [
|
||||
"Top"
|
||||
],
|
||||
"source_span": {
|
||||
"kind": "line",
|
||||
"start": 5,
|
||||
"end": 5
|
||||
},
|
||||
"payload": {
|
||||
"kind": "heading",
|
||||
"level": 2,
|
||||
"text": "Section A"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "paragraph",
|
||||
"heading_path": [
|
||||
"Top",
|
||||
"Section A"
|
||||
],
|
||||
"source_span": {
|
||||
"kind": "line",
|
||||
"start": 7,
|
||||
"end": 7
|
||||
},
|
||||
"payload": {
|
||||
"kind": "paragraph",
|
||||
"text": "body of A",
|
||||
"inlines_flat": "body of A"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "heading",
|
||||
"heading_path": [
|
||||
"Top",
|
||||
"Section A"
|
||||
],
|
||||
"source_span": {
|
||||
"kind": "line",
|
||||
"start": 9,
|
||||
"end": 9
|
||||
},
|
||||
"payload": {
|
||||
"kind": "heading",
|
||||
"level": 3,
|
||||
"text": "Sub A.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "paragraph",
|
||||
"heading_path": [
|
||||
"Top",
|
||||
"Section A",
|
||||
"Sub A.1"
|
||||
],
|
||||
"source_span": {
|
||||
"kind": "line",
|
||||
"start": 11,
|
||||
"end": 11
|
||||
},
|
||||
"payload": {
|
||||
"kind": "paragraph",
|
||||
"text": "deeper",
|
||||
"inlines_flat": "deeper"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "heading",
|
||||
"heading_path": [
|
||||
"Top"
|
||||
],
|
||||
"source_span": {
|
||||
"kind": "line",
|
||||
"start": 13,
|
||||
"end": 13
|
||||
},
|
||||
"payload": {
|
||||
"kind": "heading",
|
||||
"level": 2,
|
||||
"text": "Section B"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "paragraph",
|
||||
"heading_path": [
|
||||
"Top",
|
||||
"Section B"
|
||||
],
|
||||
"source_span": {
|
||||
"kind": "line",
|
||||
"start": 15,
|
||||
"end": 15
|
||||
},
|
||||
"payload": {
|
||||
"kind": "paragraph",
|
||||
"text": "body of B",
|
||||
"inlines_flat": "body of B"
|
||||
}
|
||||
}
|
||||
],
|
||||
"warnings": []
|
||||
}
|
||||
Reference in New Issue
Block a user