From f6117f4a3f397b47ebbd5ba355690cb3fe1fb475 Mon Sep 17 00:00:00 2001 From: mattmc3 Date: Thu, 18 Jul 2024 12:48:19 -0400 Subject: [PATCH] Add fpath rule tests --- tests/test_fpath_rules.md | 111 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 tests/test_fpath_rules.md diff --git a/tests/test_fpath_rules.md b/tests/test_fpath_rules.md new file mode 100644 index 0000000..93b17d5 --- /dev/null +++ b/tests/test_fpath_rules.md @@ -0,0 +1,111 @@ +# antidote bundle fpath-rule: + +## Setup + +```zsh +% source ./tests/_setup.zsh +% source ./antidote.zsh +% +``` + +By default, fpath is appended to: + +```zsh +% antidote bundle foo/bar kind:fpath +fpath+=( $HOME/.cache/antidote/foo/bar ) +% +``` + +fpath can be told to explicitly append, but it's unnecessary + +```zsh +% antidote bundle foo/bar kind:zsh fpath-rule:append +fpath+=( $HOME/.cache/antidote/foo/bar ) +source $HOME/.cache/antidote/foo/bar/bar.plugin.zsh +% + +fpath can be prepended with fpath-rule:prepend + +```zsh +% antidote bundle foo/bar kind:fpath fpath-rule:prepend +fpath=( $HOME/.cache/antidote/foo/bar $fpath ) +% + +fpath rules can only be append/prepend + +```zsh +% antidote bundle foo/bar kind:fpath fpath-rule:append #=> --exit 0 +% antidote bundle foo/bar kind:fpath fpath-rule:prepend #=> --exit 0 +% antidote bundle foo/bar kind:fpath fpath-rule:foo 2>&1 +antidote: error: unexpected fpath rule: 'foo' +% + +fpath rules are also used for `kind:autoload` + +```zsh +% antidote bundle foo/baz path:baz kind:autoload fpath-rule:append +fpath+=( $HOME/.cache/antidote/foo/baz/baz ) +builtin autoload -Uz $fpath[-1]/*(N.:t) +% antidote bundle foo/baz path:baz kind:autoload fpath-rule:prepend +fpath=( $HOME/.cache/antidote/foo/baz/baz $fpath ) +builtin autoload -Uz $fpath[1]/*(N.:t) +% +``` + +fpath rules are also used for `autoload:funcdir` + +```zsh +% # Append +% antidote bundle foo/baz autoload:baz fpath-rule:append +fpath+=( $HOME/.cache/antidote/foo/baz/baz ) +builtin autoload -Uz $fpath[-1]/*(N.:t) +fpath+=( $HOME/.cache/antidote/foo/baz ) +source $HOME/.cache/antidote/foo/baz/baz.plugin.zsh +% # Prepend +% antidote bundle foo/baz autoload:baz fpath-rule:prepend +fpath=( $HOME/.cache/antidote/foo/baz/baz $fpath ) +builtin autoload -Uz $fpath[1]/*(N.:t) +fpath=( $HOME/.cache/antidote/foo/baz $fpath ) +source $HOME/.cache/antidote/foo/baz/baz.plugin.zsh +% +``` + +fpath rules can be set globally with a zstyle: + +`zstyle ':antidote:fpath' rule 'prepend'` + +```zsh +% zstyle ':antidote:fpath' rule 'prepend' +% antidote bundle foo/bar +fpath=( $HOME/.cache/antidote/foo/bar $fpath ) +source $HOME/.cache/antidote/foo/bar/bar.plugin.zsh +% antidote bundle foo/bar kind:fpath +fpath=( $HOME/.cache/antidote/foo/bar $fpath ) +% antidote bundle foo/baz path:baz kind:autoload +fpath=( $HOME/.cache/antidote/foo/baz/baz $fpath ) +builtin autoload -Uz $fpath[1]/*(N.:t) +% +``` + +It is NOT recommended to do this, but if you choose to then explicit fpath-rules are +still respected: + +```zsh +% zstyle ':antidote:fpath' rule 'prepend' +% antidote bundle foo/bar fpath-rule:append +fpath+=( $HOME/.cache/antidote/foo/bar ) +source $HOME/.cache/antidote/foo/bar/bar.plugin.zsh +% antidote bundle foo/bar kind:fpath fpath-rule:append +fpath+=( $HOME/.cache/antidote/foo/bar ) +% antidote bundle foo/baz path:baz kind:autoload fpath-rule:append +fpath+=( $HOME/.cache/antidote/foo/baz/baz ) +builtin autoload -Uz $fpath[-1]/*(N.:t) +% +``` + +## Teardown + +```zsh +% t_teardown +% +```