name: Tests

on:
  push:
    branches: [master]
    paths:
      - ".github/workflows/test.yml"
      - "**.rs"
      - "Cargo.toml"
      - "Cargo.lock"
  pull_request:
    branches: [master]
    paths:
      - ".github/workflows/test.yml"
      - "**.rs"
      - "Cargo.toml"
      - "Cargo.lock"

jobs:
  build:
    name: Test target ${{ matrix.target }} on ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        target:
          - x86_64-unknown-linux-gnu
          - x86_64-pc-windows-msvc
          - x86_64-apple-darwin
          - wasm32-wasip1
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
          - target: wasm32-wasip1
            os: ubuntu-latest
          - target: x86_64-pc-windows-msvc
            os: windows-latest
          - target: x86_64-apple-darwin
            os: macos-latest

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

      - name: Setup Rust toolchain
        uses: dtolnay/rust-toolchain@master
        with:
          targets: ${{ matrix.target }}
          toolchain: stable

      - name: cargo build
        run: cargo build --target=${{ matrix.target }}

  docs:
    name: Doc Tests
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup Rust toolchain
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: stable

      - name: Test
        run: cargo test --features=chrono_0_4 --doc

  test:
    name: Test feature ${{ matrix.feature }}
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        feature:
          - chrono_0_4
          - time_0_3
          - jiff_0_1
          - jiff_0_2

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

      - name: Setup Rust toolchain
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: stable

      - name: Test
        run: cargo test --features=${{ matrix.feature }} --tests
