Skip to content

Instantly share code, notes, and snippets.

@hchbaw
Last active November 24, 2016 04:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hchbaw/7c3ea93bfd1f5e27db0a4e78aed8b300 to your computer and use it in GitHub Desktop.
Save hchbaw/7c3ea93bfd1f5e27db0a4e78aed8b300 to your computer and use it in GitHub Desktop.
all::
test:
prove --exec zsh test.zsh -v
clean:
rm -rf ./.test-data
rm -f tmp*
.PHONY: test clean
#autoload +X
# Copyright same as https://github.com/b4b4r07/go-pathshorten
pathshorten () {
setopt localoptions noksharrays extendedglob
local MATCH MBEGIN MEND
local -a match mbegin mend
"${2:-echo}" "${1//(#m)[^\/]##\//${MATCH/(#b)([^.])[^\/]*/$match[1]/}}"
}
#!zsh
((succ=0))
((fail=0))
((testn=0))
is () {
((testn++))
{
if eval "$1"; then
((succ++))
echo ok $testn >>.test-tmp/testn
else
echo $1
echo ${(qqq)functrace}
((fail++))
echo not ok $testn >>.test-tmp/testn
fi
} always {
}
}
test-run () {
mkdir -p .test-tmp
{
: >>.test-tmp/testn
local f; for f in ${@[@]}; do "$f"; done
echo 1..$testn
cat .test-tmp/testn
} always {
rm -rf .test-tmp
}
}
#!zsh
. ./test-lib.zsh
fpath[1,0]=.
autoload pathshorten
test-pathshorten () {
local ret=
local val="$2"
setret () { ret="$1" }
pathshorten "$1" setret
is '[[ "$ret" == "$val" ]]'
}
test-pathshorten-same () { test-pathshorten "$1" "$1" }
tests () {
test-pathshorten \
"~/.vim/scripts/foo/bar/baz.vim" \
"~/.v/s/f/b/baz.vim"
test-pathshorten \
~/.vim/scripts/foo/bar/baz.vim \
/h/${${HOME:t}[1]}/.v/s/f/b/baz.vim
test-pathshorten-same .
test-pathshorten-same test.csv
test-pathshorten \
foo/bar/baz \
f/b/baz
test-pathshorten \
/a/b/foo/bar/baz \
/a/b/f/b/baz
test-pathshorten \
./foo/bar/baz \
./f/b/baz
test-pathshorten-same ./baz.vim
test-pathshorten-same ../../baz.vim
test-pathshorten-same .././baz.vim
test-pathshorten \
1a/2b.dir/3c/4d.txt \
1/2/3/4d.txt
}
test-run tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment