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

Function testParseAll

flag_test.go:397–448  ·  flag_test.go::testParseAll
(f *FlagSet, t *testing.T)

Source from the content-addressed store, hash-verified

395}
396
397func testParseAll(f *FlagSet, t *testing.T) {
398 if f.Parsed() {
399 t.Error("f.Parse() = true before Parse")
400 }
401 f.BoolP("boola", "a", false, "bool value")
402 f.BoolP("boolb", "b", false, "bool2 value")
403 f.BoolP("boolc", "c", false, "bool3 value")
404 f.BoolP("boold", "d", false, "bool4 value")
405 f.StringP("stringa", "s", "0", "string value")
406 f.StringP("stringz", "z", "0", "string value")
407 f.StringP("stringx", "x", "0", "string value")
408 f.StringP("stringy", "y", "0", "string value")
409 f.Lookup("stringx").NoOptDefVal = "1"
410 args := []string{
411 "-ab",
412 "-cs=xx",
413 "--stringz=something",
414 "-d=true",
415 "-x",
416 "-y",
417 "ee",
418 }
419 want := []string{
420 "boola", "true",
421 "boolb", "true",
422 "boolc", "true",
423 "stringa", "xx",
424 "stringz", "something",
425 "boold", "true",
426 "stringx", "1",
427 "stringy", "ee",
428 }
429 got := []string{}
430 store := func(flag *Flag, value string) error {
431 got = append(got, flag.Name)
432 if len(value) > 0 {
433 got = append(got, value)
434 }
435 return nil
436 }
437 if err := f.ParseAll(args, store); err != nil {
438 t.Errorf("expected no error, got %s", err)
439 }
440 if !f.Parsed() {
441 t.Errorf("f.Parse() = false after Parse")
442 }
443 if !reflect.DeepEqual(got, want) {
444 t.Errorf("f.ParseAll() fail to restore the args")
445 t.Errorf("Got: %v", got)
446 t.Errorf("Want: %v", want)
447 }
448}
449
450func testParseWithUnknownFlags(f *FlagSet, t *testing.T, setUnknownFlags func(f *FlagSet)) {
451 if f.Parsed() {

Callers 1

TestParseAllFunction · 0.85

Calls 6

ParsedMethod · 0.80
BoolPMethod · 0.80
StringPMethod · 0.80
LookupMethod · 0.80
ParseAllMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected