Skip to content

Commit

Permalink
Merge pull request #215 from rsteube/flag-modifier
Browse files Browse the repository at this point in the history
flag modifier test
  • Loading branch information
rsteube authored Sep 8, 2023
2 parents e526514 + 92d966a commit 5e2dc17
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
11 changes: 11 additions & 0 deletions example/flag.yaml
Original file line number Diff line number Diff line change
@@ -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]
33 changes: 33 additions & 0 deletions flag_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package spec

import (
_ "embed"
"reflect"
"testing"

"github.com/rsteube/carapace"
"github.com/rsteube/carapace/pkg/sandbox"
"github.com/spf13/pflag"
)

Expand Down Expand Up @@ -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"))
})
}

0 comments on commit 5e2dc17

Please sign in to comment.