Skip to content

Commit

Permalink
Merge pull request #148 from /issues/118-tests
Browse files Browse the repository at this point in the history
add failing tests for erasure limitations [#118]
  • Loading branch information
olets authored Jul 31, 2024
2 parents d85bae2 + 81325a7 commit 680da6e
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 19 deletions.
124 changes: 108 additions & 16 deletions tests/abbr-erase.ztr.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,120 @@

main() {
emulate -LR zsh

{
ZTR_TEARDOWN_FN() {
emulate -LR zsh

[[ $ABBR_USER_ABBREVIATIONS_FILE != $ABBR_USER_ABBREVIATIONS_FILE_SAVED ]] && \
echo '' > $ABBR_USER_ABBREVIATIONS_FILE
}

abbr add $test_abbr_abbreviation=$test_abbr_expansion
abbr erase $test_abbr_abbreviation
ztr test '(( ${#ABBR_REGULAR_USER_ABBREVIATIONS} == 0 ))' \
"Can erase an abbreviation" \
"Dependencies: add, erase"
abbr add $test_abbr_abbreviation=$test_abbr_expansion
abbr erase $test_abbr_abbreviation
ztr test '(( ${#ABBR_REGULAR_USER_ABBREVIATIONS} == 0 ))' \
"Can erase an abbreviation" \
"Dependencies: add, erase"

# TODO
# See
# - https://github.com/olets/zsh-abbr/issues/118
abbr add ${test_abbr_abbreviation}^=$test_abbr_expansion
abbr erase ${test_abbr_abbreviation}^
ztr test '(( ${#ABBR_REGULAR_USER_ABBREVIATIONS} == 0 ))' \
"Can erase an abbreviation ending in a caret" \
"Dependencies: add, erase. GitHub issues: #118"

# TODO
# See
# - https://github.com/olets/zsh-abbr/issues/118
abbr add ^$test_abbr_abbreviation=$test_abbr_expansion
abbr erase ^$test_abbr_abbreviation
ztr test '(( ${#ABBR_REGULAR_USER_ABBREVIATIONS} == 0 ))' \
"Can erase an abbreviation starting with a caret" \
"Dependencies: add, erase. GitHub issues: #118"

# TODO
# See
# - https://github.com/olets/zsh-abbr/issues/118
abbr add ${test_abbr_abbreviation}^${test_abbr_abbreviation}=$test_abbr_expansion
abbr erase ${test_abbr_abbreviation}^${test_abbr_abbreviation}
ztr test '(( ${#ABBR_REGULAR_USER_ABBREVIATIONS} == 0 ))' \
"Can erase an abbreviation with an embedded caret" \
"Dependencies: add, erase. GitHub issues: #118"

# TODO
# See
# - https://github.com/olets/zsh-abbr/issues/84
# - https://github.com/olets/zsh-abbr/issues/118
abbr add ${test_abbr_abbreviation}\!=$test_abbr_expansion
abbr erase $test_abbr_abbreviation'!'
ztr test '(( ${#ABBR_REGULAR_USER_ABBREVIATIONS} == 0 ))' \
"Can erase an abbreviation ending in an escaped exclamation point" \
"Dependencies: add, erase. GitHub issues: #84, #118"

# @TODO
# See
# - https://github.com/olets/zsh-abbr/issues/84
# - https://github.com/olets/zsh-abbr/issues/118
abbr add \!$test_abbr_abbreviation=$test_abbr_expansion
abbr erase \!$test_abbr_abbreviation
ztr test '(( ${#ABBR_REGULAR_USER_ABBREVIATIONS} == 0 ))' \
"Can erase an abbreviation starting with an escaped exclamation point" \
"Dependencies: add, erase. GitHub issues: #84, #118"

# @TODO
# See
# - https://github.com/olets/zsh-abbr/issues/84
# - https://github.com/olets/zsh-abbr/issues/118
abbr add '!'$test_abbr_abbreviation=$test_abbr_expansion
abbr erase '!'$test_abbr_abbreviation
ztr test '(( ${#ABBR_REGULAR_USER_ABBREVIATIONS} == 0 ))' \
"Can erase an abbreviation starting with a single-quoted exclamation point" \
"Dependencies: add, erase. GitHub issues: #84, #118"

# @TODO
# See
# - https://github.com/olets/zsh-abbr/issues/118
local single_quoted_abbreviation="'"
single_quoted_abbreviation+=$test_abbr_abbreviation
single_quoted_abbreviation+="'"
abbr add $single_quoted_abbreviation=$test_abbr_expansion
abbr erase $single_quoted_abbreviation
ztr test '(( ${#ABBR_REGULAR_USER_ABBREVIATIONS} == 0 ))' \
"Can erase an abbreviation with single quotation marks" \
"Dependencies: add, erase. GitHub issues: #118"

# @TODO
# See
# - https://github.com/olets/zsh-abbr/issues/118
local double_quoted_abbreviation='"'
double_quoted_abbreviation+=$test_abbr_abbreviation
double_quoted_abbreviation+='"'
abbr add $double_quoted_abbreviation=$test_abbr_expansion
abbr erase $double_quoted_abbreviation
ztr test '(( ${#ABBR_REGULAR_USER_ABBREVIATIONS} == 0 ))' \
"Can erase an abbreviation starting with double quotation marks" \
"Dependencies: add, erase. GitHub issues: #118"

# Manual
# Manual

abbr add $test_abbr_abbreviation=$test_abbr_expansion
echo '' > $ABBR_USER_ABBREVIATIONS_FILE
ztr test '[[ -z $(abbr expand $test_abbr_abbreviation) ]]' \
"Can delete a user abbreviation from outside abbr without unexpected retention"
abbr add $test_abbr_abbreviation=$test_abbr_expansion
echo '' > $ABBR_USER_ABBREVIATIONS_FILE
ztr test '[[ -z $(abbr expand $test_abbr_abbreviation) ]]' \
"Can delete a user abbreviation from outside abbr without unexpected retention"


# Multiword
# Multiword

abbr add $test_abbr_abbreviation_multiword=$test_abbr_expansion
abbr erase $test_abbr_abbreviation_multiword
ztr test '(( ${#ABBR_REGULAR_USER_ABBREVIATIONS} == 0 ))' \
"Can erase a multi-word abbreviation" \
"Dependencies: add, erase"
abbr add $test_abbr_abbreviation_multiword=$test_abbr_expansion
abbr erase $test_abbr_abbreviation_multiword
ztr test '(( ${#ABBR_REGULAR_USER_ABBREVIATIONS} == 0 ))' \
"Can erase a multi-word abbreviation" \
"Dependencies: add, erase"
} always {
unfunction -m ZTR_TEARDOWN_FN
}
}

main
9 changes: 6 additions & 3 deletions tests/index.ztr.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@

main() {
emulate -LR zsh

typeset -g ABBR_USER_ABBREVIATIONS_FILE_SAVED

local \
abbr_dir \
abbr_expansion_cursor_marker_saved \
abbr_line_cursor_marker_saved \
abbr_tmpdir_saved \
abbr_user_abbreviations_file_saved \
cmd \
test_abbr_abbreviation \
test_abbr_abbreviation_2 \
Expand Down Expand Up @@ -67,7 +68,7 @@ main() {
abbr_line_cursor_marker_saved=$ABBR_LINE_CURSOR_MARKER
abbr_quiet_saved=$ABBR_QUIET
abbr_tmpdir_saved=$ABBR_TMPDIR
abbr_user_abbreviations_file_saved=$ABBR_USER_ABBREVIATIONS_FILE
ABBR_USER_ABBREVIATIONS_FILE_SAVED=$ABBR_USER_ABBREVIATIONS_FILE

# Configure
unset ABBR_EXPANSION_CURSOR_MARKER
Expand Down Expand Up @@ -110,7 +111,9 @@ main() {
ABBR_LINE_CURSOR_MARKER=$abbr_line_cursor_marker_saved
ABBR_QUIET=$abbr_quiet_saved
ABBR_TMPDIR=$abbr_tmpdir_saved
ABBR_USER_ABBREVIATIONS_FILE=$abbr_user_abbreviations_file_saved
ABBR_USER_ABBREVIATIONS_FILE=$ABBR_USER_ABBREVIATIONS_FILE_SAVED
unset ABBR_USER_ABBREVIATIONS_FILE_SAVED

if $(command -v _abbr_load_user_abbreviations); then
_abbr_load_user_abbreviations
fi
Expand Down

0 comments on commit 680da6e

Please sign in to comment.