1 # Tests for completion system matching control
3 # Most tests follow this format:
4 # test_code $matcher_string selection_list
5 # comptest -c "$code" $' tst input_string'
6 # test_code generates the string $codem which sets what words the completion
7 # should be selecting from. The comptest function actually performs the
8 # completion test, using the completion function generated by test_code.
10 # This test also tests error conditions that compadd reports, so output also
11 # contains the compadd output.
14 if ( zmodload -i zsh/zpty ) >/dev/null 2>&1; then
15 . $ZTST_srcdir/comptest
18 comptestinit -z $ZTST_testdir/../Src/zsh &&
20 list1=(IndianRed IndianRed2 IndianRed3 IndianRed4)
24 code="compdef _tst tst ; _tst () { echo -n '<COMPADD>';compadd -M '"
26 code="$code' - ${(P)list} ; echo -n '</COMPADD>'"
27 code="$code; $extra_cmd"
28 code="$code; echo -n '<INSERT_POSITIONS>'"
29 code="$code; echo \$compstate[insert_positions]"
30 code="$code; echo -n '</INSERT_POSITIONS>'"
36 ZTST_unimplemented="the zsh/zpty module is not available"
44 0:Match Error for "z:"
46 >COMPADD:{_tst:compadd: unknown match specification character `z'}
51 0:Match Error for "m:"
53 >COMPADD:{_tst:compadd: missing patterns}
58 0:Match Error for "M:"
60 >COMPADD:{_tst:compadd: missing patterns}
67 >COMPADD:{_tst:compadd: missing patterns}
74 >COMPADD:{_tst:compadd: missing patterns}
79 0:Match Error for "l:"
81 >COMPADD:{_tst:compadd: missing patterns}
86 0:Match Error for "L:"
88 >COMPADD:{_tst:compadd: missing patterns}
91 test_code 'm:{0-9' list1
93 0:Match Error for "m:{0-9"
95 >COMPADD:{_tst:compadd: unterminated character class}
98 test_code 'm:{0-9}' list1
100 0:Match Error for "m:{0-9}"
102 >COMPADD:{_tst:compadd: missing word pattern}
105 test_code 'm:{0-9}={' list1
107 0:Match Error for "m:{0-9}={"
109 >COMPADD:{_tst:compadd: unterminated character class}
112 test_code 'm:{0-9}={0-' list1
114 0:Match Error for "m:{0-9}={0-"
116 >COMPADD:{_tst:compadd: unterminated character class}
119 test_code 'm:{0-9}={-' list1
121 0:Match Error for "m:{0-9}={-"
123 >COMPADD:{_tst:compadd: unterminated character class}
130 >COMPADD:{_tst:compadd: missing patterns}
134 kshoptionprint shglob
135 listambiguous shinstdin
137 listpacked shoptionletters
138 listrowsfirst shortloops
139 listtypes shwordsplit
141 options_matcher='L:|[nN][oO]= M:_= M:{A-Z}={a-z}'
142 test_code $options_matcher example1_list
143 comptest $'tst nolistbee\t'
144 0:Documentation example for options, input "nolistbee"
145 >line: {tst nolistbeep }{}
147 >INSERT_POSITIONS:{14}
150 test_code $options_matcher example1_list
151 comptest $'tst list_bee\t'
152 0:Documentation example for options, input "list_bee"
153 >line: {tst list_beep }{}
155 >INSERT_POSITIONS:{13}
157 test_code $options_matcher example1_list
158 comptest $'tst ListBee\t'
159 0:Documentation example for options, input "ListBee"
160 >line: {tst ListBeep }{}
162 >INSERT_POSITIONS:{12}
164 test_code $options_matcher example1_list
165 comptest $'tst NOList\tB\t'
166 0:Documentation example for options, input "NOList"
167 >line: {tst NOList}{}
169 >INSERT_POSITIONS:{10}
170 >NO:{NOListambiguous}
173 >NO:{NOListrowsfirst}
175 >line: {tst NOListBeep }{}
177 >INSERT_POSITIONS:{14}
180 test_code $options_matcher example1_list
181 comptest $'tst NO_List\t__\tB\t'
182 0:Documentation example for options, input "NO_List\t__\tB\t"
183 >line: {tst NO_List}{}
185 >INSERT_POSITIONS:{11}
186 >NO:{NO_Listambiguous}
189 >NO:{NO_Listrowsfirst}
191 >line: {tst NO_List__}{}
193 >INSERT_POSITIONS:{13}
194 >NO:{NO_List__ambiguous}
196 >NO:{NO_List__packed}
197 >NO:{NO_List__rowsfirst}
199 >line: {tst NO_List__Beep }{}
201 >INSERT_POSITIONS:{17}
203 test_code $options_matcher example1_list
204 comptest $'tst __\tN\t__o\t___\tlist_\tbeep__\t'
205 0:Documentation example for options, input "__\tN\t__o\t___\tlist_\tbeep__\t"
208 >INSERT_POSITIONS:{6}
209 >NO:{__kshoptionprint}
210 >NO:{__listambiguous}
213 >NO:{__listrowsfirst}
218 >NO:{__shoptionletters}
224 >line: {tst __N__o}{}
227 >line: {tst __N__o___}{}
230 >line: {tst __N__o___list_}{}
233 >line: {tst __N__o___list_beep__}{}
237 test_code $options_matcher example1_list
238 comptest $'tst __\tNo\t___\tlist_\tbeep__\t'
239 0:Documentation example for options, input "__\tNo\t___\tlist_\tbeep__\t"
242 >INSERT_POSITIONS:{6}
243 >NO:{__kshoptionprint}
244 >NO:{__listambiguous}
247 >NO:{__listrowsfirst}
252 >NO:{__shoptionletters}
258 >line: {tst __No___}{}
261 >line: {tst __No___list_}{}
264 >line: {tst __No___list_beep__}{}
269 test_code $options_matcher example1_list
270 comptest $'tst ___\tlist_\tbeep__\t'
271 0:Documentation example for options, input "___\tlist_\tbeep__\t"
274 >INSERT_POSITIONS:{7}
275 >NO:{___kshoptionprint}
276 >NO:{___listambiguous}
279 >NO:{___listrowsfirst}
284 >NO:{___shoptionletters}
287 >line: {tst ___list_}{}
289 >INSERT_POSITIONS:{12}
290 >NO:{___list_ambiguous}
293 >NO:{___list_rowsfirst}
295 >line: {tst ___list_beep__ }{}
297 >INSERT_POSITIONS:{18}
299 test_code 'B:[nN][oO]= M:_= M:{A-Z}={a-z}' example1_list
300 comptest $'tst __no_listbe\t'
301 0:Documentation example for options, input "__no_listbe"
302 >line: {tst __no_listbeep }{}
304 >INSERT_POSITIONS:{17}
306 test_code 'B:[nN][oO]= M:_= M:{A-Z}={a-z}' example1_list
307 comptest $'tst nonono_listbe\t'
308 0:Documentation example for options, input "nonono_listbe"
309 >line: {tst nonono_listbeep }{}
311 >INSERT_POSITIONS:{19}
313 lower_insensitive_M="M:{a-z}={A-Z}"
314 lower_insensitive_m="m:{a-z}={A-Z}"
315 example2_list=(ABC Abc abc)
316 test_code $lower_insensitive_M example2_list
317 comptest $'tst ab\tC\t'
318 0:Documentation example for lowercase insenitive M, input "ab\tC\t"
321 >INSERT_POSITIONS:{6}
326 >INSERT_POSITIONS:{7}
328 test_code $lower_insensitive_m example2_list
329 comptest $'tst A\t\t'
330 0:Documentation example for lowercase insenitive m, input "A\t\t"
333 >INSERT_POSITIONS:{5}
338 >INSERT_POSITIONS:{5}
340 example3_list=(ABC Abc abc)
341 case_insensitive_M="M:{a-zA-Z}={A-Za-z}"
342 case_insensitive_m="m:{a-zA-Z}={A-Za-z}"
343 test_code $case_insensitive_M example3_list
344 comptest $'tst aB\t\t'
345 0:Documentation example for case insenitive M, input "aB\t\t"
348 >INSERT_POSITIONS:{6}
353 >INSERT_POSITIONS:{6}
356 test_code $case_insensitive_m example3_list
357 comptest $'tst aB\t\t'
358 0:Documentation example for case insenitive m, input "aB\t\t"
361 >INSERT_POSITIONS:{5:7}
364 >INSERT_POSITIONS:{5:7}
369 example4_matcher='r:|.=* r:|=*'
370 example4_list=(comp.sources.unix comp.sources.misc
371 comp.graphics.algorithms comp.graphics.animation comp.graphics.api
372 comp.graphics.apps comp.graphics.misc comp.graphics.packages
373 comp.graphics.rendering comp.graphics.visualization comp.graphics.apps.alias
374 comp.graphics.apps.gimp comp.graphics.apps.gnuplot
375 comp.graphics.apps.lightwave comp.graphics.apps.pagemaker
376 comp.graphics.apps.paint-shop-pro comp.graphics.apps.photoshop
377 comp.graphics.apps.softimage comp.graphics.apps.ulead
378 comp.graphics.rendering.misc comp.graphics.rendering.raytracing
379 comp.graphics.rendering.renderman)
380 test_code $example4_matcher example4_list
381 comptest $'tst c.s.u\t'
382 0:Documentation example using input c.s.u
383 >line: {tst comp.sources.unix }{}
385 >INSERT_POSITIONS:{21}
387 test_code $example4_matcher example4_list
388 comptest $'tst c.g.\ta\t.\tp\ta\tg\t'
389 0:Documentation example using input c.g.\ta\t.\tp\ta\tg\t
390 >line: {tst comp.graphics.}{}
392 >INSERT_POSITIONS:{18}
393 >line: {tst comp.graphics.a}{}
395 >INSERT_POSITIONS:{19}
396 >NO:{comp.graphics.algorithms}
397 >NO:{comp.graphics.animation}
398 >NO:{comp.graphics.api}
399 >NO:{comp.graphics.apps}
400 >NO:{comp.graphics.apps.alias}
401 >NO:{comp.graphics.apps.gimp}
402 >NO:{comp.graphics.apps.gnuplot}
403 >NO:{comp.graphics.apps.lightwave}
404 >NO:{comp.graphics.apps.pagemaker}
405 >NO:{comp.graphics.apps.paint-shop-pro}
406 >NO:{comp.graphics.apps.photoshop}
407 >NO:{comp.graphics.apps.softimage}
408 >NO:{comp.graphics.apps.ulead}
409 >line: {tst comp.graphics.apps.}{}
411 >INSERT_POSITIONS:{23}
412 >line: {tst comp.graphics.apps.p}{}
414 >INSERT_POSITIONS:{24}
415 >NO:{comp.graphics.apps.pagemaker}
416 >NO:{comp.graphics.apps.paint-shop-pro}
417 >NO:{comp.graphics.apps.photoshop}
418 >line: {tst comp.graphics.apps.pa}{}
420 >INSERT_POSITIONS:{25}
421 >NO:{comp.graphics.apps.pagemaker}
422 >NO:{comp.graphics.apps.paint-shop-pro}
423 >line: {tst comp.graphics.apps.pagemaker }{}
425 >INSERT_POSITIONS:{32}
427 test_code $example4_matcher example4_list
428 comptest $'tst c...pag\t'
429 0:Documentation example using input c...pag\t
430 >line: {tst comp.graphics.apps.pagemaker }{}
432 >INSERT_POSITIONS:{32}
434 test_code $example4_matcher example4_list
435 comptest $'tst c...pa\tg\t'
436 0:Documentation example using input c...pa\tg\t
437 >line: {tst comp.graphics.apps.pa}{}
439 >INSERT_POSITIONS:{25}
440 >line: {tst comp.graphics.apps.pagemaker }{}
442 >INSERT_POSITIONS:{32}
444 example5_matcher='r:|[.,_-]=* r:|=*'
445 example5_list=(veryverylongfile.c veryverylongheader.h)
446 test_code $example5_matcher example5_list
447 comptest $'tst v.c\tv.h\t'
448 0:Documentation example using input v.c\t
449 >line: {tst veryverylongfile.c }{}
451 >INSERT_POSITIONS:{23}
452 >line: {tst veryverylongfile.c veryverylongheader.h }{}
454 >INSERT_POSITIONS:{44}
457 example6_list=(LikeTHIS FooHoo 5foo123 5bar234)
458 test_code 'r:|[A-Z0-9]=* r:|=*' example6_list
460 0:Documentation example using "r:|[A-Z0-9]=* r:|=*", input H
465 test_code 'r:|[A-Z0-9]=* r:|=*' example6_list
467 0:Documentation example using "r:|[A-Z0-9]=* r:|=*", input 2
472 test_code 'r:|[A-Z0-9]=** r:|=*' example6_list
474 0:Documentation example using "r:|[A-Z0-9]=** r:|=*", input H
477 >INSERT_POSITIONS:{4}
481 test_code 'r:|[A-Z0-9]=** r:|=*' example6_list
482 comptest $'tst 2\t\t'
483 0:Documentation example using "r:|[A-Z0-9]=** r:|=*", input 2
486 >INSERT_POSITIONS:{5:7}
489 >INSERT_POSITIONS:{5:7}
493 example7_matcher="r:[^A-Z0-9]||[A-Z0-9]=** r:|=*"
494 example7_list=($example6_list)
495 test_code $example7_matcher example7_list
496 comptest $'tst H\t2\t'
497 0:Documentation example using "r:[^A-Z0-9]||[A-Z0-9]=** r:|=*"
498 >line: {tst FooHoo }{}
500 >INSERT_POSITIONS:{10}
501 >line: {tst FooHoo 5bar234 }{}
503 >INSERT_POSITIONS:{18}
506 workers_7311_matcher="m:{a-z}={A-Z} r:|[.,_-]=* r:|=*"
507 workers_7311_list=(Abc-Def-Ghij.txt Abc-def.ghi.jkl_mno.pqr.txt Abc_def_ghi_jkl_mno_pqr.txt)
508 test_code $workers_7311_matcher workers_7311_list
509 comptest $'tst a-a\t'
510 0:Bug from workers 7311
515 test_code $workers_7311_matcher workers_7311_list
516 comptest $'tst a\t\t-d.\t'
517 0:Bug from workers_7311
520 >INSERT_POSITIONS:{7}
523 >INSERT_POSITIONS:{7}
524 >NO:{Abc-Def-Ghij.txt}
525 >NO:{Abc-def.ghi.jkl_mno.pqr.txt}
526 >NO:{Abc_def_ghi_jkl_mno_pqr.txt}
527 >line: {tst Abc-def.ghi.jkl_mno.pqr.txt }{}
529 >INSERT_POSITIONS:{31}
531 workers_10886_matcher="r:|[A-Z0-9]=* r:|=*"
532 workers_10886_list=(BW UWB W)
533 test_code $workers_10886_matcher workers_10886_list
535 0:Bug from workers 10886
538 >INSERT_POSITIONS:{5}
540 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:|=*'
541 workers_11081_list=(build.out build.out1 build.out2)
542 test_code $workers_11081_matcher workers_11081_list
543 comptest $'tst bui\t\t\t'
544 0:Bug from workers 11081
545 >line: {tst build.out}{}
547 >INSERT_POSITIONS:{13}
548 >line: {tst build.out}{}
550 >INSERT_POSITIONS:{13}
554 >line: {tst build.out}{}
556 >INSERT_POSITIONS:{13}
559 workers_11388_matcher='r:|[:.]=* r:|=*'
560 workers_11388_list=(a.b:0 c.d:1)
561 test_code $workers_11388_matcher workers_11388_list
563 0:Non-bug from workers 11388
568 workers_11388_matcher='r:|[:.]=** r:|=*'
569 workers_11388_list=(a.b:0 c.d:1)
570 test_code $workers_11388_matcher workers_11388_list
572 0:Non-bug from workers 11388
575 >INSERT_POSITIONS:{4:5:6}
577 workers_11586_matcher='r:|.=** r:[^0-9]||[0-9]=**'
578 workers_11586_list=(c00.abc c01.abc.def.00.0)
579 test_code $workers_11586_matcher workers_11586_list
580 comptest $'tst c00\t.\ta\t'
581 0:Bug from workers 11586
584 >INSERT_POSITIONS:{6}
586 >NO:{c01.abc.def.00.0}
589 >INSERT_POSITIONS:{7:8}
591 >NO:{c01.abc.def.00.0}
592 >line: {tst c00.abc }{}
594 >INSERT_POSITIONS:{11}
596 workers_12995a_matcher='r:|/=* r:|=*'
597 workers_12995a_list=(u1 u1/q1 u1/q1/e1 u2 u2/q1 u2/q1/e2 u2/q1/e2/a1 u2/q1/e2/a2 u3 u3/q1 u4 u4/q u4/q/a1 u4/q/a2)
598 test_code $workers_12995a_matcher workers_12995a_list
599 comptest $'tst u/q/a\t'
600 0:First test from workers 12995
601 >line: {tst u4/q/a}{}
603 >INSERT_POSITIONS:{10}
605 workers_12995b_matcher='m:{a-z}={A-Z} r:|/=* r:|=*'
606 workers_12995b_list=(../Completion/Core ../Completion/Commands)
607 test_code $workers_12995b_matcher workers_12995b_list
608 comptest $'tst ../com/cor\002\002\002\002\002\002\002\t'
609 0:Second test from workers 12995
610 >line: {tst ../Completion/Core }{}
612 >INSERT_POSITIONS:{22}
614 workers_13320_matcher='r:|[.,_-]=** r:[^0-9]||[0-9]=**'
615 workers_13320_list=(glibc-2.1.94-3.i386.rpm glibc-devel-2.1.94-3.i386.rpm)
616 workers_13320_list=($workers_13320_list glibc-profile-2.1.94-3.i386.rpm)
617 test_code $workers_13320_matcher workers_13320_list
618 comptest $'tst glibc-2.1\t'
619 0:Test from workers 13320
620 >line: {tst glibc}{-2.1.94-3.i386.rpm}
622 >INSERT_POSITIONS:{9:27}
624 test_code $workers_13320_matcher workers_13320_list
625 comptest $'tst g-2\t'
626 0:Test from workers 13320
627 >line: {tst glibc}{-2.1.94-3.i386.rpm}
629 >INSERT_POSITIONS:{9:27}
631 workers_13345a_matcher='r:|[.,_-]=**'
632 workers_13345a_list=(A.B.C A.B.C.D A.C)
633 test_code $workers_13345a_matcher workers_13345a_list
634 comptest $'tst A.C\t'
635 0:First test from workers 13345
638 >INSERT_POSITIONS:{5:7}
644 workers_13345b_matcher='r:|[.,_-]=** r:[^0-9]||[0-9]=**'
645 workers_13345b_list=(a-b_1_2_2 a-b_2_0.gz a-b_2_0.zip)
646 test_code $workers_13345b_matcher workers_13345b_list
647 comptest $'tst a-b_2\t'
648 0:Second test from workers 13345
649 >line: {tst a-b_2_}{}
651 >INSERT_POSITIONS:{8:10}
653 workers_13382_matcher='r:|.=**'
654 workers_13382_list=(a.b.c a.b.c.d aA.bB.cB.dA aA.bB.cC.dD aD.bC.cB.dA aA.bC.cB.dA)
655 test_code $workers_13382_matcher workers_13382_list
656 comptest $'tst a...\tA\tC\t'
657 0:Test for insert positions
658 >line: {tst a.b.c.d}{}
660 >INSERT_POSITIONS:{5:7:9:11}
661 >line: {tst a.b}{.cB.dA}
663 >INSERT_POSITIONS:{5:7:13}
664 >line: {tst a}{.bC.cB.dA}
666 >INSERT_POSITIONS:{5:14}
670 users_12227_matcher='r:|[-./_]=* r:|=* l:|=*'
671 users_12227_list=(foo-bar-abc foo-bar-def foo-bar-ghi)
672 test_code $users_12227_matcher users_12227_list
673 comptest $'tst bar\t'
674 0:Test for wildcard left anchor with partial word right anchors
675 >line: {tst foo-bar-}{}
677 >INSERT_POSITIONS:{12}
681 zmodload -ui zsh/zpty