From 92d966a491537c70737c4edeaca7943b0f858af6 Mon Sep 17 00:00:00 2001 From: rsteube Date: Fri, 8 Sep 2023 23:18:27 +0200 Subject: [PATCH] flag modifier test --- example/flag.yaml | 11 +++++++++++ flag_test.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 example/flag.yaml diff --git a/example/flag.yaml b/example/flag.yaml new file mode 100644 index 0000000..a99617d --- /dev/null +++ b/example/flag.yaml @@ -0,0 +1,11 @@ +name: flag +flags: + --hidden&: hidden + --hidden-arg&=: hidden with argument + --hidden-opt&?: hidden with optional argument + --repeatable*: repeatable + --required!: required +completion: + flag: + hidden-arg: [h1, h2] + hidden-opt: [ho1, ho2] diff --git a/flag_test.go b/flag_test.go index 91d1a4e..f3ed21d 100644 --- a/flag_test.go +++ b/flag_test.go @@ -1,9 +1,12 @@ package spec import ( + _ "embed" "reflect" "testing" + "github.com/rsteube/carapace" + "github.com/rsteube/carapace/pkg/sandbox" "github.com/spf13/pflag" ) @@ -119,3 +122,33 @@ func TestParseFlag(t *testing.T) { nameAsShorthand: false, }) } + +//go:embed example/flag.yaml +var flagSpec string + +func TestFlag(t *testing.T) { + sandboxSpec(t, flagSpec)(func(s *sandbox.Sandbox) { + s.Run("--hidden"). + Expect(carapace.ActionValues(). + NoSpace('.')) + + s.Run("--hidden-arg", ""). + Expect(carapace.ActionValues( + "h1", + "h2", + ).Usage("hidden with argument")) + + s.Run("--hidden-opt="). + Expect(carapace.ActionValues( + "ho1", + "ho2", + ).Prefix("--hidden-opt="). + Usage("hidden with optional argument")) + + s.Run("--repeatable", "--repeat"). + Expect(carapace.ActionValuesDescribed( + "--repeatable", "repeatable", + ).NoSpace('.'). + Tag("flags")) + }) +}