diff options
author | Ethel Morgan <eth@ethulhu.co.uk> | 2020-06-24 12:10:57 +0100 |
---|---|---|
committer | Ethel Morgan <eth@ethulhu.co.uk> | 2020-06-24 12:10:57 +0100 |
commit | aa380da6a61f9b29ee263d95d17a2953a0528b28 (patch) | |
tree | c2915f6508ed321eeacb6ca3c7ba8de313c0ce11 /flagset_test.go | |
parent | 02f268cc3ba056be15097a7185a367585dd05275 (diff) |
import package flag from helixv0.0.1
Diffstat (limited to '')
-rw-r--r-- | flagset_test.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/flagset_test.go b/flagset_test.go new file mode 100644 index 0000000..bef4dd2 --- /dev/null +++ b/flagset_test.go @@ -0,0 +1,34 @@ +// SPDX-FileCopyrightText: 2020 Ethel Morgan +// +// SPDX-License-Identifier: MIT + +package flag + +import ( + "testing" + "time" +) + +func TestFlagSetCustom(t *testing.T) { + fs := NewFlagSet("test", ContinueOnError) + + i := fs.Int("i", 0, "i") + d := fs.Custom("d", "1s", "d", func(raw string) (interface{}, error) { + return time.ParseDuration(raw) + }) + e := fs.Custom("e", "", "e", StringEnum("json", "table")) + + if err := fs.Parse([]string{"-i", "12", "-d", "3m", "-e", "json"}); err != nil { + t.Fatalf("got error: %v", err) + } + + if *i != 12 { + t.Errorf("-i == %v, wanted %v", *i, 12) + } + if (*d).(time.Duration) != 3*time.Minute { + t.Errorf("-d == %v, wanted %v", *d, 3*time.Minute) + } + if (*e).(string) != "json" { + t.Errorf("-e == %v, wanted %v", *e, "json") + } +} |