MCPcopy
hub / github.com/uber-go/zap / TestEquals

Function TestEquals

zapcore/field_test.go:206–350  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

204}
205
206func TestEquals(t *testing.T) {
207 // Values outside the UnixNano range were encoded incorrectly (#737, #803).
208 timeOutOfRangeHigh := time.Unix(0, math.MaxInt64).Add(time.Nanosecond)
209 timeOutOfRangeLow := time.Unix(0, math.MinInt64).Add(-time.Nanosecond)
210 timeOutOfRangeHighNano := time.Unix(0, timeOutOfRangeHigh.UnixNano())
211 timeOutOfRangeLowNano := time.Unix(0, timeOutOfRangeLow.UnixNano())
212 require.False(t, timeOutOfRangeHigh.Equal(timeOutOfRangeHighNano), "should be different as value is > UnixNano range")
213 require.False(t, timeOutOfRangeHigh.Equal(timeOutOfRangeHighNano), "should be different as value is < UnixNano range")
214
215 tests := []struct {
216 a, b Field
217 want bool
218 }{
219 {
220 a: zap.Int16("a", 1),
221 b: zap.Int32("a", 1),
222 want: false,
223 },
224 {
225 a: zap.String("k", "a"),
226 b: zap.String("k", "a"),
227 want: true,
228 },
229 {
230 a: zap.String("k", "a"),
231 b: zap.String("k2", "a"),
232 want: false,
233 },
234 {
235 a: zap.String("k", "a"),
236 b: zap.String("k", "b"),
237 want: false,
238 },
239 {
240 a: zap.Time("k", time.Unix(1000, 1000)),
241 b: zap.Time("k", time.Unix(1000, 1000)),
242 want: true,
243 },
244 {
245 a: zap.Time("k", time.Unix(1000, 1000).In(time.UTC)),
246 b: zap.Time("k", time.Unix(1000, 1000).In(time.FixedZone("TEST", -8))),
247 want: false,
248 },
249 {
250 a: zap.Time("k", timeOutOfRangeLow),
251 b: zap.Time("k", timeOutOfRangeLowNano),
252 want: false,
253 },
254 {
255 a: zap.Time("k", timeOutOfRangeHigh),
256 b: zap.Time("k", timeOutOfRangeHighNano),
257 want: false,
258 },
259 {
260 a: zap.Time("k", time.Unix(1000, 1000)),
261 b: zap.Time("k", time.Unix(1000, 2000)),
262 want: false,
263 },

Callers

nothing calls this directly

Calls 14

Int16Function · 0.92
Int32Function · 0.92
StringFunction · 0.92
TimeFunction · 0.92
BinaryFunction · 0.92
ByteStringFunction · 0.92
IntsFunction · 0.92
ObjectFunction · 0.92
AnyFunction · 0.92
DictFunction · 0.92
DictObjectFunction · 0.92
EqualsMethod · 0.80

Tested by

no test coverage detected