@@ -7,13 +7,12 @@ package expvar
7
7
import (
8
8
"bytes"
9
9
"encoding/json"
10
- "math"
11
10
"net"
12
11
"net/http/httptest"
12
+ "reflect"
13
13
"runtime"
14
14
"strconv"
15
15
"sync"
16
- "sync/atomic"
17
16
"testing"
18
17
)
19
18
@@ -58,6 +57,10 @@ func TestInt(t *testing.T) {
58
57
if reqs .i != - 2 {
59
58
t .Errorf ("reqs.i = %v, want -2" , reqs .i )
60
59
}
60
+
61
+ if v , want := reqs .Value (), int64 (- 2 ); v != want {
62
+ t .Errorf ("reqs.Value() = %q, want %q" , v , want )
63
+ }
61
64
}
62
65
63
66
func BenchmarkIntAdd (b * testing.B ) {
@@ -80,10 +83,6 @@ func BenchmarkIntSet(b *testing.B) {
80
83
})
81
84
}
82
85
83
- func (v * Float ) val () float64 {
84
- return math .Float64frombits (atomic .LoadUint64 (& v .f ))
85
- }
86
-
87
86
func TestFloat (t * testing.T ) {
88
87
RemoveAll ()
89
88
reqs := NewFloat ("requests-float" )
@@ -96,17 +95,17 @@ func TestFloat(t *testing.T) {
96
95
97
96
reqs .Add (1.5 )
98
97
reqs .Add (1.25 )
99
- if v := reqs .val (); v != 2.75 {
100
- t .Errorf ("reqs.val () = %v, want 2.75" , v )
98
+ if v := reqs .Value (); v != 2.75 {
99
+ t .Errorf ("reqs.Value () = %v, want 2.75" , v )
101
100
}
102
101
103
102
if s := reqs .String (); s != "2.75" {
104
103
t .Errorf ("reqs.String() = %q, want \" 4.64\" " , s )
105
104
}
106
105
107
106
reqs .Add (- 2 )
108
- if v := reqs .val (); v != 0.75 {
109
- t .Errorf ("reqs.val () = %v, want 0.75" , v )
107
+ if v := reqs .Value (); v != 0.75 {
108
+ t .Errorf ("reqs.Value () = %v, want 0.75" , v )
110
109
}
111
110
}
112
111
@@ -146,6 +145,10 @@ func TestString(t *testing.T) {
146
145
t .Errorf ("from %q, name.String() = %q, want %q" , name .s , s , want )
147
146
}
148
147
148
+ if s , want := name .Value (), "Mike" ; s != want {
149
+ t .Errorf ("from %q, name.Value() = %q, want %q" , name .s , s , want )
150
+ }
151
+
149
152
// Make sure we produce safe JSON output.
150
153
name .Set (`<` )
151
154
if s , want := name .String (), "\" \\ u003c\" " ; s != want {
@@ -177,7 +180,7 @@ func TestMapCounter(t *testing.T) {
177
180
if x := colors .m ["blue" ].(* Int ).i ; x != 4 {
178
181
t .Errorf ("colors.m[\" blue\" ] = %v, want 4" , x )
179
182
}
180
- if x := colors .m [`green "midori"` ].(* Float ).val (); x != 4.125 {
183
+ if x := colors .m [`green "midori"` ].(* Float ).Value (); x != 4.125 {
181
184
t .Errorf ("colors.m[`green \" midori\" ] = %v, want 4.125" , x )
182
185
}
183
186
@@ -242,6 +245,9 @@ func TestFunc(t *testing.T) {
242
245
if s , exp := f .String (), `["a","b"]` ; s != exp {
243
246
t .Errorf (`f.String() = %q, want %q` , s , exp )
244
247
}
248
+ if v := f .Value (); ! reflect .DeepEqual (v , x ) {
249
+ t .Errorf (`f.Value() = %q, want %q` , v , x )
250
+ }
245
251
246
252
x = 17
247
253
if s , exp := f .String (), `17` ; s != exp {
0 commit comments