Skip to content
Myr

test-complete

This file

Path

ci/test-complete

88 lines · 2.8 KiB

Last changed by

test-complete: misc. improvementsdanabefore adoption2394f72

History of this file

Take it

The walk stopped after 200 commits: lines older than 5f5da48 point at it.

globset: support nested alternatesLuke Sandbergbefore adoption5f5da48

lines 1–2why, one step back
1#!/usr/bin/env zsh
2

test-complete: misc. improvementsdanabefore adoption2394f72

line 3why, one step back
3emulate zsh -o extended_glob -o no_unset -o warn_create_global

globset: support nested alternatesLuke Sandbergbefore adoption5f5da48

lines 4–20why, one step back
4
5##6# Compares options in `rg --help` output to options in zsh completion function78get_comp_args() {9 # Technically there are many options that the completion system sets that10 # our function may rely on, but we'll trust that we've got it mostly right11 setopt local_options unset1213 # Our completion function recognises a special variable which tells it to14 # dump the _arguments specs and then just return. But do this in a sub-shell15 # anyway to avoid any weirdness16 ( _RG_COMPLETE_LIST_ARGS=1 source $1 )17}1819main() {20 local diff

test-complete: misc. improvementsdanabefore adoption2394f72

lines 21–22why, one step back
21 local rg=${ZSH_ARGZERO:a:h}/../${TARGET_DIR:-target}/release/rg
22 local _rg=${ZSH_ARGZERO:a:h}/../crates/core/flags/complete/rg.zsh

globset: support nested alternatesLuke Sandbergbefore adoption5f5da48

lines 23–30why, one step back
23 local -a help_args comp_args
2425 [[ -e $rg ]] || rg=${rg/%\/release\/rg/\/debug\/rg}2627 rg=${rg:a}28 _rg=${_rg:a}2930 [[ -e $rg ]] || {

test-complete: misc. improvementsdanabefore adoption2394f72

line 31why, one step back
31 print -ru2 - "${ZSH_ARGZERO:t}: rg not found: $rg"

globset: support nested alternatesLuke Sandbergbefore adoption5f5da48

lines 32–34why, one step back
32 return 1
33 }34 [[ -e $_rg ]] || {

test-complete: misc. improvementsdanabefore adoption2394f72

line 35why, one step back
35 print -ru2 - "${ZSH_ARGZERO:t}: _rg not found: $_rg"

globset: support nested alternatesLuke Sandbergbefore adoption5f5da48

lines 36–48why, one step back
36 return 1
37 }3839 print -rl - 'Comparing options:' "-$rg" "+$_rg"4041 # 'Parse' options out of the `--help` output. To prevent false positives we42 # only look at lines where the first non-white-space character is `-`, or43 # where a long option starting with certain letters (see `_rg`) is found.44 # Occasionally we may have to handle some manually, however45 help_args=( ${(f)"$(46 $rg --help |47 $rg -i -- '^\s+--?[a-z0-9.]|--[a-z]' |48 $rg -ior '$1' -- $'[\t /\"\'`.,](-[a-z0-9.]|--[a-z0-9-]+)(,|\\b)' |

test-complete: misc. improvementsdanabefore adoption2394f72

line 49why, one step back
49 $rg -vw -- --print0 # False positives

globset: support nested alternatesLuke Sandbergbefore adoption5f5da48

line 50why, one step back
50 )"} )

test-complete: misc. improvementsdanabefore adoption2394f72

line 51why, one step back
51 help_args=( ${(ou)help_args} )

globset: support nested alternatesLuke Sandbergbefore adoption5f5da48

lines 52–54why, one step back
52
53 # 'Parse' options out of the completion function54 comp_args=( ${(f)"$( get_comp_args $_rg )"} )

test-complete: misc. improvementsdanabefore adoption2394f72

line 55why, one step back
55 comp_args=( ${comp_args#\!} ) # Strip hidden indicator

globset: support nested alternatesLuke Sandbergbefore adoption5f5da48

lines 56–60why, one step back
56 comp_args=( ${comp_args#\(*\)} ) # Strip excluded options
57 comp_args=( ${comp_args#\*} ) # Strip repetition indicator58 comp_args=( ${comp_args%%-[:[]*} ) # Strip everything after -optname-59 comp_args=( ${comp_args%%[:+=[]*} ) # Strip everything after other optspecs60 comp_args=( ${comp_args##[^-]*} ) # Remove non-options

test-complete: misc. improvementsdanabefore adoption2394f72

line 61why, one step back
61 comp_args=( ${(ou)comp_args} )

globset: support nested alternatesLuke Sandbergbefore adoption5f5da48

lines 62–63why, one step back
62
63 (( $#help_args )) || {

test-complete: misc. improvementsdanabefore adoption2394f72

line 64why, one step back
64 print -ru2 - "${ZSH_ARGZERO:t}: Failed to get help_args"

globset: support nested alternatesLuke Sandbergbefore adoption5f5da48

lines 65–67why, one step back
65 return 1
66 }67 (( $#comp_args )) || {

test-complete: misc. improvementsdanabefore adoption2394f72

line 68why, one step back
68 print -ru2 - "${ZSH_ARGZERO:t}: Failed to get comp_args"

globset: support nested alternatesLuke Sandbergbefore adoption5f5da48

lines 69–71why, one step back
69 return 1
70 }71

test-complete: misc. improvementsdanabefore adoption2394f72

lines 72–77why, one step back
72 diff=$(
73 diff -U2 \74 -L 'rg --help' \75 -L '_rg' \76 =( print -rl - $help_args ) =( print -rl - $comp_args )77 )

globset: support nested alternatesLuke Sandbergbefore adoption5f5da48

lines 78–79why, one step back
78
79 (( $#diff )) && {

test-complete: misc. improvementsdanabefore adoption2394f72

lines 80–81why, one step back
80 print -ru2 - "${ZSH_ARGZERO:t}: zsh completion options differ from --help options:"
81 print -rlu2 - $diff

globset: support nested alternatesLuke Sandbergbefore adoption5f5da48

lines 82–83why, one step back
82 return 1
83 }

test-complete: misc. improvementsdanabefore adoption2394f72

line 84why, one step back
84 print -r - OK

globset: support nested alternatesLuke Sandbergbefore adoption5f5da48

lines 85–88why, one step back
85 return 0
86}8788main "$@"