Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix abbr --add option typo #13

Merged
merged 2 commits into from
Feb 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conf.d/abbr_tips.fish
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function __abbr_tips --on-event fish_postexec -d "Abbreviation reminder for the

# Update abbreviations lists when adding/removing abbreviations
if test "$command[1]" = "abbr"
if string match -q -r '^--append|-a$' -- "$command[2]"
if string match -q -r '^--add|-a$' -- "$command[2]"
and not contains -- "$command[3]" $__ABBR_TIPS_KEYS
set -a __ABBR_TIPS_KEYS "$command[3]"
set -a __ABBR_TIPS_VALUES "$command[4..-1]"
Expand Down
25 changes: 25 additions & 0 deletions test/fish-abbreviation-tips.fish
Original file line number Diff line number Diff line change
Expand Up @@ -21,84 +21,109 @@ function teardown
set ABBR_TIPS_PROMPT "$tmp_tips_prompt"
end

function clear_test_var
# Clear variables to prevent the results
# of each unit test from affecting each other
set -g __ABBR_TIPS_KEYS
set -g __ABBR_TIPS_VALUES
end

setup

# Tests
@test "initial tip key" (
clear_test_var
abbr -a __abbr_test ps
set -e __ABBR_TIPS_KEYS
__abbr_tips_init
contains "__abbr_test" $__ABBR_TIPS_KEYS
) "$status" = 0

@test "initial tip value" (
clear_test_var
abbr -a __abbr_test ps
set -e __ABBR_TIPS_VALUES
__abbr_tips_init
contains "ps" $__ABBR_TIPS_VALUES
) "$status" = 0

@test "add abbreviation tip key" (
clear_test_var
__abbr_tips 'abbr -a __abbr_test ps'
contains "__abbr_test" $__ABBR_TIPS_KEYS
) "$status" = 0

@test "add abbreviation tip value" (
clear_test_var
__abbr_tips 'abbr -a __abbr_test ps'
contains "ps" $__ABBR_TIPS_VALUES
) "$status" = 0


@test "remove abbreviation tip key" (
clear_test_var
__abbr_tips 'abbr -a __abbr_test ps'
__abbr_tips 'abbr -e __abbr_test'
not contains "__abbr_test" $__ABBR_TIPS_KEYS
) "$status" = 0

@test "remove abbreviation tip value" (
clear_test_var
__abbr_tips 'abbr -a __abbr_test ps'
__abbr_tips 'abbr -e __abbr_test'
not contains "ps" $__ABBR_TIPS_VALUES
) "$status" = 0

@test "add alias tip key" (
clear_test_var
__abbr_tips 'alias __abbr_test_alias "grep -q"'
contains "a____abbr_test_alias" $__ABBR_TIPS_KEYS
) "$status" = 0

@test "add alias tip value" (
clear_test_var
__abbr_tips 'alias __abbr_test_alias "grep -q"'
contains "grep -q" $__ABBR_TIPS_VALUES
) "$status" = 0

@test "add alias tip value with =" (
clear_test_var
__abbr_tips 'alias __abbr_test_alias=grep"'
contains "grep" $__ABBR_TIPS_VALUES
) "$status" = 0

@test "add alias tip key with =" (
clear_test_var
__abbr_tips 'alias __abbr_test_alias=grep"'
contains "a____abbr_test_alias" $__ABBR_TIPS_KEYS
) "$status" = 0


@test "remove alias tip key" (
clear_test_var
__abbr_tips 'alias __abbr_test_alias "grep -q"'
__abbr_tips 'functions --erase __abbr_test_alias'
not contains "a____abbr_test_alias" $__ABBR_TIPS_KEYS
) "$status" = 0

@test "remove alias tip value" (
clear_test_var
__abbr_tips 'alias __abbr_test_alias "grep -q"'
__abbr_tips 'functions --erase __abbr_test_alias'
not contains "grep -q" $__ABBR_TIPS_VALUES
) "$status" = 0

@test "abbreviation tip match" (
clear_test_var
__abbr_tips 'abbr -a __abbr_test ps'
echo (__abbr_tips 'ps')
) = "__abbr_test => ps"

@test "alias tip match" (
clear_test_var
alias __abbr_test_alias "grep -q"
__abbr_tips 'alias __abbr_test_alias "grep -q"'
echo (__abbr_tips 'grep -q')
) = "__abbr_test_alias => grep -q"

teardown