From 05d3c175a5f9d1eb7bd8ed5f9c36ff5838ee6b8e Mon Sep 17 00:00:00 2001 From: Sven Wischnowsky Date: Wed, 17 May 2000 11:59:32 +0000 Subject: add Felix' completion matching test; some fixes for bugs shown by it (11439) --- Test/.distfiles | 2 +- Test/54compmatch.ztst | 488 ++++++++++++++++++++++++++++++++++++++++++++++++++ Test/comptest | 61 +++++-- 3 files changed, 534 insertions(+), 17 deletions(-) create mode 100644 Test/54compmatch.ztst (limited to 'Test') diff --git a/Test/.distfiles b/Test/.distfiles index 9f8d53980..d65d09912 100644 --- a/Test/.distfiles +++ b/Test/.distfiles @@ -5,5 +5,5 @@ DISTFILES_SRC=' 05command.ztst 06arith.ztst 07cond.ztst 08traps.ztst 09funcdef.ztst 10prompt.ztst 11glob.ztst 12procsubst.ztst 13parameter.ztst 50cd.ztst 51xtrace.ztst 52zregexparse.ztst - 53completion.ztst + 53completion.ztst 54compmatch.ztst ' diff --git a/Test/54compmatch.ztst b/Test/54compmatch.ztst new file mode 100644 index 000000000..7c55134f0 --- /dev/null +++ b/Test/54compmatch.ztst @@ -0,0 +1,488 @@ +# Tests for completion system matching control + +# Most tests follow this format: +# test_code $matcher_string selection_list +# comptest -c "$code" $' tst input_string' +# test_code generates the string $codem which sets what words the completion +# should be selecting from. The comptest function actually performs the +# completion test, using the completion function generated by test_code. +# +# This test also tests error conditions that compadd reports, so output also +# contains the compadd output. + +%prep + zmodload -i zsh/zpty + + TERM=vt100 + export ZTST_testdir ZTST_srcdir TERM + comptest () { $ZTST_testdir/../Src/zsh -f $ZTST_srcdir/comptest -z $ZTST_testdir/../Src/zsh -d $ZTST_testdir/compdump.tmp "$@" } + + mkdir match.tmp + cd match.tmp + + + list1=(IndianRed IndianRed2 IndianRed3 IndianRed4) + test_code () { + matcher=$1; + list=$2; + code="compdef _tst tst ; _tst () { echo -n '';compadd -M '" + code="$code$matcher" + code="$code' - ${(P)list} ; echo -n ''}" + } + + + +%test + + + test_code z: list1 + comptest -c "$code" $'tst \t' +0:Match Error for "z:" +>line: {tst }{} +>COMPADD:{_tst:compadd: unknown match specification character `z'} + + test_code m: list1 + comptest -c "$code" $'tst \t' +0:Match Error for "m:" +>line: {tst }{} +>COMPADD:{_tst:compadd: missing patterns} + + test_code M: list1 + comptest -c "$code" $'tst \t' +0:Match Error for "M:" +>line: {tst }{} +>COMPADD:{_tst:compadd: missing patterns} + + test_code r: list1 + comptest -c "$code" $'tst \t' +0:Match Error "r:" +>line: {tst }{} +>COMPADD:{_tst:compadd: missing patterns} + + test_code R: list1 + comptest -c "$code" $'tst \t' +0:Match Error "R:" +>line: {tst }{} +>COMPADD:{_tst:compadd: missing patterns} + + test_code l: list1 + comptest -c "$code" $'tst \t' +0:Match Error for "l:" +>line: {tst }{} +>COMPADD:{_tst:compadd: missing patterns} + + test_code L: list1 + comptest -c "$code" $'tst \t' +0:Match Error for "L:" +>line: {tst }{} +>COMPADD:{_tst:compadd: missing patterns} + + test_code 'm:{0-9' list1 + comptest -c "$code" $'tst \t' +0:Match Error for "m:{0-9" +>line: {tst }{} +>COMPADD:{_tst:compadd: unterminated character class} + + test_code 'm:{0-9}' list1 + comptest -c "$code" $'tst \t' +0:Match Error for "m:{0-9}" +>line: {tst }{} +>COMPADD:{_tst:compadd: missing word pattern} + + test_code 'm:{0-9}={' list1 + comptest -c "$code" $'tst \t' +0:Match Error for "m:{0-9}={" +>line: {tst }{} +>COMPADD:{_tst:compadd: unterminated character class} + + test_code 'm:{0-9}={0-' list1 + comptest -c "$code" $'tst \t' +0:Match Error for "m:{0-9}={0-" +>line: {tst }{} +>COMPADD:{_tst:compadd: unterminated character class} + + test_code 'm:{0-9}={-' list1 + comptest -c "$code" $'tst \t' +0:Match Error for "m:{0-9}={-" +>line: {tst }{} +>COMPADD:{_tst:compadd: unterminated character class} + + test_code r: list1 + comptest -c "$code" $'tst \t' +0:Match Error "r:" +>line: {tst }{} +>COMPADD:{_tst:compadd: missing patterns} + + example1_list=( + kshoptionprint shglob + listambiguous shinstdin + listbeep shnullcmd + listpacked shoptionletters + listrowsfirst shortloops + listtypes shwordsplit + ) + options_matcher='L:|[nN][oO]= M:_= M:{A-Z}={a-z}' + test_code $options_matcher example1_list + comptest -c "$code" $'tst nolistbee\t' +0:Documentation example for options, input "nolistbee" +>line: {tst nolistbeep }{} +>COMPADD:{} + + + test_code $options_matcher example1_list + comptest -c "$code" $'tst list_bee\t' +0:Documentation example for options, input "list_bee" +>line: {tst list_beep }{} +>COMPADD:{} + + test_code $options_matcher example1_list + comptest -c "$code" $'tst ListBee\t' +0:Documentation example for options, input "ListBee" +>line: {tst ListBeep }{} +>COMPADD:{} + + test_code $options_matcher example1_list + comptest -c "$code" $'tst NOList\tB\t' +0:Documentation example for options, input "NOList" +>line: {tst NOList}{} +>COMPADD:{} +>NO:{NOListambiguous} +>NO:{NOListbeep} +>NO:{NOListpacked} +>NO:{NOListrowsfirst} +>NO:{NOListtypes} +>line: {tst NOListBeep }{} +>COMPADD:{} + + + test_code $options_matcher example1_list + comptest -c "$code" $'tst NO_List\t__\tB\t' +0:Documentation example for options, input "NO_List\t__\tB\t" +>line: {tst NO_List}{} +>COMPADD:{} +>NO:{NO_Listambiguous} +>NO:{NO_Listbeep} +>NO:{NO_Listpacked} +>NO:{NO_Listrowsfirst} +>NO:{NO_Listtypes} +>line: {tst NO_List__}{} +>COMPADD:{} +>NO:{NO_List__ambiguous} +>NO:{NO_List__beep} +>NO:{NO_List__packed} +>NO:{NO_List__rowsfirst} +>NO:{NO_List__types} +>line: {tst NO_List__Beep }{} +>COMPADD:{} + + test_code $options_matcher example1_list + comptest -c "$code" $'tst __\tN\t__o\t___\tlist_\tbeep__\t' +0:Documentation example for options, input "__\tN\t__o\t___\tlist_\tbeep__\t" +>line: {tst __}{} +>COMPADD:{} +>NO:{__kshoptionprint} +>NO:{__listambiguous} +>NO:{__listbeep} +>NO:{__listpacked} +>NO:{__listrowsfirst} +>NO:{__listtypes} +>NO:{__shglob} +>NO:{__shinstdin} +>NO:{__shnullcmd} +>NO:{__shoptionletters} +>NO:{__shortloops} +>NO:{__shwordsplit} +>line: {tst __N}{} +>COMPADD:{} +>line: {tst __N__o}{} +>COMPADD:{} +>line: {tst __N__o___}{} +>COMPADD:{} +>line: {tst __N__o___list_}{} +>COMPADD:{} +>line: {tst __N__o___list_beep__}{} +>COMPADD:{} + + test_code $options_matcher example1_list + comptest -c "$code" $'tst __\tNo\t___\tlist_\tbeep__\t' +0:Documentation example for options, input "__\tNo\t___\tlist_\tbeep__\t" +>line: {tst __}{} +>COMPADD:{} +>NO:{__kshoptionprint} +>NO:{__listambiguous} +>NO:{__listbeep} +>NO:{__listpacked} +>NO:{__listrowsfirst} +>NO:{__listtypes} +>NO:{__shglob} +>NO:{__shinstdin} +>NO:{__shnullcmd} +>NO:{__shoptionletters} +>NO:{__shortloops} +>NO:{__shwordsplit} +>line: {tst __No}{} +>COMPADD:{} +>line: {tst __No___}{} +>COMPADD:{} +>line: {tst __No___list_}{} +>COMPADD:{} +>line: {tst __No___list_beep__}{} +>COMPADD:{} + + + test_code $options_matcher example1_list + comptest -c "$code" $'tst ___\tlist_\tbeep__\t' +0:Documentation example for options, input "___\tlist_\tbeep__\t" +>line: {tst ___}{} +>COMPADD:{} +>NO:{___kshoptionprint} +>NO:{___listambiguous} +>NO:{___listbeep} +>NO:{___listpacked} +>NO:{___listrowsfirst} +>NO:{___listtypes} +>NO:{___shglob} +>NO:{___shinstdin} +>NO:{___shnullcmd} +>NO:{___shoptionletters} +>NO:{___shortloops} +>NO:{___shwordsplit} +>line: {tst ___list_}{} +>COMPADD:{} +>NO:{___list_ambiguous} +>NO:{___list_beep} +>NO:{___list_packed} +>NO:{___list_rowsfirst} +>NO:{___list_types} +>line: {tst ___list_beep__ }{} +>COMPADD:{} + + lower_insensitive_M="M:{a-z}={A-Z}" + lower_insensitive_m="m:{a-z}={A-Z}" + example2_list=(ABC Abc abc) + test_code $lower_insensitive_M example2_list + comptest -c "$code" $'tst ab\tC\t' +0:Documentation example for lowercase insenitive M, input "ab\tC\t" +>line: {tst ab}{} +>COMPADD:{} +>NO:{abC} +>NO:{abc} +>line: {tst abC }{} +>COMPADD:{} + + test_code $lower_insensitive_m example2_list + comptest -c "$code" $'tst A\t\t' +0:Documentation example for lowercase insenitive m, input "A\t\t" +>line: {tst A}{} +>COMPADD:{} +>NO:{ABC} +>NO:{Abc} +>line: {tst ABC}{} +>COMPADD:{} + + example3_list=(ABC Abc abc) + case_insensitive_M="M:{a-zA-Z}={A-Za-z}" + case_insensitive_m="m:{a-zA-Z}={A-Za-z}" + test_code $case_insensitive_M example3_list + comptest -c "$code" $'tst aB\t\t' +0:Documentation example for case insenitive M, input "aB\t\t" +>line: {tst aB}{} +>COMPADD:{} +>NO:{aBC} +>NO:{aBc} +>line: {tst aBC}{} +>COMPADD:{} + + + test_code $case_insensitive_m example3_list + comptest -c "$code" $'tst aB\t\t' +0:Documentation example for case insenitive m, input "aB\t\t" +>line: {tst a}{BC} +>COMPADD:{} +>line: {tst a}{BC} +>COMPADD:{} +>NO:{ABC} +>NO:{Abc} +>NO:{abc} + + example4_matcher='r:|.=* r:|=*' + example4_list=(comp.sources.unix comp.sources.misc + comp.graphics.algorithms comp.graphics.animation comp.graphics.api + comp.graphics.apps comp.graphics.misc comp.graphics.packages + comp.graphics.rendering comp.graphics.visualization comp.graphics.apps.alias + comp.graphics.apps.gimp comp.graphics.apps.gnuplot + comp.graphics.apps.lightwave comp.graphics.apps.pagemaker + comp.graphics.apps.paint-shop-pro comp.graphics.apps.photoshop + comp.graphics.apps.softimage comp.graphics.apps.ulead + comp.graphics.rendering.misc comp.graphics.rendering.raytracing + comp.graphics.rendering.renderman) + test_code $example4_matcher example4_list + comptest -c "$code" $'tst c.s.u\t' +0:Documentation example using input c.s.u +>line: {tst comp.sources.unix }{} +>COMPADD:{} + + test_code $example4_matcher example4_list + comptest -c "$code" $'tst c.g.\ta\t.\tp\ta\tg\t' +0:Documentation example using input c.g.\ta\t.\tp\ta\tg\t +>line: {tst comp.graphics.}{} +>COMPADD:{} +>line: {tst comp.graphics.a}{} +>COMPADD:{} +>NO:{comp.graphics.algorithms} +>NO:{comp.graphics.animation} +>NO:{comp.graphics.api} +>NO:{comp.graphics.apps} +>NO:{comp.graphics.apps.alias} +>NO:{comp.graphics.apps.gimp} +>NO:{comp.graphics.apps.gnuplot} +>NO:{comp.graphics.apps.lightwave} +>NO:{comp.graphics.apps.pagemaker} +>NO:{comp.graphics.apps.paint-shop-pro} +>NO:{comp.graphics.apps.photoshop} +>NO:{comp.graphics.apps.softimage} +>NO:{comp.graphics.apps.ulead} +>line: {tst comp.graphics.apps.}{} +>COMPADD:{} +>line: {tst comp.graphics.apps.p}{} +>COMPADD:{} +>NO:{comp.graphics.apps.pagemaker} +>NO:{comp.graphics.apps.paint-shop-pro} +>NO:{comp.graphics.apps.photoshop} +>line: {tst comp.graphics.apps.pa}{} +>COMPADD:{} +>NO:{comp.graphics.apps.pagemaker} +>NO:{comp.graphics.apps.paint-shop-pro} +>line: {tst comp.graphics.apps.pagemaker }{} +>COMPADD:{} + + test_code $example4_matcher example4_list + comptest -c "$code" $'tst c...pag\t' +0:Documentation example using input c...pag\t +>line: {tst comp.graphics.apps.pagemaker }{} +>COMPADD:{} + + test_code $example4_matcher example4_list + comptest -c "$code" $'tst c...pa\tg\t' +0:Documentation example using input c...pa\tg\t +>line: {tst comp.graphics.apps.pa}{} +>COMPADD:{} +>line: {tst comp.graphics.apps.pagemaker }{} +>COMPADD:{} + + example5_matcher='r:|[.,_-]=* r:|=*' + example5_list=(veryverylongfile.c veryverylongheader.h) + test_code $example5_matcher example5_list + comptest -c "$code" $'tst v.c\tv.h\t' +0:Documentation example using input v.c\t +>line: {tst veryverylongfile.c }{} +>COMPADD:{} +>line: {tst veryverylongfile.c veryverylongheader.h }{} +>COMPADD:{} + + + example6_list=(LikeTHIS FooHoo 5foo123 5bar234) + test_code 'r:|[A-Z0-9]=* r:|=*' example6_list + comptest -c "$code" $'tst H\t' +0:Documentation example using "r:|[A-Z0-9]=* r:|=*", input H +>line: {tst H}{} +>COMPADD:{} + + test_code 'r:|[A-Z0-9]=* r:|=*' example6_list + comptest -c "$code" $'tst 2\t' +0:Documentation example using "r:|[A-Z0-9]=* r:|=*", input 2 +>line: {tst 2}{} +>COMPADD:{} + + test_code 'r:|[A-Z0-9]=** r:|=*' example6_list + comptest -c "$code" $'tst H\t' +0:Documentation example using "r:|[A-Z0-9]=* r:|=*", input 2 +>line: {tst H}{} +>COMPADD:{} +>NO:{FooHoo} +>NO:{LikeTHIS} + + test_code 'r:|[A-Z0-9]=** r:|=*' example6_list + comptest -c "$code" $'tst 2\t\t' +0:Documentation example using "r:|[A-Z0-9]=* r:|=*", input 2 +>line: {tst 523}{} +>COMPADD:{} +>line: {tst 523}{} +>COMPADD:{} +>NO:{5bar234} +>NO:{5foo123} + + example7_matcher="r:[^A-Z0-9]||[A-Z0-9]=** r:|=*" + example7_list=($example6_list) + test_code $example7_matcher example7_list + comptest -c "$code" $'tst H\t2\t' +0:Documentation example using "r:[^A-Z0-9]||[A-Z0-9]=** r:|=*" +>line: {tst FooHoo }{} +>COMPADD:{} +>line: {tst FooHoo 5bar234 }{} +>COMPADD:{} + + + workers_7311_matcher="m:{a-z}={A-Z} r:|[.,_-]=* r:|=*" + workers_7311_list=(Abc-Def-Ghij.txt Abc-def.ghi.jkl_mno.pqr.txt Abc_def_ghi_jkl_mno_pqr.txt) + test_code $workers_7311_matcher workers_7311_list + comptest -c "$code" $'tst a-a\t' +0:Bug from workers 7311 +>line: {tst a-a}{} +>COMPADD:{} + + test_code $workers_7311_matcher workers_7311_list + comptest -c "$code" $'tst a\t\t-d.\t' +0:Bug from workers_7311 +>line: {tst Abc}{} +>COMPADD:{} +>line: {tst Abc}{} +>COMPADD:{} +>NO:{Abc-Def-Ghij.txt} +>NO:{Abc-def.ghi.jkl_mno.pqr.txt} +>NO:{Abc_def_ghi_jkl_mno_pqr.txt} +>line: {tst Abc-def.ghi.jkl_mno.pqr.txt }{} +>COMPADD:{} + + workers_10886_matcher="r:|[A-Z0-9]=* r:|=*" + workers_10886_list=(BW UWB W) + test_code $workers_10886_matcher workers_10886_list + comptest -c "$code" $'tst W\t' +0:Bug from workers 10886 +>line: {tst W }{} +>COMPADD:{} + + workers_11081_matcher='m:{a-zA-Z}={A-Za-z} r:|[.,_-]=* r:[^A-Z0-9]||[A-Z0-9]=* r:[A-Z0-9]||[^A-Z0-9]=* r:[^0-9]||[0-9]=* r:|=*' + workers_11081_list=(build.out build.out1 build.out2) + test_code $workers_11081_matcher workers_11081_list + comptest -c "$code" $'tst bui\t\t\t' +0:Bug from workers 11081 +>line: {tst build.out}{} +>COMPADD:{} +>line: {tst build.out}{} +>COMPADD:{} +>NO:{build.out} +>NO:{build.out1} +>NO:{build.out2} +>line: {tst build.out}{} +>COMPADD:{} + + + workers_11388_matcher='r:|[:.]=* r:|=*' + workers_11388_list=(a.b:0 c.d:1) + test_code $workers_11388_matcher workers_11388_list + comptest -c "$code" $'tst :\t' +0:Non-bug from workers 11388 +>line: {tst :}{} +>COMPADD:{} + + workers_11388_matcher='r:|[:.]=** r:|=*' + workers_11388_list=(a.b:0 c.d:1) + test_code $workers_11388_matcher workers_11388_list + comptest -c "$code" $'tst :\t' +0:Non-bug from workers 11388 +>line: {tst }{.:} +>COMPADD:{} + +%clean +exit 0 diff --git a/Test/comptest b/Test/comptest index aae996105..6a37bb15e 100644 --- a/Test/comptest +++ b/Test/comptest @@ -1,13 +1,19 @@ #!/usr/local/bin/zsh -f -zmodload zsh/zpty +[[ -d $ZTST_testdir/Modules/zsh ]] && module_path=( $ZTST_testdir/Modules ) + +zmodload -i zsh/zpty setopt extendedglob +fpath=( $ZTST_srcdir/../(Completion|Functions)/*~*/CVS(/) ) + debug= dump=(-D) code= zsh=${ZSH:-zsh} +termcap_ce="$(echotc ce)" +debug=yes while getopts Dd:c:z: opt; do case $opt in D) debug=yes;; @@ -20,14 +26,18 @@ done input="$*" -init=\ -'stty columns 80 rows 24 +tmp=/tmp/comptest.$$ + +cat <$tmp +module_path=( $module_path ) +fpath=( $fpath ) +stty columns 80 rows 24 LISTMAX=10000000 -'"ZLS_COLORS='no=:fi=:di=:ln=:pi=:so=:bd=:cd=:ex=:mi=:tc=:sp=:lc=:ec=\n:rc=' +ZLS_COLORS='no=:fi=:di=:ln=:pi=:so=:bd=:cd=:ex=:mi=:tc=:sp=:lc=:ec=\n:rc=' bindkey -e autoload -U compinit compinit $dump -"'zstyle ":completion:*" group-name "" +zstyle ":completion:*" group-name "" zstyle ":completion*:messages" format "%d " zstyle ":completion*:descriptions" format "%d @@ -39,7 +49,7 @@ zmodload zsh/complist expand-or-complete-with-report () { print -lr "" zle expand-or-complete - print -lr - "$LBUFFER" "$RBUFFER" + print -lr - "\$LBUFFER" "\$RBUFFER" zle clear-screen zle -R } @@ -51,6 +61,7 @@ list-choices-with-report () { } finish () { print "" + sleep 1 exit 0 } zle -N expand-or-complete-with-report @@ -59,18 +70,33 @@ zle -N finish bindkey "^I" expand-or-complete-with-report bindkey "^D" list-choices-with-report bindkey "^Z" finish -'"$code" +$code +End export PS1="" zpty zsh "$zsh" -f -zpty -r zsh log "**" +zpty -r zsh log1 "**" || { + print first prompt doesn\'t appered. + exit 1 +} -zpty -w zsh "eval ${init:q}" -zpty -r zsh log "**" +zpty -w zsh ". $tmp" +zpty -r zsh log2 "**" || { + print second prompt doesn\'t appered. + exit 1 +} +rm $tmp + +zpty -n -w zsh "$input"$'\C-Z' +zpty -r zsh log "**" || { + print finish widget doesn\'t invoked. + exit 1 +} -zpty -w zsh "$input"$'\C-Z' -zpty -r zsh log "**" +if [[ -n "$debug" ]]; then + print -lr - "$log" > /tmp/comptest.debug +fi logs=(${(s::)log}) shift logs @@ -79,16 +105,19 @@ for log in "$logs[@]"; do if [[ "$log" = (#b)*$''(*)$'\r\n'(*)$''* ]]; then print -lr "line: {$match[1]}{$match[2]}" fi - while (( ${(N)log#*(#b)(<(??)>(*)|(*)|(*))} )); do + while (( ${(N)log#*(#b)(<(??)>(*)|(*)|(*)|(*))} )); do log="${log[$mend[1]+1,-1]}" if (( 0 <= $mbegin[2] )); then if [[ $match[2] != TC && $match[3] != \ # ]]; then - print "$match[2]:{$match[3]}" + print -lr "$match[2]:{${match[3]%$termcap_ce}}" fi elif (( 0 <= $mbegin[4] )); then - print "DESCRIPTION:{$match[4]}" + print -lr "DESCRIPTION:{$match[4]}" elif (( 0 <= $mbegin[5] )); then - print "MESSAGE:{$match[5]}" + print -lr "MESSAGE:{$match[5]}" + elif (( 0 <= $mbegin[6] )); then + result=`echo $match[6] | tr -d '\012\015'` + print -lr "COMPADD:{$result}" fi done done -- cgit 1.4.1