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

Function TestVisitAllFlagOrder

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

Source from the content-addressed store, hash-verified

1357}
1358
1359func TestVisitAllFlagOrder(t *testing.T) {
1360 fs := NewFlagSet("TestVisitAllFlagOrder", ContinueOnError)
1361 fs.SortFlags = false
1362 // https://github.com/spf13/pflag/issues/120
1363 fs.SetNormalizeFunc(func(f *FlagSet, name string) NormalizedName {
1364 return NormalizedName(name)
1365 })
1366
1367 names := []string{"C", "B", "A", "D"}
1368 for _, name := range names {
1369 fs.Bool(name, false, "")
1370 }
1371
1372 i := 0
1373 fs.VisitAll(func(f *Flag) {
1374 if names[i] != f.Name {
1375 t.Errorf("Incorrect order. Expected %v, got %v", names[i], f.Name)
1376 }
1377 i++
1378 })
1379}
1380
1381func TestVisitFlagOrder(t *testing.T) {
1382 fs := NewFlagSet("TestVisitFlagOrder", ContinueOnError)

Callers

nothing calls this directly

Calls 5

SetNormalizeFuncMethod · 0.95
BoolMethod · 0.95
VisitAllMethod · 0.95
NewFlagSetFunction · 0.85
NormalizedNameTypeAlias · 0.85

Tested by

no test coverage detected