From 06d9708d40f74434b7a4db9efd0d01ee4a8380f6 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Wed, 26 Oct 2022 13:22:45 -0500 Subject: [PATCH] Add `complete -k` group order test Ensure that multiple `-k` completions intermixed with one or more non-`-k` completions are produced in the expected order with the order of all completions in a single `-k` completion respected, non-`-k` completions correctly sorted and interspersed, and the results of multiple `-k` completions in the reverse-intuitive order (with chronologically later completions coming before chronologically earlier `-k` counterparts), as per #9221. --- tests/pexpects/complete-group-order.py | 46 ++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/pexpects/complete-group-order.py diff --git a/tests/pexpects/complete-group-order.py b/tests/pexpects/complete-group-order.py new file mode 100644 index 000000000..cc4364bfe --- /dev/null +++ b/tests/pexpects/complete-group-order.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +from pexpect_helper import SpawnedProc + +sp = SpawnedProc() +send, sendline, sleep, expect_prompt, expect_re, expect_str = ( + sp.send, + sp.sendline, + sp.sleep, + sp.expect_prompt, + sp.expect_re, + sp.expect_str, +) + +# This test verifies the overall sort order across multiple `complete -k` completions with identical +# predicates. We check for legacy "reverse what you'd expect" order, as discussed in #9221. + +expect_prompt() +sendline("function fooc; true; end;") +expect_prompt() + +# A non-`complete -k` completion +sendline('complete -c fooc -fa "alpha delta bravo"') +expect_prompt() + +# A `complete -k` completion chronologically and alphabetically before the next completion. You'd +# expect it to come first, but we documented that it will come second. +sendline('complete -c fooc -fka "golf charlie echo"') +expect_prompt() + +# A `complete -k` completion that is chronologically after and alphabetically after the previous +# one, so a naive sort would place it after but we want to make sure it comes before. +sendline('complete -c fooc -fka "india foxtrot hotel"') +expect_prompt() + +# Another non-`complete -k` completion +sendline('complete -c fooc -fa "kilo juliett lima"') +expect_prompt() + +sendline("set TERM xterm") +expect_prompt() + +# Generate completions +send('fooc \t') + +expect_re("alpha\W+india\W+hotel\W+charlie\W+echo\W+kilo\r\n" ++ "bravo\W+foxtrot\W+golf\W+delta\W+juliett\W+lima")