Typstyle Docs

Rust Development

This section covers building, testing, and benchmarking the Rust crates of typstyle.

Building Components

CLI and Core

cargo build                     # Debug build
cargo build --release           # Release build
cargo build -p typstyle         # CLI only
cargo build -p typstyle-core    # Core only
cargo build                     # Debug build
cargo build --release           # Release build
cargo build -p typstyle         # CLI only
cargo build -p typstyle-core    # Core only

Running Tests

Important

Update snapshots with cargo instacargo insta when changing core library or fixtures.

Add CLI tests to crates/typstyle/tests/crates/typstyle/tests/ when modifying CLI behavior. For style arguments, add tests to test_style_args.rstest_style_args.rs.

Test Commands

List all tests:

cargo nextest list --workspace
cargo nextest list --workspace

Run all tests and review snapshots:

cargo nextest run --workspace --no-fail-fast
cargo insta review
cargo nextest run --workspace --no-fail-fast
cargo insta review

Snapshot tests only:

cargo nextest run --workspace -E 'test([snapshot])' \
  --no-fail-fast --no-default-features
cargo insta review
cargo nextest run --workspace -E 'test([snapshot])' \
  --no-fail-fast --no-default-features
cargo insta review

Exclude end-to-end tests:

cargo nextest run --workspace -E '!test([e2e])' --no-fail-fast
cargo nextest run --workspace -E '!test([e2e])' --no-fail-fast

CLI tests only:

cargo nextest run -p typstyle --no-fail-fast
cargo nextest run -p typstyle --no-fail-fast

Integration tests:

cargo nextest run -p tests --no-fail-fast
cargo nextest run -p tests --no-fail-fast

Snapshot Management

Review and accept snapshot changes:

cargo insta review    # Interactive review
cargo insta accept    # Accept all changes
cargo insta review    # Interactive review
cargo insta accept    # Accept all changes

Benchmarks

Using Criterion.rs:

cargo bench --workspace -- --list    # List benchmarks
cargo bench --workspace              # Run all benchmarks
cargo bench --workspace -- --list    # List benchmarks
cargo bench --workspace              # Run all benchmarks

View HTML reports at target/criterion/report/index.htmltarget/criterion/report/index.html.

Code Quality

Formatting and Linting

Format code:

cargo fmt --all
cargo fmt --all

Run clippy:

cargo clippy --workspace --all-targets --all-features
cargo clippy --workspace --all-targets --all-features

Testing Guidelines

  • Add tests to appropriate modules when implementing new features
  • Use snapshot tests for formatter output validation
  • Update snapshots after intentional changes to formatting behavior
  • Add CLI integration tests for new command-line features
  • Benchmark performance-critical changes