on:
  push:
    branches:
      - main

  pull_request: {}

name: Test

jobs:
  build_and_test:
    name: Test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: nightly
          components: clippy

      - uses: Swatinem/rust-cache@v2

      - name: Test core functionality
        run: cargo test

      - name: Run all examples
        run: |
          # cargo run --example main
          cargo run --example buffer
          cargo run --example from
          # cargo run --example bincode
          cargo run --example serde_demo
          cargo run --example readme_test
          cargo run --example struct_key_demo

      - name: Clippy check
        run: cargo clippy --all-features -- -D warnings
