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 bug in __abbr_tips_init.fish #23

Merged
merged 3 commits into from
Jun 17, 2022
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
4 changes: 2 additions & 2 deletions functions/__abbr_tips_init.fish
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function __abbr_tips_init -d "Initialize abbreviations variables for fish-abbr-t
while test $i -le (count $abb)
set -l current_abb (string split -m1 -- ' ' "$abb[$i]")
set -a __ABBR_TIPS_KEYS "$current_abb[1]"
set -a __ABBR_TIPS_VALUES (string trim -c -- '\'' "$current_abb[2]")
set -a __ABBR_TIPS_VALUES (string trim -c '\'' -- "$current_abb[2]")
set i (math $i + 1)
end

Expand All @@ -18,7 +18,7 @@ function __abbr_tips_init -d "Initialize abbreviations variables for fish-abbr-t
while test $i -le (count $abb)
set -l current_abb (string split -m2 -- ' ' "$abb[$i]")
set -a __ABBR_TIPS_KEYS "a__$current_abb[2]"
set -a __ABBR_TIPS_VALUES (string trim -c -- '\'' "$current_abb[3]")
set -a __ABBR_TIPS_VALUES (string trim -c '\'' -- "$current_abb[3]")
set i (math $i + 1)
end
end
27 changes: 23 additions & 4 deletions test/fish-abbreviation-tips.fish
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@ function setup
end

function teardown
# Restore variables
set __ABBR_TIPS_KEYS $tmp_keys
set __ABBR_TIPS_VALUES $tmp_values
set ABBR_TIPS_PROMPT "$tmp_tips_prompt"
# Restore variables
set __ABBR_TIPS_KEYS $tmp_keys
set __ABBR_TIPS_VALUES $tmp_values
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
abbr -e __abbr_test
abbr -e __abbr_test_one
abbr -e __abbr_test_two
end

setup
Expand Down Expand Up @@ -136,4 +139,20 @@ setup
echo (__abbr_tips 'grep -q')
) = "__abbr_test_alias => grep -q"

@test "multiple abbreviation tip match" (
clear_test_var
abbr -a __abbr_test_one ps
abbr -a __abbr_test_two "grep -q"
__abbr_tips_init
echo (__abbr_tips 'grep -q')
) = "__abbr_test_two => grep -q"

@test "multiple alias tip match" (
clear_test_var
alias abbr_test_alias_one ps
alias abbr_test_alias_two "grep -q"
__abbr_tips_init
echo (__abbr_tips 'grep -q')
) = "abbr_test_alias_two => grep -q"

teardown