#! /usr/bin/env bash
# shellcheck source=tool/test/.ctx

ec=0

(
  desc='Renaming a directory does not report the old directory in new events'
  read -r -d '' expect << .
[
  {
    "effect_type": "create",
    "path_name": "s/self/live@d",
    "path_type": "watcher"
  },
  {
    "effect_type": "create",
    "path_name": "d/d-old",
    "path_type": "dir"
  },
  {
    "effect_type": "rename",
    "path_name": "d/d-old",
    "path_type": "dir",
    "associated": {
      "effect_type": "rename",
      "path_name": "d/d-new",
      "path_type": "dir"
    }
  },
  {
    "effect_type": "create",
    "path_name": "d/d-new/some-new-file",
    "path_type": "file"
  },
  {
    "effect_type": "destroy",
    "path_name": "s/self/die@d",
    "path_type": "watcher"
  }
]
.

  echo -n "$desc ... "

  . "$(dirname "$0")/.ctx"

  actual=$(
    watch-async "$testdir" -ms 800 > "$testdir.json"
    mkdir d-old
    mv d-old d-new
    touch d-new/some-new-file
    wait # for the watcher
    show-events "$testdir" | without-effect-time
  )

  check-result "$expect" "$actual"
)
ec=$((ec + $?))

exit "$ec"
