spf13--cobra/zsh_completions_test.go
Cornelius Weig 410fe1a254 Derive zsh completion from bash completion
This is a temporary fix to get some zsh completion. The idea is taken from kubectl where the bash completion script is wrapped with some zsh adapter code. The zsh magic is taken from kubectl.
2019-02-23 01:03:47 +01:00

35 lines
619 B
Go

package cobra
import (
"bytes"
"strings"
"testing"
)
const (
expectedTail = `BASH_COMPLETION_EOF
}
__cobra_bash_source <(__trivialapp_convert_bash_to_zsh)
_complete trivialapp 2>/dev/null
`
expectedHead = `#compdef trivialapp`
)
func TestZshCompletion(t *testing.T) {
root := &Command{Use: "trivialapp"}
buf := &bytes.Buffer{}
err := root.GenZshCompletion(buf)
if err != nil {
t.Errorf("Unexpected error: %s", err)
}
actual := buf.String()
if !strings.HasPrefix(actual, expectedHead) {
t.Error("Unexpected head")
}
if !strings.HasSuffix(actual, expectedTail) {
t.Error("Unexpected tail")
}
}