MCPcopy
hub / github.com/spf13/pflag / TestCustomNormalizedNames

Function TestCustomNormalizedNames

flag_test.go:817–838  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

815}
816
817func TestCustomNormalizedNames(t *testing.T) {
818 f := NewFlagSet("normalized", ContinueOnError)
819 if f.Parsed() {
820 t.Error("f.Parse() = true before Parse")
821 }
822
823 validFlag := f.Bool("valid-flag", false, "bool value")
824 f.SetNormalizeFunc(aliasAndWordSepFlagNames)
825 someOtherFlag := f.Bool("some-other-flag", false, "bool value")
826
827 args := []string{"--old_valid_flag", "--some-other_flag"}
828 if err := f.Parse(args); err != nil {
829 t.Fatal(err)
830 }
831
832 if *validFlag != true {
833 t.Errorf("validFlag is %v even though we set the alias --old_valid_falg", *validFlag)
834 }
835 if *someOtherFlag != true {
836 t.Error("someOtherFlag should be true, is ", *someOtherFlag)
837 }
838}
839
840// Every flag we add, the name (displayed also in usage) should normalized
841func TestNormalizationFuncShouldChangeFlagName(t *testing.T) {

Callers

nothing calls this directly

Calls 6

ParsedMethod · 0.95
BoolMethod · 0.95
SetNormalizeFuncMethod · 0.95
ParseMethod · 0.95
NewFlagSetFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected