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

Function TestChangedHelper

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

Source from the content-addressed store, hash-verified

702}
703
704func TestChangedHelper(t *testing.T) {
705 f := NewFlagSet("changedtest", ContinueOnError)
706 f.Bool("changed", false, "changed bool")
707 f.Bool("settrue", true, "true to true")
708 f.Bool("setfalse", false, "false to false")
709 f.Bool("unchanged", false, "unchanged bool")
710
711 args := []string{"--changed", "--settrue", "--setfalse=false"}
712 if err := f.Parse(args); err != nil {
713 t.Error("f.Parse() = false after Parse")
714 }
715 if !f.Changed("changed") {
716 t.Errorf("--changed wasn't changed!")
717 }
718 if !f.Changed("settrue") {
719 t.Errorf("--settrue wasn't changed!")
720 }
721 if !f.Changed("setfalse") {
722 t.Errorf("--setfalse wasn't changed!")
723 }
724 if f.Changed("unchanged") {
725 t.Errorf("--unchanged was changed!")
726 }
727 if f.Changed("invalid") {
728 t.Errorf("--invalid was changed!")
729 }
730 if f.ArgsLenAtDash() != -1 {
731 t.Errorf("Expected argsLenAtDash: %d but got %d", -1, f.ArgsLenAtDash())
732 }
733}
734
735func replaceSeparators(name string, from []string, to string) string {
736 result := name

Callers

nothing calls this directly

Calls 6

BoolMethod · 0.95
ParseMethod · 0.95
ChangedMethod · 0.95
ArgsLenAtDashMethod · 0.95
NewFlagSetFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…