add more alias unit tests

A recent regression to the `alias` command points out the need for more
unit tests of its behavior. I also decided to use it as an opportunity
to normalize the output of just `alias` to list aliases.
This commit is contained in:
Kurtis Rader
2017-07-15 17:36:36 -07:00
parent 98449fec51
commit f2c8e73891
4 changed files with 17 additions and 5 deletions

View File

@@ -17,9 +17,11 @@ function alias --description 'Creates a function wrapping a command'
if not set -q argv[1]
# Print the known aliases.
for func in (functions -n)
set -l output (functions $func | string match -r -- "function .* --description '(alias .*)'" | string split \n)
set -q output[2]
and echo $output[2]
set -l output (functions $func | string match -r -- "^function .* --description 'alias (.*)'")
if set -q output[2]
set output (string replace -r '^'$func'[= ]' '' -- $output[2])
echo alias $func (string escape -- $output[1])
end
end
return 0
else if not set -q argv[2]