name: Unit Tests

on:
  workflow_call:
    inputs:
      neovim_versions:
        required: true
        type: string

jobs:
  tests:
    name: unit tests
    runs-on: ubuntu-22.04
    strategy:
      fail-fast: false
      matrix:
        rev: ${{ fromJson(inputs.neovim_versions) }}
    steps:
      - uses: actions/checkout@v3
      - run: date +%F > todays-date
      - name: Restore cache for Neovim
        uses: actions/cache@v3
        with:
          path: .ci/neovim
          key: ${{ matrix.rev }}-${{ hashFiles('todays-date') }}
      - name: Prepare
        run: |
          test -d .ci/neovim || {
            mkdir -p .ci/neovim
            curl -sL "https://github.com/neovim/neovim/releases/download/${{ matrix.rev }}/nvim-linux64.tar.gz" | tar xzf - --strip-components=1 -C "${PWD}/.ci/neovim"
          }

      - name: Run tests
        run: |
          export PATH="${PWD}/.ci/neovim/bin:${PATH}"
          export VIM="${PWD}/.ci/neovim/share/nvim/runtime"
          nvim --version
          make test
