| 1 | #!/bin/sh |
| 2 | TEST_PREFIX="[complete-compgen]" |
| 3 | . "$(cd "$(dirname "$0")" && pwd)/test_harness.sh" |
| 4 | |
| 5 | section "1. complete define" |
| 6 | check_exit "complete with -W word list" 'complete -W "start stop restart" myservice' "0" |
| 7 | check_exit "complete with -F function" 'complete -F _my_completer mycommand 2>/dev/null; true' "0" |
| 8 | check_exit "complete with -A action" 'complete -A command mytest 2>/dev/null; true' "0" |
| 9 | check_exit "complete multiple options" 'complete -W "a b" -o nospace testcmd 2>/dev/null; true' "0" |
| 10 | |
| 11 | section "2. complete list and remove" |
| 12 | check_exit "complete -p prints completions" 'complete -W "a b c" testcmd; complete -p' "0" |
| 13 | compare_output "complete -p shows defined spec" 'complete -W "alpha beta" testcmd; complete -p testcmd' |
| 14 | check_exit "complete -r removes completion" 'complete -W "a b" testcmd; complete -r testcmd' "0" |
| 15 | check_exit "complete -r nonexistent" 'complete -r nonexistent_cmd 2>/dev/null; true' "0" |
| 16 | compare_output "complete -p after -r is empty" 'complete -W "a b" testcmd; complete -r testcmd; complete -p testcmd 2>/dev/null; echo $?' |
| 17 | |
| 18 | section "3. compgen basic" |
| 19 | compare_output "compgen -W filters by prefix" 'compgen -W "start stop status" st' |
| 20 | compare_output "compgen -W no match empty output" 'compgen -W "alpha beta" z' |
| 21 | compare_output "compgen -W exact match" 'compgen -W "alpha beta gamma" alpha' |
| 22 | compare_output "compgen -W all match empty prefix" 'compgen -W "a b c"' |
| 23 | |
| 24 | section "4. compgen edge cases" |
| 25 | compare_output "compgen -W single word" 'compgen -W "only" o' |
| 26 | compare_output "compgen -W empty string" 'compgen -W "" a' |
| 27 | compare_output "compgen -W multiple matches" 'compgen -W "start stop stash status" st' |
| 28 | compare_output "compgen -W case sensitive" 'compgen -W "Alpha Beta" a' |
| 29 | compare_output "compgen -W no prefix matches all" 'compgen -W "x y z" | wc -l | tr -d " "' |
| 30 | |
| 31 | print_summary |