Commit 8bfa9175 authored by David Symonds's avatar David Symonds Committed by Andrew Gerrand

expvar: quote StringFunc output, same as String output.

R=adg
CC=golang-dev
https://golang.org/cl/3797041
parent 2662b99f
......@@ -152,7 +152,7 @@ func (v IntFunc) String() string { return strconv.Itoa64(v()) }
// The function will be called each time the Var is evaluated.
type StringFunc func() string
func (f StringFunc) String() string { return f() }
func (f StringFunc) String() string { return strconv.Quote(f()) }
// All published variables.
......
......@@ -86,8 +86,8 @@ func TestMapCounter(t *testing.T) {
}
func TestIntFunc(t *testing.T) {
x := int(4)
ix := IntFunc(func() int64 { return int64(x) })
x := int64(4)
ix := IntFunc(func() int64 { return x })
if s := ix.String(); s != "4" {
t.Errorf("ix.String() = %v, want 4", s)
}
......@@ -97,3 +97,16 @@ func TestIntFunc(t *testing.T) {
t.Errorf("ix.String() = %v, want 5", s)
}
}
func TestStringFunc(t *testing.T) {
x := "hello"
sx := StringFunc(func() string { return x })
if s, exp := sx.String(), `"hello"`; s != exp {
t.Errorf(`sx.String() = %q, want %q`, s, exp)
}
x = "goodbye"
if s, exp := sx.String(), `"goodbye"`; s != exp {
t.Errorf(`sx.String() = %q, want %q`, s, exp)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment