From 73519a3538720b2cbca59cde36f755a1e4068eae Mon Sep 17 00:00:00 2001 From: GrĂ©goire DuchĂȘne Date: Sun, 4 Dec 2022 00:00:47 +0000 Subject: 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. --- flag_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'flag_test.go') 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} -- cgit v1.2.3-70-g09d2