From 2d51522fef90e7f8ef58826ce088591dbe87a207 Mon Sep 17 00:00:00 2001 From: rsteube Date: Mon, 20 Jan 2025 18:00:32 +0100 Subject: [PATCH] special: added verification --- action_test.go | 4 ---- .../development/vhs/word/out/word.xonsh.ascii | 4 ++-- example/_test/invoke_bash | 10 ---------- example/_test/invoke_elvish | 12 ------------ example/_test/invoke_fish | 3 --- example/_test/invoke_oil | 18 ------------------ example/_test/invoke_powershell | 4 ---- example/_test/invoke_xonsh | 18 ------------------ example/_test/invoke_zsh | 1 - example/cmd/special.go | 17 +++++++++++++++-- 10 files changed, 17 insertions(+), 74 deletions(-) delete mode 100755 example/_test/invoke_bash delete mode 100755 example/_test/invoke_elvish delete mode 100755 example/_test/invoke_fish delete mode 100755 example/_test/invoke_oil delete mode 100755 example/_test/invoke_powershell delete mode 100755 example/_test/invoke_xonsh delete mode 120000 example/_test/invoke_zsh diff --git a/action_test.go b/action_test.go index d4dd69138..d2d56107a 100644 --- a/action_test.go +++ b/action_test.go @@ -155,10 +155,8 @@ func TestActionDirectories(t *testing.T) { assertEqual(t, ActionStyledValues( - "_test/", style.Of(style.Blue, style.Bold), "cmd/", style.Of(style.Blue, style.Bold), ).NoSpace('/').Tag("directories").Invoke(Context{}).Prefix("example/").UidF(uid.Map( - "example/_test/", "file://"+wd("")+"/example/_test/", "example/cmd/", "file://"+wd("")+"/example/cmd/", )), ActionDirectories().Invoke(Context{Value: "example/"}), @@ -199,13 +197,11 @@ func TestActionFiles(t *testing.T) { assertEqual(t, ActionStyledValues( "README.md", style.Default, - "_test/", style.Of(style.Blue, style.Bold), "cmd/", style.Of(style.Blue, style.Bold), "main.go", style.Default, "main_test.go", style.Default, ).NoSpace('/').Tag("files").Invoke(Context{}).Prefix("example/").UidF(uid.Map( "example/README.md", "file://"+wd("example")+"/README.md", - "example/_test/", "file://"+wd("example")+"/_test/", "example/cmd/", "file://"+wd("example")+"/cmd/", "example/main.go", "file://"+wd("example")+"/main.go", "example/main_test.go", "file://"+wd("example")+"/main_test.go", diff --git a/docs/src/development/vhs/word/out/word.xonsh.ascii b/docs/src/development/vhs/word/out/word.xonsh.ascii index 9043ef6b6..00982b242 100644 --- a/docs/src/development/vhs/word/out/word.xonsh.ascii +++ b/docs/src/development/vhs/word/out/word.xonsh.ascii @@ -6,7 +6,7 @@ ──────────────────────────────────────────────────────────────────────────────── -> example >/dev/null +> example @@ -14,7 +14,7 @@ ──────────────────────────────────────────────────────────────────────────────── -> example >/dev/null +> example diff --git a/example/_test/invoke_bash b/example/_test/invoke_bash deleted file mode 100755 index f5c488908..000000000 --- a/example/_test/invoke_bash +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -i -#set -x -source <(example _carapace bash) -COMP_LINE="$1" -COMP_POINT=${#1} -COMP_WORDS=($COMP_LINE'') -COMP_CWORD=$((${#COMP_WORDS[@]}-1)) - -_example_completion -( IFS=$'\n'; echo "${COMPREPLY[*]}" ) diff --git a/example/_test/invoke_elvish b/example/_test/invoke_elvish deleted file mode 100755 index 566b93acf..000000000 --- a/example/_test/invoke_elvish +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/expect -set timeout 10 -set CMDLINE [lindex $argv 0] -log_user 0 -match_max -d 5000 -spawn elvish -norc -send "eval (example _carapace elvish|slurp);echo EXPECT_START; \$edit:completion:arg-completer\[example\] $CMDLINE'' | each {|c| echo \$c }; echo EXPECT_END" -send "\r" -expect -re "EXPECT_START\r\n(.*?)EXPECT_END" -puts "$expect_out(1,string)" -send "exit\r" -expect eof diff --git a/example/_test/invoke_fish b/example/_test/invoke_fish deleted file mode 100755 index ac19b4b61..000000000 --- a/example/_test/invoke_fish +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/fish -example _carapace fish|source -complete --do-complete="$argv" diff --git a/example/_test/invoke_oil b/example/_test/invoke_oil deleted file mode 100755 index 77688ab24..000000000 --- a/example/_test/invoke_oil +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env osh -# TODO not yet working so just hardcode the function -# source <(example _carapace oil) -_example_completion() { - local compline="${COMP_LINE:0:${COMP_POINT}}" - local IFS=$'\n' - mapfile -t COMPREPLY < <(echo "$compline" | sed -e "s/ \$/ ''/" -e 's/"/\"/g' | xargs example _carapace oil) - [[ "${COMPREPLY[@]}" == "" ]] && COMPREPLY=() # fix for mapfile creating a non-empty array from empty command output - [[ ${COMPREPLY[0]} == *[/=@:.,] ]] && compopt -o nospace -} - - COMP_LINE="$1" - COMP_POINT=${#1} - COMP_WORDS=($COMP_LINE'') - COMP_CWORD=$((${#COMP_WORDS[@]}-1)) - - _example_completion - ( IFS=$'\n'; echo "${COMPREPLY[*]}" ) diff --git a/example/_test/invoke_powershell b/example/_test/invoke_powershell deleted file mode 100755 index 1350d2332..000000000 --- a/example/_test/invoke_powershell +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/pwsh - -example _carapace powershell | out-string | invoke-expression -[System.Management.Automation.CommandCompletion]::CompleteInput("$($args[0])", $args[0].length, $null).CompletionMatches diff --git a/example/_test/invoke_xonsh b/example/_test/invoke_xonsh deleted file mode 100755 index 7f1267c98..000000000 --- a/example/_test/invoke_xonsh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/expect -set timeout 10 -set CMDLINE [lindex $argv 0] -log_user 0 -match_max -d 5000 - -# prevent banner by creating a fake .xonshrc -set ::env(HOME) /tmp/carapace-fakehome -spawn mkdir /tmp/carapace-fakehome -spawn touch /tmp/carapace-fakehome/.xonshrc - -spawn xonsh -i --shell-type dumb -send "exec(\$(example _carapace xonsh)); from xonsh.parsers.completion_context import *; echo EXPECT_START;_example_completer(CompletionContextParser().parse('$CMDLINE', len('$CMDLINE'), None)); echo EXPECT_END" -send "\r" -expect -re "EXPECT_START\r\n(.*?)EXPECT_END" -puts "$expect_out(1,string)" -send "exit\r" -expect eof diff --git a/example/_test/invoke_zsh b/example/_test/invoke_zsh deleted file mode 120000 index aba33ac36..000000000 --- a/example/_test/invoke_zsh +++ /dev/null @@ -1 +0,0 @@ -../../third_party/github.com/Valodim/zsh-capture-completion/capture.zsh \ No newline at end of file diff --git a/example/cmd/special.go b/example/cmd/special.go index 786f15671..3957d7e4e 100644 --- a/example/cmd/special.go +++ b/example/cmd/special.go @@ -1,14 +1,27 @@ package cmd import ( + "fmt" + "os" + "github.com/carapace-sh/carapace" "github.com/spf13/cobra" ) +var special = `p1 & < > ' " { } $ # | ? ( ) ; [ ] * \ $() ${} ` + "` ``" + var specialCmd = &cobra.Command{ Use: "special", Short: "", - Run: func(cmd *cobra.Command, args []string) {}, + Run: func(cmd *cobra.Command, args []string) { + if len(args) > 0 && args[0] != special { + fmt.Printf("expected: %#v\n", special) + fmt.Printf("actual : %#v\n", args[0]) + os.Exit(1) + } else { + fmt.Println("ok") + } + }, } func init() { @@ -30,6 +43,6 @@ func init() { }) carapace.Gen(specialCmd).PositionalCompletion( - carapace.ActionValues(`p1 & < > ' " { } $ # | ? ( ) ; [ ] * \ `+"`", "positional1"), + carapace.ActionValues(special), ) }