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") + } +}