diff options
| author | Grégoire Duchêne <gduchene@awhk.org> | 2022-12-04 00:00:47 +0000 |
|---|---|---|
| committer | Grégoire Duchêne <gduchene@awhk.org> | 2022-12-10 14:11:53 +0000 |
| commit | 73519a3538720b2cbca59cde36f755a1e4068eae (patch) | |
| tree | 07d2a2f548616859e930f017f18f50880dd4b653 /flag_test.go | |
| parent | 1ec7c85d76814533a8e401f36a51a2448430d9bd (diff) | |
Add Feature and FlagFeature{,Var}
Feature is essentially a boolean flag that can be safely mutated at run
time. FlagFeature{,Var} make Feature objects work with flags.
Diffstat (limited to 'flag_test.go')
| -rw-r--r-- | flag_test.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/flag_test.go b/flag_test.go index 91c6caa..1cc9ba8 100644 --- a/flag_test.go +++ b/flag_test.go @@ -11,6 +11,18 @@ import ( "go.awhk.org/core" ) +func TestFeature_Disable(t *testing.T) { + f := core.Feature{} + f.Disable() + (&core.T{T: t}).AssertEqual(false, f.Enabled()) +} + +func TestFeature_Enable(t *testing.T) { + f := core.Feature{} + f.Enable() + (&core.T{T: t}).AssertEqual(true, f.Enabled()) +} + func TestFlag(s *testing.T) { t := core.T{T: s} @@ -21,6 +33,15 @@ func TestFlag(s *testing.T) { t.AssertEqual(84, *fl) } +func TestFlagFeature(s *testing.T) { + t := core.T{T: s} + + fs := flag.NewFlagSet("", flag.PanicOnError) + ff := core.FlagFeature(fs, "some-feature", false, "") + t.AssertErrorIs(nil, fs.Parse([]string{"-some-feature"})) + t.AssertEqual(true, ff.Enabled()) +} + func TestFlagVar(s *testing.T) { t := core.T{T: s} |
