|
| 1 | +use quarto_markdown_pandoc::readers; |
| 2 | +use quarto_markdown_pandoc::utils; |
| 3 | + |
| 4 | +#[test] |
| 5 | +fn test_caption_without_table_warning() { |
| 6 | + // Create input with a caption after a div (not a table) |
| 7 | + // This should parse successfully but emit a warning |
| 8 | + let input = r#"::: {.my-div} |
| 9 | +Some content |
| 10 | +::: |
| 11 | +
|
| 12 | +: This caption has no table |
| 13 | +"#; |
| 14 | + |
| 15 | + // Parse the document |
| 16 | + let result = readers::qmd::read( |
| 17 | + input.as_bytes(), |
| 18 | + false, |
| 19 | + "test.md", |
| 20 | + &mut std::io::sink(), |
| 21 | + None::< |
| 22 | + fn(&[u8], &utils::tree_sitter_log_observer::TreeSitterLogObserver, &str) -> Vec<String>, |
| 23 | + >, |
| 24 | + ); |
| 25 | + |
| 26 | + // Parsing should succeed (warnings are not errors) |
| 27 | + assert!(result.is_ok(), "Document should parse successfully despite warning"); |
| 28 | + |
| 29 | + // TODO: Once the fix is implemented, we need to verify that the warning |
| 30 | + // "Caption found without a preceding table" was actually output. |
| 31 | + // For now, this test just verifies that parsing succeeds. |
| 32 | + // After the fix, we'll need to capture stderr or modify the API |
| 33 | + // to return warnings alongside the successful parse result. |
| 34 | +} |
| 35 | + |
| 36 | +#[test] |
| 37 | +fn test_caption_with_table_no_warning() { |
| 38 | + // Create input with a proper table caption |
| 39 | + // This should parse successfully with no warnings |
| 40 | + let input = r#"| A | B | |
| 41 | +|---|---| |
| 42 | +| 1 | 2 | |
| 43 | +
|
| 44 | +: Table caption |
| 45 | +"#; |
| 46 | + |
| 47 | + // Parse the document |
| 48 | + let result = readers::qmd::read( |
| 49 | + input.as_bytes(), |
| 50 | + false, |
| 51 | + "test.md", |
| 52 | + &mut std::io::sink(), |
| 53 | + None::< |
| 54 | + fn(&[u8], &utils::tree_sitter_log_observer::TreeSitterLogObserver, &str) -> Vec<String>, |
| 55 | + >, |
| 56 | + ); |
| 57 | + |
| 58 | + // Parsing should succeed and no warnings should be emitted |
| 59 | + assert!(result.is_ok(), "Document with valid table caption should parse successfully"); |
| 60 | + |
| 61 | + let (pandoc, _context) = result.unwrap(); |
| 62 | + |
| 63 | + // Verify we have a table in the output |
| 64 | + assert!( |
| 65 | + pandoc.blocks.iter().any(|b| matches!(b, quarto_markdown_pandoc::pandoc::Block::Table(_))), |
| 66 | + "Should have a table in the output" |
| 67 | + ); |
| 68 | +} |
0 commit comments