---
name: Test

on:
  workflow_call:

jobs:
  format:
    name: Format
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v6

      - name: Set up Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          components: llvm-tools-preview

      - name: Run formatter
        run: cargo fmt --all -- --check

  lint:
    name: Clippy
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v6

      - name: Set up Rust toolchain
        uses: dtolnay/rust-toolchain@stable

      - name: Run Clippy linter
        run: cargo clippy --all-targets --all-features

  check:
    name: Check
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v6

      - name: Set up Rust toolchain
        uses: dtolnay/rust-toolchain@stable

      - name: Run cargo check
        run: cargo check

  test:
    name: Test
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os:
          - ubuntu-latest
          - macOS-latest
          - windows-latest

    needs:
      - format
      - lint
      - check

    steps:
      - name: Checkout code
        uses: actions/checkout@v6

      - name: Set up Rust toolchain
        uses: dtolnay/rust-toolchain@stable

      - name: Run tests
        run: cargo test -- --nocapture
