Skip to content

core: Add compile-only doc tests - #304

Closed
T1mVo wants to merge 3 commits into
typst-community:mainfrom
T1mVo:docs
Closed

T1mVo wants to merge 3 commits into
typst-community:mainfrom
T1mVo:docs

Conversation

@T1mVo

@T1mVo T1mVo commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

See commit messages.

Related Issues

Checklist

  • I have structured my commits according to the commit guidelines (if applicable).
  • I have added tests for new features (if applicable).
  • I have updated the documentation (if applicable).

T1mVo added 3 commits July 23, 2026 11:48
Add documentation test support:
- DocTest struct with parse() using typst-syntax LinkedNode AST
- ID format path:function:number for doc test identification
- Doc(DocTest) variant on Test enum with match arms everywhere
- DocTestsConfig in ProjectConfig (enabled + sources)
- Suite::collect_doc_tests() for discovery from .typ source files
- DocTestRunner in runner.rs (compile-only, no comparison)
- doc()/doc-tests() filter builtin, skip() updated for doc tests
- JSON serialization, list display, and diagnostics reporting
The typst-syntax tree stores /// comments as trivia which are skipped by
prev_sibling(). Switch to scanning source text backwards from the LetBinding
node offset, stripping the leading # character. Also fix function detection
to look for Closure children (not Ident+Params) which is how #let f(x)=...
is parsed in typst-syntax.
…ollection

Replace raw source text scanning with typst-ide-style sibling walking
via LinkedNode::prev_sibling_with_trivia(), matching the approach used
by typst-ide's internal Docs::collect_doc_comment(). Uses ast::LineComment
casting for proper /// detection.
@T1mVo T1mVo changed the title Docs core: Add compile-only doc tests Jul 24, 2026
@T1mVo

T1mVo commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

@tingerrr I'm just experimenting with how to implement doctests for Tytanic. Depending on how this turns out, this PR might be worth merging, but I wouldn't mind if it isn't.

I noticed you're doing a fairly substantial refactor of the tests in #293. Does it make more sense for me to base this work on that branch, or should I wait until it's merged?

@tingerrr

Copy link
Copy Markdown
Member

I'm on phone right now so it's not easy to see.

Did I already merge the empty doc test parts, i.e. just the identifier parsing and data types? If yes you should be able to base off of those, other wise I'd wait until those are merged and then base it off of those.

But you can also explore the implementation here. What I left out in the changes to the internals was collection and evaluation.

Collection is complicated because I don't think there's a clear cut answer to what is a doc test. Some prior work in this space would be tidy.

Evaluation is the hardest part as it's unclear what should be available for a doc test to execute.

I haven't done much research what packages do for either of this, I wanted to build a tool to more easily search across the whole universe, but that work stalled.

@tingerrr

Copy link
Copy Markdown
Member

Did you come to any conclusions here? I'm updating my work right now, and I'm wondering if there is work I can adopt.

@tingerrr

Copy link
Copy Markdown
Member

I'll take this as a no, feel free to re-open this if you get around to working on it again.

@tingerrr tingerrr closed this Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants