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

Function TestNormalizationSetFlags

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

Source from the content-addressed store, hash-verified

897}
898
899func TestNormalizationSetFlags(t *testing.T) {
900 f := NewFlagSet("normalized", ContinueOnError)
901 nfunc := wordSepNormalizeFunc
902 testName := "valid_flag"
903 normName := nfunc(nil, testName)
904 if testName == string(normName) {
905 t.Error("TestNormalizationSetFlags meaningless: the original and normalized flag names are identical:", testName)
906 }
907
908 f.Bool(testName, false, "bool value")
909 f.Set(testName, "true")
910 f.SetNormalizeFunc(nfunc)
911
912 if len(f.formal) != 1 {
913 t.Error("Normalizing flags should not result in duplications in the flag set:", f.formal)
914 }
915 if f.orderedFormal[0].Name != string(normName) {
916 t.Error("Flag name not normalized")
917 }
918 for k := range f.formal {
919 if k != "valid.flag" {
920 t.Errorf("The key in the flag map should have been normalized: wanted \"%s\", got \"%s\" instead", normName, k)
921 }
922 }
923
924 if !reflect.DeepEqual(f.formal, f.actual) {
925 t.Error("The map of set flags should get normalized. Formal:", f.formal, "Actual:", f.actual)
926 }
927}
928
929// Declare a user-defined flag type.
930type flagVar []string

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected