2000-05-17 14:31:32 +02:00
comptestinit () {
setopt extendedglob
[[ -d $ZTST_testdir/Modules/zsh ]] && module_path=( $ZTST_testdir/Modules )
2001-04-03 13:25:11 +02:00
fpath=( $ZTST_srcdir/../Functions/*~*/CVS(/)
$ZTST_srcdir/../Completion
$ZTST_srcdir/../Completion/*/*~*/CVS(/) )
2000-02-29 16:51:21 +01:00
2015-11-22 08:56:25 +01:00
zmodload zsh/zpty || return $?
2000-05-17 13:59:32 +02:00
2000-05-17 14:31:32 +02:00
comptest_zsh=${ZSH:-zsh}
2013-02-12 11:55:32 +01:00
comptest_keymap=e
2000-02-29 16:51:21 +01:00
2013-02-12 11:55:32 +01:00
while getopts vz: opt; do
2000-05-17 14:31:32 +02:00
case $opt in
z) comptest_zsh="$OPTARG";;
2013-02-12 11:55:32 +01:00
v) comptest_keymap="v";;
2000-05-17 14:31:32 +02:00
esac
done
(( OPTIND > 1 )) && shift $(( OPTIND - 1 ))
2000-02-29 16:51:21 +01:00
2000-05-17 14:31:32 +02:00
export PS1="<PROMPT>"
2001-05-08 12:26:58 +02:00
zpty zsh "$comptest_zsh -f +Z"
2000-02-29 16:51:21 +01:00
2000-05-17 14:31:32 +02:00
zpty -r zsh log1 "*<PROMPT>*" || {
2000-06-06 01:06:52 +02:00
print "first prompt hasn't appeared."
2000-05-17 14:31:32 +02:00
return 1
}
2000-05-17 13:59:32 +02:00
2000-05-17 14:31:32 +02:00
comptesteval \
2015-12-10 18:51:41 +01:00
"export LC_ALL=${ZSH_TEST_LANG:-C}" \
2008-10-12 21:20:00 +02:00
"emulate -R zsh" \
2000-07-04 02:45:07 +02:00
"export ZDOTDIR=$ZTST_testdir" \
2000-05-17 14:31:32 +02:00
"module_path=( $module_path )" \
"fpath=( $fpath )" \
2013-02-12 11:55:32 +01:00
"bindkey -$comptest_keymap" \
2000-05-17 14:31:32 +02:00
'LISTMAX=10000000
2014-11-25 22:48:53 +01:00
stty 38400 columns 80 rows 24 tabs -icanon -iexten
2001-06-08 05:02:46 +02:00
TERM=vt100
2014-11-17 16:19:12 +01:00
KEYTIMEOUT=1
2001-02-08 04:29:58 +01:00
setopt zle
2000-02-29 16:51:21 +01:00
autoload -U compinit
2000-06-22 19:33:38 +02:00
compinit -u
2000-06-19 14:16:34 +02:00
zstyle ":completion:*:default" list-colors "no=<NO>" "fi=<FI>" "di=<DI>" "ln=<LN>" "pi=<PI>" "so=<SO>" "bd=<BD>" "cd=<CD>" "ex=<EX>" "mi=<MI>" "tc=<TC>" "sp=<SP>" "lc=<LC>" "ec=<EC>\n" "rc=<RC>"
2000-05-17 13:59:32 +02:00
zstyle ":completion:*" group-name ""
2000-06-19 14:16:34 +02:00
zstyle ":completion:*:messages" format "<MESSAGE>%d</MESSAGE>
2000-02-29 16:51:21 +01:00
"
2000-06-19 14:16:34 +02:00
zstyle ":completion:*:descriptions" format "<DESCRIPTION>%d</DESCRIPTION>
2000-02-29 16:51:21 +01:00
"
2000-06-19 14:16:34 +02:00
zstyle ":completion:*:options" verbose yes
zstyle ":completion:*:values" verbose yes
2000-02-29 16:51:21 +01:00
setopt noalwayslastprompt listrowsfirst completeinword
zmodload zsh/complist
expand-or-complete-with-report () {
print -lr "<WIDGET><expand-or-complete>"
zle expand-or-complete
2000-05-17 14:31:32 +02:00
print -lr - "<LBUFFER>$LBUFFER</LBUFFER>" "<RBUFFER>$RBUFFER</RBUFFER>"
2000-02-29 16:51:21 +01:00
zle clear-screen
zle -R
}
list-choices-with-report () {
print -lr "<WIDGET><list-choices>"
zle list-choices
zle clear-screen
zle -R
}
2013-02-12 11:55:32 +01:00
comp-finish () {
2000-02-29 16:51:21 +01:00
print "<WIDGET><finish>"
2000-05-17 14:31:32 +02:00
zle kill-whole-line
zle clear-screen
zle -R
2000-02-29 16:51:21 +01:00
}
2013-02-12 11:55:32 +01:00
zle-finish () {
2014-02-13 17:23:32 +01:00
local buffer="$BUFFER" cursor="$CURSOR" mark="$MARK"
(( region_active)) || unset mark
BUFFER=""
zle -I
2013-02-12 11:55:32 +01:00
zle clear-screen
2014-02-13 17:23:32 +01:00
zle redisplay
print -lr "<WIDGET><finish>" "BUFFER: $buffer" "CURSOR: $cursor"
(( $+mark )) && print -lr "MARK: $mark"
zle accept-line
2013-02-12 11:55:32 +01:00
}
2000-02-29 16:51:21 +01:00
zle -N expand-or-complete-with-report
zle -N list-choices-with-report
2013-02-12 11:55:32 +01:00
zle -N comp-finish
zle -N zle-finish
2000-02-29 16:51:21 +01:00
bindkey "^I" expand-or-complete-with-report
bindkey "^D" list-choices-with-report
2013-02-12 11:55:32 +01:00
bindkey "^Z" comp-finish
2014-02-13 17:23:32 +01:00
bindkey "^X" zle-finish
bindkey -a "^X" zle-finish
2000-05-17 14:31:32 +02:00
'
2000-05-17 13:59:32 +02:00
}
2000-02-29 16:51:21 +01:00
2014-02-13 17:23:32 +01:00
zpty_flush() {
local junk
if zpty -r -t zsh junk \*; then
(( ZTST_verbose > 2 )) && print -n -u $ZTST_fd "$*: ${(V)junk}"
while zpty -r -t zsh junk \* ; do
(( ZTST_verbose > 2 )) && print -n -u $ZTST_fd "${(V)junk}"
done
2014-02-13 17:25:09 +01:00
(( ZTST_verbose > 2 )) && print -u $ZTST_fd ''
2014-02-13 17:23:32 +01:00
fi
}
2014-03-18 17:57:47 +01:00
zpty_run() {
zpty -w zsh "$*"
zpty -r -m zsh log "*<PROMPT>*" || {
print "prompt hasn't appeared."
return 1
}
}
2000-05-17 14:31:32 +02:00
comptesteval () {
local tmp=/tmp/comptest.$$
2000-05-17 13:59:32 +02:00
2000-05-17 14:31:32 +02:00
print -lr - "$@" > $tmp
2014-02-15 22:45:35 +01:00
# zpty_flush Before comptesteval
2000-05-17 14:31:32 +02:00
zpty -w zsh ". $tmp"
2009-01-13 13:09:26 +01:00
zpty -r -m zsh log_eval "*<PROMPT>*" || {
2000-06-06 01:06:52 +02:00
print "prompt hasn't appeared."
2000-05-17 14:31:32 +02:00
return 1
}
2014-02-13 17:23:32 +01:00
zpty_flush After comptesteval
2000-05-17 14:31:32 +02:00
rm $tmp
2000-05-17 13:59:32 +02:00
}
2000-02-29 16:51:21 +01:00
2000-05-17 14:31:32 +02:00
comptest () {
input="$*"
zpty -n -w zsh "$input"$'\C-Z'
2009-01-13 13:09:26 +01:00
zpty -r -m zsh log "*<WIDGET><finish>*<PROMPT>*" || {
2000-06-06 01:06:52 +02:00
print "failed to invoke finish widget."
2000-05-17 14:31:32 +02:00
return 1
}
2000-02-29 16:51:21 +01:00
2000-05-17 14:31:32 +02:00
logs=(${(s:<WIDGET>:)log})
shift logs
2000-02-29 16:51:21 +01:00
2000-05-17 14:31:32 +02:00
for log in "$logs[@]"; do
if [[ "$log" = (#b)*$'<LBUFFER>'(*)$'</LBUFFER>\r\n<RBUFFER>'(*)$'</RBUFFER>'* ]]; then
print -lr "line: {$match[1]}{$match[2]}"
2000-02-29 16:51:21 +01:00
fi
2001-01-28 20:37:30 +01:00
while (( ${(N)log#*(#b)(<LC><(??)><RC>(*)<EC>|<DESCRIPTION>(*)</DESCRIPTION>|<MESSAGE>(*)</MESSAGE>|<COMPADD>(*)</COMPADD>|<INSERT_POSITIONS>(*)</INSERT_POSITIONS>)} )); do
2000-05-17 14:31:32 +02:00
log="${log[$mend[1]+1,-1]}"
if (( 0 <= $mbegin[2] )); then
if [[ $match[2] != TC && $match[3] != \ # ]]; then
2001-06-09 19:25:56 +02:00
print -lr "$match[2]:{${match[3]%${(%):-%E}}}"
2000-05-17 14:31:32 +02:00
fi
elif (( 0 <= $mbegin[4] )); then
print -lr "DESCRIPTION:{$match[4]}"
elif (( 0 <= $mbegin[5] )); then
print -lr "MESSAGE:{$match[5]}"
elif (( 0 <= $mbegin[6] )); then
2000-05-18 05:33:39 +02:00
print -lr "COMPADD:{${${match[6]}//[$'\r\n']/}}"
2001-01-28 20:37:30 +01:00
elif (( 0 <= $mbegin[7] )); then
print -lr "INSERT_POSITIONS:{${${match[7]}//[$'\r\n']/}}"
2000-05-17 14:31:32 +02:00
fi
done
2000-02-29 16:51:21 +01:00
done
2000-05-17 14:31:32 +02:00
}
2013-02-12 11:55:32 +01:00
zletest () {
2014-11-17 16:19:12 +01:00
local first=0
for input; do
2014-12-07 08:14:29 +01:00
# zpty_flush Before zletest
2014-11-17 16:19:12 +01:00
# sleep for $KEYTIMEOUT
2015-03-25 17:57:23 +01:00
(( first++ )) && { sleep 2 & } | read -t 0.011 -u 0 -k 1
2014-11-17 16:19:12 +01:00
zpty -n -w zsh "$input"
done
zpty -n -w zsh $'\C-X'
2013-02-12 11:55:32 +01:00
zpty -r -m zsh log "*<WIDGET><finish>*<PROMPT>*" || {
print "failed to invoke finish widget."
return 1
}
2014-02-15 22:45:35 +01:00
# zpty_flush After zletest
2014-11-15 21:27:44 +01:00
print -lr "${(@)${(@ps:\r\n:)log##*<WIDGET><finish>}[2,-2]}"
2013-02-12 11:55:32 +01:00
}