Skip to content

Commit 90261f9

Browse files
committed
add invalid syntax tests
1 parent 14cd96e commit 90261f9

File tree

3 files changed

+34
-22
lines changed

3 files changed

+34
-22
lines changed

crates/quarto_markdown_pandoc/src/readers/qmd.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,9 @@ pub fn read<T: Write>(
6767
return Err(error_messages);
6868
}
6969

70+
// // repeat this 100 times to get profiling data
71+
// for _ in 0..100 {
72+
// let _ = pandoc::treesitter::treesitter_to_pandoc(&mut output_stream, &tree, &input_bytes);
73+
// }
7074
pandoc::treesitter_to_pandoc(&mut output_stream, &tree, &input_bytes)
7175
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Hello {=world}

crates/quarto_markdown_pandoc/tests/test.rs

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -321,42 +321,49 @@ fn test_json_writer() {
321321
);
322322
}
323323

324-
#[test]
325-
fn test_disallowed_in_qmd_fails() {
324+
fn ensure_file_does_not_parse(path: &std::path::Path) {
325+
let markdown = std::fs::read_to_string(path).expect("Failed to read file");
326+
let mut parser = MarkdownParser::default();
327+
let input_bytes = markdown.as_bytes();
328+
let tree = parser
329+
.parse(input_bytes, None)
330+
.expect("Failed to parse input");
331+
332+
let errors = parse_is_good(&tree);
333+
if errors.is_empty() {
334+
panic!(
335+
"File {} should not parse but it did: {:?}",
336+
path.display(),
337+
errors
338+
);
339+
}
340+
}
341+
342+
fn ensure_every_file_in_directory_does_not_parse(pattern: &str) {
326343
let mut file_count = 0;
327-
for entry in glob("tests/pandoc-differences/disallowed-in-qmd/*.qmd")
328-
.expect("Failed to read glob pattern")
329-
{
344+
for entry in glob(pattern).expect("Failed to read glob pattern") {
330345
match entry {
331346
Ok(path) => {
332347
eprintln!("Opening file: {}", path.display());
333-
let markdown = std::fs::read_to_string(&path).expect("Failed to read file");
334-
335-
// Parse with our parser
336-
let mut parser = MarkdownParser::default();
337-
let input_bytes = markdown.as_bytes();
338-
let tree = parser
339-
.parse(input_bytes, None)
340-
.expect("Failed to parse input");
341-
342-
let errors = parse_is_good(&tree);
343-
if errors.is_empty() {
344-
panic!(
345-
"File {} contains disallowed syntax but no parse errors were reported",
346-
path.display()
347-
);
348-
}
348+
ensure_file_does_not_parse(&path);
349349
file_count += 1;
350350
}
351351
Err(e) => panic!("Error reading glob entry: {}", e),
352352
}
353353
}
354354
assert!(
355355
file_count > 0,
356-
"No files found in tests/pandoc-differences/disallowed-in-qmd directory"
356+
"No files found in directory matching pattern: {}",
357+
pattern
357358
);
358359
}
359360

361+
#[test]
362+
fn test_disallowed_in_qmd_fails() {
363+
ensure_every_file_in_directory_does_not_parse("tests/pandoc-differences/disallowed-in-qmd/*.qmd");
364+
ensure_every_file_in_directory_does_not_parse("tests/invalid-syntax/*.qmd");
365+
}
366+
360367
#[test]
361368
fn test_do_not_smoke() {
362369
let mut file_count = 0;

0 commit comments

Comments
 (0)