@@ -7,10 +7,13 @@ import (
7
7
"time"
8
8
)
9
9
10
- type CompareType int
10
+ // Deprecated: CompareType has only ever been for internal use and has accidentally been published since v1.6.0. Do not use it.
11
+ type CompareType = compareResult
12
+
13
+ type compareResult int
11
14
12
15
const (
13
- compareLess CompareType = iota - 1
16
+ compareLess compareResult = iota - 1
14
17
compareEqual
15
18
compareGreater
16
19
)
28
31
uint32Type = reflect .TypeOf (uint32 (1 ))
29
32
uint64Type = reflect .TypeOf (uint64 (1 ))
30
33
34
+ uintptrType = reflect .TypeOf (uintptr (1 ))
35
+
31
36
float32Type = reflect .TypeOf (float32 (1 ))
32
37
float64Type = reflect .TypeOf (float64 (1 ))
33
38
37
42
bytesType = reflect .TypeOf ([]byte {})
38
43
)
39
44
40
- func compare (obj1 , obj2 interface {}, kind reflect.Kind ) (CompareType , bool ) {
45
+ func compare (obj1 , obj2 interface {}, kind reflect.Kind ) (compareResult , bool ) {
41
46
obj1Value := reflect .ValueOf (obj1 )
42
47
obj2Value := reflect .ValueOf (obj2 )
43
48
@@ -323,7 +328,13 @@ func compare(obj1, obj2 interface{}, kind reflect.Kind) (CompareType, bool) {
323
328
timeObj2 = obj2Value .Convert (timeType ).Interface ().(time.Time )
324
329
}
325
330
326
- return compare (timeObj1 .UnixNano (), timeObj2 .UnixNano (), reflect .Int64 )
331
+ if timeObj1 .Before (timeObj2 ) {
332
+ return compareLess , true
333
+ }
334
+ if timeObj1 .Equal (timeObj2 ) {
335
+ return compareEqual , true
336
+ }
337
+ return compareGreater , true
327
338
}
328
339
case reflect .Slice :
329
340
{
@@ -343,7 +354,27 @@ func compare(obj1, obj2 interface{}, kind reflect.Kind) (CompareType, bool) {
343
354
bytesObj2 = obj2Value .Convert (bytesType ).Interface ().([]byte )
344
355
}
345
356
346
- return CompareType (bytes .Compare (bytesObj1 , bytesObj2 )), true
357
+ return compareResult (bytes .Compare (bytesObj1 , bytesObj2 )), true
358
+ }
359
+ case reflect .Uintptr :
360
+ {
361
+ uintptrObj1 , ok := obj1 .(uintptr )
362
+ if ! ok {
363
+ uintptrObj1 = obj1Value .Convert (uintptrType ).Interface ().(uintptr )
364
+ }
365
+ uintptrObj2 , ok := obj2 .(uintptr )
366
+ if ! ok {
367
+ uintptrObj2 = obj2Value .Convert (uintptrType ).Interface ().(uintptr )
368
+ }
369
+ if uintptrObj1 > uintptrObj2 {
370
+ return compareGreater , true
371
+ }
372
+ if uintptrObj1 == uintptrObj2 {
373
+ return compareEqual , true
374
+ }
375
+ if uintptrObj1 < uintptrObj2 {
376
+ return compareLess , true
377
+ }
347
378
}
348
379
}
349
380
@@ -359,7 +390,7 @@ func Greater(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface
359
390
if h , ok := t .(tHelper ); ok {
360
391
h .Helper ()
361
392
}
362
- return compareTwoValues (t , e1 , e2 , []CompareType {compareGreater }, "\" %v\" is not greater than \" %v\" " , msgAndArgs ... )
393
+ return compareTwoValues (t , e1 , e2 , []compareResult {compareGreater }, "\" %v\" is not greater than \" %v\" " , msgAndArgs ... )
363
394
}
364
395
365
396
// GreaterOrEqual asserts that the first element is greater than or equal to the second
@@ -372,7 +403,7 @@ func GreaterOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...in
372
403
if h , ok := t .(tHelper ); ok {
373
404
h .Helper ()
374
405
}
375
- return compareTwoValues (t , e1 , e2 , []CompareType {compareGreater , compareEqual }, "\" %v\" is not greater than or equal to \" %v\" " , msgAndArgs ... )
406
+ return compareTwoValues (t , e1 , e2 , []compareResult {compareGreater , compareEqual }, "\" %v\" is not greater than or equal to \" %v\" " , msgAndArgs ... )
376
407
}
377
408
378
409
// Less asserts that the first element is less than the second
@@ -384,7 +415,7 @@ func Less(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{})
384
415
if h , ok := t .(tHelper ); ok {
385
416
h .Helper ()
386
417
}
387
- return compareTwoValues (t , e1 , e2 , []CompareType {compareLess }, "\" %v\" is not less than \" %v\" " , msgAndArgs ... )
418
+ return compareTwoValues (t , e1 , e2 , []compareResult {compareLess }, "\" %v\" is not less than \" %v\" " , msgAndArgs ... )
388
419
}
389
420
390
421
// LessOrEqual asserts that the first element is less than or equal to the second
@@ -397,7 +428,7 @@ func LessOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...inter
397
428
if h , ok := t .(tHelper ); ok {
398
429
h .Helper ()
399
430
}
400
- return compareTwoValues (t , e1 , e2 , []CompareType {compareLess , compareEqual }, "\" %v\" is not less than or equal to \" %v\" " , msgAndArgs ... )
431
+ return compareTwoValues (t , e1 , e2 , []compareResult {compareLess , compareEqual }, "\" %v\" is not less than or equal to \" %v\" " , msgAndArgs ... )
401
432
}
402
433
403
434
// Positive asserts that the specified element is positive
@@ -409,7 +440,7 @@ func Positive(t TestingT, e interface{}, msgAndArgs ...interface{}) bool {
409
440
h .Helper ()
410
441
}
411
442
zero := reflect .Zero (reflect .TypeOf (e ))
412
- return compareTwoValues (t , e , zero .Interface (), []CompareType {compareGreater }, "\" %v\" is not positive" , msgAndArgs ... )
443
+ return compareTwoValues (t , e , zero .Interface (), []compareResult {compareGreater }, "\" %v\" is not positive" , msgAndArgs ... )
413
444
}
414
445
415
446
// Negative asserts that the specified element is negative
@@ -421,10 +452,10 @@ func Negative(t TestingT, e interface{}, msgAndArgs ...interface{}) bool {
421
452
h .Helper ()
422
453
}
423
454
zero := reflect .Zero (reflect .TypeOf (e ))
424
- return compareTwoValues (t , e , zero .Interface (), []CompareType {compareLess }, "\" %v\" is not negative" , msgAndArgs ... )
455
+ return compareTwoValues (t , e , zero .Interface (), []compareResult {compareLess }, "\" %v\" is not negative" , msgAndArgs ... )
425
456
}
426
457
427
- func compareTwoValues (t TestingT , e1 interface {}, e2 interface {}, allowedComparesResults []CompareType , failMessage string , msgAndArgs ... interface {}) bool {
458
+ func compareTwoValues (t TestingT , e1 interface {}, e2 interface {}, allowedComparesResults []compareResult , failMessage string , msgAndArgs ... interface {}) bool {
428
459
if h , ok := t .(tHelper ); ok {
429
460
h .Helper ()
430
461
}
@@ -447,7 +478,7 @@ func compareTwoValues(t TestingT, e1 interface{}, e2 interface{}, allowedCompare
447
478
return true
448
479
}
449
480
450
- func containsValue (values []CompareType , value CompareType ) bool {
481
+ func containsValue (values []compareResult , value compareResult ) bool {
451
482
for _ , v := range values {
452
483
if v == value {
453
484
return true
0 commit comments