|
| 1 | +# Grammar Changes Checklist |
| 2 | + |
| 3 | +This document provides guidelines for making changes to Quarto Markdown syntax. |
| 4 | + |
| 5 | +## 🚨 CRITICAL QUESTION |
| 6 | + |
| 7 | +Before making any grammar change, ask yourself: |
| 8 | + |
| 9 | +**"What existing valid QMD documents might this change break?"** |
| 10 | + |
| 11 | +If you can't confidently answer "none", you need to: |
| 12 | +1. Create test cases for those documents |
| 13 | +2. Run the parser on them before and after your change |
| 14 | +3. Verify they still parse correctly |
| 15 | + |
| 16 | +## When to Use This Checklist |
| 17 | + |
| 18 | +Use this checklist whenever you're adding new syntax to Quarto Markdown, either by tree-sitter changes or changes in the Pandoc AST |
| 19 | +processing steps. |
| 20 | + |
| 21 | +## Pre-Implementation Phase |
| 22 | + |
| 23 | +### 1. Plan Your Test Cases |
| 24 | + |
| 25 | +Before writing any code, plan tests for: |
| 26 | + |
| 27 | +#### Positive Cases (Feature Works) |
| 28 | +- [ ] Basic valid example |
| 29 | +- [ ] Valid example with edge cases (empty, very long, special characters, etc.) |
| 30 | +- [ ] Valid example in different contexts (nested, at start/end of document, etc.) |
| 31 | + |
| 32 | +#### Negative Cases (Similar But Different) |
| 33 | +- [ ] Syntax that looks similar but shouldn't be treated as this feature |
| 34 | +- [ ] Old/deprecated syntax that should be handled differently |
| 35 | + |
| 36 | +#### Edge Cases (Feature in Unexpected Contexts) |
| 37 | +- [ ] Feature appears where it's not expected (e.g., caption without preceding table) |
| 38 | +- [ ] Feature appears between other constructs |
| 39 | +- [ ] Feature appears at document boundaries |
| 40 | +- [ ] Feature appears nested in other constructs |
| 41 | + |
| 42 | +#### Compatibility Cases (Doesn't Break Existing Valid Syntax) |
| 43 | +- [ ] **CRITICAL:** Documents that look like they might conflict with new syntax |
| 44 | +- [ ] Documents with similar punctuation patterns |
| 45 | +- [ ] Documents with similar structure patterns |
| 46 | + |
| 47 | +#### Roundtrip Cases |
| 48 | +- [ ] At least one roundtrip test: QMD → JSON → QMD → JSON |
| 49 | +- [ ] Verify the feature survives roundtripping intact |
| 50 | + |
| 51 | +### 2. Write and Run Failing Tests FIRST |
| 52 | +- [ ] Write test cases in appropriate test directories |
| 53 | +- [ ] Run tests and verify they fail in the expected way |
| 54 | +- [ ] If tests don't fail as expected, revise your understanding |
| 55 | + |
| 56 | +## Implementation Phase |
| 57 | + |
| 58 | +Use your best judgment to implement changes, studying the source code and similar features. |
| 59 | +Ask clarification questions when you conclude that you don't know enough to go on. |
| 60 | + |
| 61 | +### 3. Update Writers If Needed |
| 62 | + |
| 63 | +- [ ] QMD writer (`src/writers/qmd.rs`) - for roundtripping |
| 64 | +- [ ] JSON writer (`src/writers/json.rs`) - if adding new node types |
| 65 | +- [ ] Native writer (`src/writers/native.rs`) - usually auto-handled |
| 66 | +- [ ] Look in the writers/ directory to find others |
| 67 | + |
| 68 | +## Testing Phase |
| 69 | + |
| 70 | +### 4. Run All Tests |
| 71 | + |
| 72 | +- [ ] `cargo check` - verify code compiles |
| 73 | +- [ ] `cargo test` - verify all tests pass |
| 74 | +- [ ] **ALL tests must pass** - don't ignore failures even if they seem unrelated |
| 75 | + |
| 76 | +If you can't write the feature so that your tests pass, do not erase the tests. |
| 77 | +Stop and report them to the user. |
| 78 | + |
| 79 | +### 9. Verify Test Coverage |
| 80 | + |
| 81 | +- [ ] All planned test cases are implemented |
| 82 | +- [ ] Tests are in the appropriate directories: |
| 83 | + - `tests/snapshots/native/` - for native format output tests |
| 84 | + - `tests/roundtrip_tests/qmd-json-qmd/` - for roundtrip tests |
| 85 | + - `tests/pandoc-match-corpus/markdown/` - for Pandoc compatibility tests |
| 86 | + - `tests/smoke/` - for basic smoke tests |
| 87 | + |
| 88 | +### 10. Manual Testing |
| 89 | + |
| 90 | +- [ ] Test with `-v` flag to see tree-sitter output |
| 91 | +- [ ] Test edge cases interactively |
| 92 | +- [ ] If something unexpected happens, add a test for it |
| 93 | + |
| 94 | +## Quick Reference: Test File Locations |
| 95 | + |
| 96 | +- **Snapshot tests (native format):** `tests/snapshots/native/*.qmd` + `.qmd.snapshot` |
| 97 | +- **Snapshot tests (JSON format):** `tests/snapshots/json/*.qmd` + `.qmd.snapshot` |
| 98 | +- **Snapshot tests (QMD format):** `tests/snapshots/qmd/*.qmd` + `.qmd.snapshot` |
| 99 | +- **Roundtrip tests:** `tests/roundtrip_tests/qmd-json-qmd/*.qmd` |
| 100 | +- **Pandoc compatibility:** `tests/pandoc-match-corpus/markdown/*.qmd` |
| 101 | +- **Smoke tests:** `tests/smoke/*.qmd` |
| 102 | + |
| 103 | +## Remember |
| 104 | + |
| 105 | +The goal is not just to make the feature work, but to make it work **without breaking anything else**. |
| 106 | + |
| 107 | +When in doubt, ask the user for guidance, especially about: |
| 108 | +- Whether there are existing QMD documents to test against |
| 109 | +- How edge cases should be handled |
| 110 | +- Whether a grammar-based or postprocessing-based approach is preferred |
0 commit comments