Add Equals method to config.Value
This commit is contained in:
parent
656be379e4
commit
a8878e1e20
@ -84,12 +84,17 @@ var negativeZero = math.Copysign(0, -1)
|
|||||||
type Value interface {
|
type Value interface {
|
||||||
value ()
|
value ()
|
||||||
fmt.Stringer
|
fmt.Stringer
|
||||||
|
Equals (Value) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValueString is a string value.
|
// ValueString is a string value.
|
||||||
type ValueString string
|
type ValueString string
|
||||||
var _ Value = ValueString("")
|
var _ Value = ValueString("")
|
||||||
func (ValueString) value () { }
|
func (ValueString) value () { }
|
||||||
|
func (value ValueString) Equals (other Value) bool {
|
||||||
|
other, ok := other.(ValueString)
|
||||||
|
return ok && value == other
|
||||||
|
}
|
||||||
func (value ValueString) String () string {
|
func (value ValueString) String () string {
|
||||||
return fmt.Sprintf("\"%s\"", escape(string(value)))
|
return fmt.Sprintf("\"%s\"", escape(string(value)))
|
||||||
}
|
}
|
||||||
@ -98,6 +103,10 @@ func (value ValueString) String () string {
|
|||||||
type ValueNumber float64
|
type ValueNumber float64
|
||||||
var _ Value = ValueNumber(0)
|
var _ Value = ValueNumber(0)
|
||||||
func (ValueNumber) value () { }
|
func (ValueNumber) value () { }
|
||||||
|
func (value ValueNumber) Equals (other Value) bool {
|
||||||
|
other, ok := other.(ValueNumber)
|
||||||
|
return ok && value == other
|
||||||
|
}
|
||||||
func (value ValueNumber) String () string {
|
func (value ValueNumber) String () string {
|
||||||
number := float64(value)
|
number := float64(value)
|
||||||
// the requirements I wrote said lossless in all cases. here's lossless
|
// 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)
|
var _ Value = ValueBool(false)
|
||||||
type ValueBool bool
|
type ValueBool bool
|
||||||
func (ValueBool) value () { }
|
func (ValueBool) value () { }
|
||||||
|
func (value ValueBool) Equals (other Value) bool {
|
||||||
|
other, ok := other.(ValueBool)
|
||||||
|
return ok && value == other
|
||||||
|
}
|
||||||
func (value ValueBool) String () string {
|
func (value ValueBool) String () string {
|
||||||
if value {
|
if value {
|
||||||
return "true"
|
return "true"
|
||||||
|
Loading…
Reference in New Issue
Block a user