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