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

Function TestNormalizationFuncShouldChangeFlagName

flag_test.go:841–863  ·  view source on GitHub ↗

Every flag we add, the name (displayed also in usage) should normalized

(t *testing.T)

Source from the content-addressed store, hash-verified

839
840// Every flag we add, the name (displayed also in usage) should normalized
841func TestNormalizationFuncShouldChangeFlagName(t *testing.T) {
842 // Test normalization after addition
843 f := NewFlagSet("normalized", ContinueOnError)
844
845 f.Bool("valid_flag", false, "bool value")
846 if f.Lookup("valid_flag").Name != "valid_flag" {
847 t.Error("The new flag should have the name 'valid_flag' instead of ", f.Lookup("valid_flag").Name)
848 }
849
850 f.SetNormalizeFunc(wordSepNormalizeFunc)
851 if f.Lookup("valid_flag").Name != "valid.flag" {
852 t.Error("The new flag should have the name 'valid.flag' instead of ", f.Lookup("valid_flag").Name)
853 }
854
855 // Test normalization before addition
856 f = NewFlagSet("normalized", ContinueOnError)
857 f.SetNormalizeFunc(wordSepNormalizeFunc)
858
859 f.Bool("valid_flag", false, "bool value")
860 if f.Lookup("valid_flag").Name != "valid.flag" {
861 t.Error("The new flag should have the name 'valid.flag' instead of ", f.Lookup("valid_flag").Name)
862 }
863}
864
865// Related to https://github.com/spf13/cobra/issues/521.
866func TestNormalizationSharedFlags(t *testing.T) {

Callers

nothing calls this directly

Calls 5

BoolMethod · 0.95
LookupMethod · 0.95
SetNormalizeFuncMethod · 0.95
NewFlagSetFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected