diff --git a/config/config.go b/config/config.go index 4e2391d..711c255 100644 --- a/config/config.go +++ b/config/config.go @@ -84,12 +84,17 @@ var negativeZero = math.Copysign(0, -1) type Value interface { value () fmt.Stringer + Equals (Value) bool } // ValueString is a string value. type ValueString string var _ Value = ValueString("") func (ValueString) value () { } +func (value ValueString) Equals (other Value) bool { + other, ok := other.(ValueString) + return ok && value == other +} func (value ValueString) String () string { return fmt.Sprintf("\"%s\"", escape(string(value))) } @@ -98,6 +103,10 @@ func (value ValueString) String () string { type ValueNumber float64 var _ Value = ValueNumber(0) func (ValueNumber) value () { } +func (value ValueNumber) Equals (other Value) bool { + other, ok := other.(ValueNumber) + return ok && value == other +} func (value ValueNumber) String () string { number := float64(value) // the requirements I wrote said lossless in all cases. here's lossless @@ -133,6 +142,10 @@ func (value ValueNumber) String () string { var _ Value = ValueBool(false) type ValueBool bool func (ValueBool) value () { } +func (value ValueBool) Equals (other Value) bool { + other, ok := other.(ValueBool) + return ok && value == other +} func (value ValueBool) String () string { if value { return "true"