Last active
November 24, 2016 04:15
-
-
Save hchbaw/7c3ea93bfd1f5e27db0a4e78aed8b300 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all:: | |
test: | |
prove --exec zsh test.zsh -v | |
clean: | |
rm -rf ./.test-data | |
rm -f tmp* | |
.PHONY: test clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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]/}}" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!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 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!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