From 5d8c9417a3a264c3f96b1959a3e8be6c8584fbf1 Mon Sep 17 00:00:00 2001 From: tannevaled Date: Mon, 30 Nov 2026 21:09:32 +0100 Subject: [PATCH] plot: test that a parameterless option is a switch (kills the plot.go:463 `!b` survivor) plOption gives no option for false and the option for true; nothing asserted the difference, so mutsweep's `!b` -> `b` survived. TestPlOptionSwitch asserts true -> option, false -> nil, non-bool -> error with plot.Density. mutsweep -only plot.go:463: caught. Co-Authored-By: Claude Sonnet 5.5 --- ploption_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 ploption_test.go diff --git a/ploption_test.go b/ploption_test.go new file mode 100644 index 0000000..9c96b9b --- /dev/null +++ b/ploption_test.go @@ -0,0 +1,25 @@ +package ruby + +import ( + "reflect" + "testing" + + "github.com/go-plot/plot" +) + +// A parameterless option constructor is a switch: true gives the option, +// false gives no option at all (nil, nil), anything else is a TypeError. +func TestPlOptionSwitchTrueAppliesFalseDoesNot(t *testing.T) { + fn := reflect.ValueOf(plot.Density) + o, err := plOption("density", fn, true) + if err != nil || o == nil { + t.Errorf("true: option %v, err %v; want an option, nil", o != nil, err) + } + o, err = plOption("density", fn, false) + if err != nil || o != nil { + t.Errorf("false: option %v, err %v; want none, nil", o != nil, err) + } + if _, err = plOption("density", fn, 1); err == nil { + t.Error("a non-boolean switch value was accepted") + } +}